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

Private GIT Repository
Merge branch 'master' of ssh://info.iut-bm.univ-fcomte.fr/loba
[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();
25     //print_loads_p(false, xbt_log_priority_debug);
26
27     bool found = true;
28
29     while (found) {
30         found = false;
31         for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
32             if (pneigh[i]->get_load() <= get_load() - 2) {
33                 found = true;
34                 send(pneigh[i], 1);
35                 DEBUG1("sent to %s", pneigh[i]->get_name());
36             }
37         }
38     }
39 }
40
41 // Local variables:
42 // mode: c++
43 // End: