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

Private GIT Repository
Remove useless include.
[loba.git] / loba_makhoul2.cpp
1 #include <xbt/log.h>
2
3 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
4
5 #include "loba_makhoul2.h"
6
7 // Note: adapted from Makhoul's code
8
9 void loba_makhoul2::load_balance()
10 {
11     pneigh_sort_by_load(std::less<double>());
12     print_loads_p(false, xbt_log_priority_debug);
13
14     double alpha = 1.0 / (pneigh.size() + 1.0);
15     double neighborLoadMax = 0.0; // maximum load of neighbors to
16                                   // which something has been sent
17     for (unsigned i = 0;
18          i < pneigh.size() && pneigh[i]->get_load() < get_load(); ++i)
19     {
20
21         double delta = get_load() - pneigh[i]->get_load();
22
23         // do not violate ping-pong condition
24         double transfer = std::min(alpha * delta, get_load() - neighborLoadMax);
25         // note: alpha <= 1/2
26         XBT_DEBUG("delta = %g ; transfer = %g", delta, transfer);
27
28         send(pneigh[i], transfer);
29         XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
30
31         double newNeighborLoad = pneigh[i]->get_load();
32         if (newNeighborLoad > neighborLoadMax)
33             neighborLoadMax = newNeighborLoad;
34     }
35 }
36
37 // Local variables:
38 // mode: c++
39 // End: