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

Private GIT Repository
Define process::print_loads_p() to print loads by using neighp[]
[loba.git] / loba_fairstrategy.cpp
1 #include <algorithm>
2 #include <xbt/log.h>
3
4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
5
6 #include "loba_fairstrategy.h"
7
8 /* simple version:
9  *   load balance with a least-loaded neighbor,
10  *   without breaking the ping-pong condition
11  */
12
13 class compare {
14 public : 
15         bool operator()(const neighbor*a, const neighbor*b)     {
16                 return a->get_load()>b->get_load();
17         }
18 };
19
20 double loba_fairstrategy::load_balance(double my_load)
21 {
22     int imin = -1;
23     int imax = -1;
24     double min = my_load;
25     double max = -1.0;
26
27                 std::sort(pneigh.begin(),pneigh.end(),compare());
28
29                 print_loads_p();
30
31                 double sum_sent=0;
32                 bool found=true;
33
34                 while(found) {
35                         found=false;
36                         for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
37         double l = pneigh[i]->get_load();
38         if (l >= my_load)
39                                         continue;
40                                 if(l<my_load+2) {
41                                         found=true;
42                                         pneigh[i]->set_load(l+1);
43                                         pneigh[i]->add_to_send(1);
44                                         INFO1("sent to %s",pneigh[i]->get_name());
45                                         my_load--;
46                                         sum_sent++;
47                                 }
48                         }
49                 }
50
51
52                 
53                 return sum_sent;
54     
55 }
56
57 // Local variables:
58 // mode: c++
59 // End: