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

Private GIT Repository
Experimental: use TRY_NO_BACKTRACE if available.
[loba.git] / loba_lln.cpp
1 #include <algorithm>
2 #include <xbt/log.h>
3
4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
5
6 #include "loba_lln.h"
7
8 void loba_lln::load_balance()
9 {
10     std::vector<int> listLessLoadedNeighbors;
11     unsigned i;
12     double myLoad = get_load();
13     unsigned size = pneigh.size();
14     double *S = new double[size];
15     double lessLoad = get_load();
16
17     listLessLoadedNeighbors.clear();
18     for (i = 0; i < size; ++i) {
19         S[i] = 0.0;
20         if (pneigh[i]->get_load() < lessLoad)
21             listLessLoadedNeighbors.push_back(i);
22     }
23     int nbLessLoadedNeighbors = listLessLoadedNeighbors.size();
24     for (i = 0; i < listLessLoadedNeighbors.size(); ++i) {
25         double delta =
26             (myLoad - pneigh[listLessLoadedNeighbors[i]]->get_load()) /
27             (nbLessLoadedNeighbors + 1);
28         if (myLoad - delta > pneigh[listLessLoadedNeighbors[i]]->get_load()) {
29             S[i] = delta;
30             myLoad -= delta;
31         }
32     }
33     for (i = 0; i < size; ++i) {
34         send(pneigh[i], S[i]);
35         XBT_DEBUG("sent to %s", pneigh[i]->get_name());
36     }
37     delete[] S;
38 }
39
40 // Local variables:
41 // mode: c++
42 // End: