From 0ebfaf6eb40a90d31baa3813c891eb7261e818d2 Mon Sep 17 00:00:00 2001
From: Raphael Couturier <raphael.couturier@univ-fcomte.fr>
Date: Tue, 20 Sep 2011 14:57:07 +0200
Subject: [PATCH 1/1] makhoul3

---
 Experimentations/rc_test_a_lance | 19 ++++++++++++++--
 loba_makhoul3.cpp                | 37 ++++++++++++++++++++++++++++++++
 loba_makhoul3.h                  | 19 ++++++++++++++++
 options.cpp                      |  3 +++
 4 files changed, 76 insertions(+), 2 deletions(-)
 create mode 100644 loba_makhoul3.cpp
 create mode 100644 loba_makhoul3.h

diff --git a/Experimentations/rc_test_a_lance b/Experimentations/rc_test_a_lance
index 39de54f..eb5876b 100644
--- a/Experimentations/rc_test_a_lance
+++ b/Experimentations/rc_test_a_lance
@@ -29,7 +29,22 @@ cd Experimentation
 
 
 
-#test avec plus de neouds, c'est enfin best qui va plus vite, meme s'il effectue plus d'échange
+#test avec plus de noeuds, c'est enfin best qui va plus vite, meme s'il effectue plus d'échange
 ../loba  -c1e6,0 -C1e4,0 -M10 -Tline -a2best -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z
 ../loba  -c1e6,0 -C1e4,0 -M10 -Tline -abest -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z 
-../loba  -c1e6,0 -C1e4,0 -M10 -Tline -amakhoul -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z
\ No newline at end of file
+../loba  -c1e6,0 -C1e4,0 -M10 -Tline -amakhoul -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z
+
+#tres leger avant pour best en calcul, avant pour makhoul en comm
+
+../loba  -c1e6,0 -C1e4,0 -M10 -Tline -a2best -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z -R -r34
+../loba  -c1e6,0 -C1e4,0 -M10 -Tline -abest -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z -R -r 34
+../loba  -c1e6,0 -C1e4,0 -M10 -Tline -amakhoul -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z -R -r34
+
+# kifkif
+../loba  -c1e8,0 -C1e4,0 -M10 -Tline -abest -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z -R -r 34
+../loba  -c1e8,0 -C1e4,0 -M10 -Tline -amakhoul -N0 -L-1000 -t10000 cluster256.xml -l100 -b -Z -R -r34
+
+
+#idem calcul, makhoul bcp - de comm
+../loba  -c1e6,0 -C1e4,0 -M10 -Thcube -abest -N0 -L-1000 -t2000 cluster256.xml -l100 -b -Z -R -r 34
+../loba  -c1e6,0 -C1e4,0 -M10 -Thcube -amakhoul -N0 -L-1000 -t2000 cluster256.xml -l100 -b -Z -R -r34
\ No newline at end of file
diff --git a/loba_makhoul3.cpp b/loba_makhoul3.cpp
new file mode 100644
index 0000000..9517002
--- /dev/null
+++ b/loba_makhoul3.cpp
@@ -0,0 +1,37 @@
+#include <xbt/log.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
+
+#include "loba_makhoul3.h"
+
+void loba_makhoul3::load_balance()
+{
+    pneigh_sort_by_load(std::less<double>());
+    print_loads_p(false, xbt_log_priority_debug);
+
+		int nb_less_loaded=0;
+		for (unsigned i = 0 ; i < pneigh.size() ; ++i) {
+			nb_less_loaded+=(pneigh[i]->get_load()<=get_load());
+		}
+
+    double alpha = 1.0 / (nb_less_loaded );
+    double my_load = get_load();
+    bool cont = true;
+    for (unsigned i = 0 ;
+         cont && i < pneigh.size() && pneigh[i]->get_load() < my_load ; ++i) {
+
+        double delta = my_load - pneigh[i]->get_load();
+        double transfer = alpha * delta;
+        XBT_DEBUG("delta = %g ; transfer = %g", delta, transfer);
+        if (pneigh[i]->get_load() + transfer <= get_load() - transfer) {
+            send(pneigh[i], transfer);
+            XBT_DEBUG("sent %g to %s", transfer, pneigh[i]->get_name());
+        } else {
+            cont = false;
+        }
+    }
+}
+
+// Local variables:
+// mode: c++
+// End:
diff --git a/loba_makhoul3.h b/loba_makhoul3.h
new file mode 100644
index 0000000..2aa7085
--- /dev/null
+++ b/loba_makhoul3.h
@@ -0,0 +1,19 @@
+#ifndef LOBA_MAKHOUL3_H
+#define LOBA_MAKHOUL3_H
+
+#include "process.h"
+
+class loba_makhoul3: public process {
+public:
+    loba_makhoul3(int argc, char* argv[]): process(argc, argv) { }
+    ~loba_makhoul3()                                           { }
+
+private:
+    void load_balance();
+};
+
+#endif //!LOBA_MAKHOUL3_H
+
+// Local variables:
+// mode: c++
+// End:
diff --git a/options.cpp b/options.cpp
index b387267..482d486 100644
--- a/options.cpp
+++ b/options.cpp
@@ -17,6 +17,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
 #include "loba_lln.h"
 #include "loba_makhoul.h"
 #include "loba_makhoul2.h"
+#include "loba_makhoul3.h"
 #include "loba_simple.h"
 #include "misc.h"
 
@@ -96,6 +97,8 @@ namespace opt {
                    loba_makhoul);
         NOL_INSERT("makhoul2", "balance with Makhoul's source code",
                    loba_makhoul2);
+        NOL_INSERT("makhoul3", "describe your algorithm here...",
+                   loba_makhoul3);
         NOL_INSERT("none", "no load-balancing (for testing only)",
                    process);
         NOL_INSERT("simple", "balance with least loaded neighbor",
-- 
2.39.5