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

Private GIT Repository
Add Makhoul's algorithm.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 3 Feb 2011 16:10:22 +0000 (17:10 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 3 Feb 2011 16:15:25 +0000 (17:15 +0100)
Not tested.

loba_makhoul.cpp [new file with mode: 0644]
loba_makhoul.h [new file with mode: 0644]
options.cpp

diff --git a/loba_makhoul.cpp b/loba_makhoul.cpp
new file mode 100644 (file)
index 0000000..67a2359
--- /dev/null
@@ -0,0 +1,33 @@
+#include <algorithm>
+#include <xbt/log.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
+
+#include "loba_makhoul.h"
+
+class compare {
+public:
+    bool operator()(const neighbor*a, const neighbor*b) {
+        return a->get_load() < b->get_load();
+    }
+};
+
+void loba_makhoul::load_balance()
+{
+    std::sort(pneigh.begin(), pneigh.end(), compare());
+
+    print_loads_p(false, xbt_log_priority_debug);
+
+    double alpha = 1.0 / (pneigh.size() + 1.0);
+    double delta;
+    for (unsigned i = 0 ;
+         i < pneigh.size() &&
+             (delta = get_load() - pneigh[i]->get_load()) > 0.0 ;
+         ++i) {
+        send(pneigh[i], delta * alpha);
+    }
+}
+
+// Local variables:
+// mode: c++
+// End:
diff --git a/loba_makhoul.h b/loba_makhoul.h
new file mode 100644 (file)
index 0000000..46b6e55
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef LOBA_MAKHOUL_H
+#define LOBA_MAKHOUL_H
+
+#include "process.h"
+
+class loba_makhoul: public process {
+public:
+    loba_makhoul(int argc, char* argv[]): process(argc, argv) { }
+    ~loba_makhoul()                                           { }
+
+private:
+    void load_balance();
+};
+
+#endif //!LOBA_MAKHOUL_H
+
+// Local variables:
+// mode: c++
+// End:
index fd9da4eb8b05dd0b3d1d0f0246dac670ee3a1422..96b53e0ae9c14a4e7bd30f073c3f53c13260e69d 100644 (file)
@@ -11,6 +11,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
 #include "process.h"
 #include "loba_simple.h"
 #include "loba_fairstrategy.h"
+#include "loba_makhoul.h"
 
 #include "options.h"
 
@@ -63,6 +64,7 @@ namespace opt {
     loba_algorithms_type::loba_algorithms_type()
     {
         NOL_INSERT("fairstrategy", "balance with fair strategy", loba_fairstrategy);
+        NOL_INSERT("makhoul", "balance with Makhoul's PhD algorithm", loba_makhoul);
         NOL_INSERT("none", "no load-balancing (for testing only)", process);
         NOL_INSERT("simple", "balance with least loaded neighbor", loba_simple);
     }