1 #include <cmath> // std::isfinite
6 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
8 #include "loba_2besteffort.h"
10 void loba_2besteffort::load_balance()
12 using std::placeholders::_1;
13 using std::placeholders::_2;
15 pneigh_sort_by_load(std::less<double>());
16 print_loads_p(false, xbt_log_priority_debug);
18 double sum = get_load() +
19 std::accumulate(pneigh.begin(), pneigh.end(), 0.0,
20 std::bind(std::plus<double>(), _1,
21 std::bind(&neighbor::get_load, _2)));
22 double mean = sum / (pneigh.size() + 1);
23 XBT_DEBUG("sum = %g ; mean = %g", sum, mean);
25 if (!std::isfinite(mean))
28 for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
29 double transfer = std::min(mean - pneigh[i]->get_load(),
31 // don't continue if get_load() <= mean, or pneigh[i]->get_load >= mean
35 transfer /= opt::option_x; // HACK!!!
36 send(pneigh[i], transfer);
37 XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());