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

Private GIT Repository
API change in SimGrid 3.8: MSG_global_init -> MSG_init.
[loba.git] / loba_besteffort.cpp
index 18e8c0c790591c1df0fa654e41d6e11847714431..f3a8c33ef32fca74f50e5aed8a3d635a8b0c14d0 100644 (file)
@@ -6,8 +6,31 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
 
 void loba_besteffort::load_balance()
 {
-    // write code here...
-    xbt_die("Load-balancing algorithm besteffort not implemented!");
+    pneigh_sort_by_load(std::less<double>());
+    print_loads_p(false, xbt_log_priority_debug);
+
+    unsigned bound = pneigh.size();
+    double sum = get_load();
+    for (unsigned i = 0 ; i < bound ; ++i) {
+        if (get_load() <= pneigh[i]->get_load()) {
+            bound = i;
+        } else {
+            double newsum = sum + pneigh[i]->get_load();
+            if (pneigh[i]->get_load() <= newsum / (i + 2))
+                sum = newsum;
+            else
+                bound = i;
+        }
+    }
+
+    double mean = sum / (bound + 1);
+    for (unsigned i = 0 ; i < bound ; ++i) {
+        double transfer = mean - pneigh[i]->get_load();
+        if (opt::loba_best_divisor)
+            transfer /= opt::loba_best_divisor;
+        send(pneigh[i], transfer);
+        XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
+    }
 }
 
 // Local variables: