1 #include <cmath> // std::isfinite
5 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
7 #include "loba_2besteffort.h"
9 void loba_2besteffort::load_balance()
11 pneigh_sort_by_load(std::less<double>());
12 print_loads_p(false, xbt_log_priority_debug);
14 double sum = get_load() +
15 std::accumulate(pneigh.begin(), pneigh.end(), 0.0,
16 [](double x, const neighbor* n) {
17 return x + n->get_load();
19 double mean = sum / (pneigh.size() + 1);
20 XBT_DEBUG("sum = %g ; mean = %g", sum, mean);
22 if (!std::isfinite(mean))
25 for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
26 double transfer = std::min(mean - pneigh[i]->get_load(),
28 // don't continue if get_load() <= mean, or pneigh[i]->get_load >= mean
31 if (opt::loba_best_divisor)
32 transfer /= opt::loba_best_divisor;
33 send(pneigh[i], transfer);
34 XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());