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

Private GIT Repository
Add statistics about convergence (see parameter -%).
[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         if (opt::loba_best_divisor)
30             transfer /= opt::loba_best_divisor;
31         send(pneigh[i], transfer);
32         XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
33     }
34 }
35
36 // Local variables:
37 // mode: c++
38 // End: