]> AND Private Git Repository - loba.git/blob - loba_fairstrategy.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Use MSG_comm_waitall for communicator::flush(true).
[loba.git] / loba_fairstrategy.cpp
1 #include <algorithm>
2 #include <xbt/log.h>
3
4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
5
6 #include "loba_fairstrategy.h"
7
8 /* simple version:
9  *   load balance with a least-loaded neighbor,
10  *   without breaking the ping-pong condition
11  */
12
13 class compare {
14 public:
15     bool operator()(const neighbor*a, const neighbor*b) {
16         return a->get_load() > b->get_load();
17     }
18 };
19
20 void loba_fairstrategy::load_balance()
21 {
22     std::sort(pneigh.begin(), pneigh.end(), compare());
23
24     print_loads_p(false, xbt_log_priority_debug);
25
26     bool found = true;
27
28     while (found) {
29         found = false;
30         for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
31             if (pneigh[i]->get_load() <= get_load() - 2) {
32                 found = true;
33                 send(pneigh[i], 1);
34                 DEBUG1("sent to %s", pneigh[i]->get_name());
35             }
36         }
37     }
38 }
39
40 // Local variables:
41 // mode: c++
42 // End: