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

Private GIT Repository
Fix missing definition in gcc 4.4/cstdatomic.
[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 = (myLoad-pneigh[listLessLoadedNeighbors[i]]->get_load())/(nbLessLoadedNeighbors+1);
26                         if(myLoad-delta > pneigh[listLessLoadedNeighbors[i]]->get_load()) {
27                                 S[i]=delta;
28                                 myLoad-=delta;
29                         }
30                 }
31                 for(i=0; i<size; ++i) {
32                         send(pneigh[i], S[i]);
33                         XBT_DEBUG("sent to %s", pneigh[i]->get_name());
34                 }
35         delete[] S;
36 }
37
38 // Local variables:
39 // mode: c++
40 // End: