4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
8 void loba_bulk::load_balance()
10 float myLoad = get_load();
12 unsigned NbNwMinLoad = 0;
13 unsigned NbNwLowerLoad = 0;
14 unsigned NbNeighbours = pneigh.size();
16 double *S = new double[NbNeighbours];
17 for (unsigned i = 0; i < NbNeighbours; i++)
19 //What is the minimum and maximum load under myLoad?
20 float minLoad = myLoad;
21 for (unsigned i = 0; i < NbNeighbours; i++) {
22 if (pneigh[i]->get_load() < minLoad) {
23 minLoad = pneigh[i]->get_load();
25 if (pneigh[i]->get_load() < myLoad) {
29 for (unsigned i = 0; i < NbNeighbours; i++)
30 if (pneigh[i]->get_load() == minLoad)
33 float maxLoad = minLoad;
34 for (unsigned i = 0; i < NbNeighbours; i++) {
35 if (pneigh[i]->get_load() > minLoad && pneigh[i]->get_load() < myLoad)
36 if (maxLoad < pneigh[i]->get_load())
37 maxLoad = pneigh[i]->get_load();
42 if (NbNwLowerLoad && NbNwMinLoad < NbNwLowerLoad) //There is one or many neighbors with minimum load but not all neighbors have minimum load
43 alpha = (1. / ((double) NbNwMinLoad + 2));
44 if (NbNwMinLoad == NbNwLowerLoad) //All neighbors have minimum load
45 alpha = (1. / ((double) NbNwMinLoad + 1));
47 //There exist underloaded neighbors
48 if (NbNwMinLoad && myLoad != 0.0) {
49 for (unsigned i = 0; i < NbNeighbours; i++) {
50 if (pneigh[i]->get_load() == minLoad) {
51 S[i] = floor(alpha * (myLoad - minLoad));
54 if (pneigh[i]->get_load() < myLoad) {
55 S[i] = floor(alpha * (myLoad - pneigh[i]->get_load()));
60 //Check assumption 4.2 (b) page 520
61 bool HaveToCorrectS = false;
62 for (unsigned i = 0; i < NbNeighbours; i++) {
63 if (pneigh[i]->get_load() < myLoad) { //
65 if ((myLoad - myS) < (pneigh[i]->get_load() + S[i])) {
66 HaveToCorrectS = true;
71 for (unsigned i = 0; i < NbNeighbours; i++) {
72 while (((myLoad - myS) < pneigh[i]->get_load() + S[i]) && (S[i] > 0)) {
78 }//End there are underloaded neighbors;
79 for (unsigned i = 0 ; i < NbNeighbours ; i++) {
80 send(pneigh[i], S[i]);
81 XBT_DEBUG("sent to %s", pneigh[i]->get_name());