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

Private GIT Repository
Add some notes on experimentations to run.
[loba.git] / loba_besteffort.cpp
1 #include <xbt/log.h>
2
3 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
4
5 #include "loba_besteffort.h"
6
7 void loba_besteffort::load_balance()
8 {
9     pneigh_sort_by_load(std::less<double>());
10     print_loads_p(false, xbt_log_priority_debug);
11
12     unsigned bound = pneigh.size();
13     double sum = get_load();
14     for (unsigned i = 0 ; i < bound ; ++i) {
15         if (get_load() <= pneigh[i]->get_load()) {
16             bound = i;
17         } else {
18             double newsum = sum + pneigh[i]->get_load();
19             if (pneigh[i]->get_load() <= newsum / (i + 2))
20                 sum = newsum;
21             else
22                 bound = i;
23         }
24     }
25
26     double mean = sum / (bound + 1);
27     for (unsigned i = 0 ; i < bound ; ++i) {
28         double transfer = mean - pneigh[i]->get_load();
29         send(pneigh[i], transfer);
30         XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
31     }
32 }
33
34 // Local variables:
35 // mode: c++
36 // End: