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

Private GIT Repository
Wip++...
[loba.git] / process.cpp
index e1232f2ac59640923e46f1c5f5f0b627ca0055c8..9988defd083267ef8c197feb47465a8d59a97ee8 100644 (file)
@@ -3,6 +3,7 @@
 #include <algorithm>
 #include <tr1/functional>
 #include <iterator>
+#include <numeric>
 #include <stdexcept>
 #include <sstream>
 #include <xbt/log.h>
 #include "misc.h"
 #include "options.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(proc);
 
 process::process(int argc, char* argv[])
 {
+    using namespace std::tr1;
+    using namespace std::tr1::placeholders;
+
     if (argc < 2 || !(std::istringstream(argv[1]) >> load))
         throw std::invalid_argument("bad or missing initial load");
 
     neigh.assign(argv + 2, argv + argc);
 
     std::for_each(neigh.begin(), neigh.end(),
-                  std::tr1::bind(&process::insert_neighbor_in_map,
-                                 this, std::tr1::placeholders::_1));
+                  bind(&process::insert_neighbor_in_map, this, _1));
+
+    pneigh.resize(neigh.size());
+    std::transform(neigh.begin(), neigh.end(), pneigh.begin(),
+                   misc::address<neighbor>());
 
     expected_load = load;
 
@@ -42,7 +49,7 @@ process::process(int argc, char* argv[])
         oss << ESSE(neigh.size()) << ": ";
         std::transform(neigh.begin(), neigh.end() - 1,
                        std::ostream_iterator<const char*>(oss, ", "),
-                       std::tr1::mem_fn(&neighbor::get_name));
+                       mem_fn(&neighbor::get_name));
         oss << neigh.back().get_name();
     }
     LOG1(logp, "Got %s.", oss.str().c_str());
@@ -59,6 +66,8 @@ int process::run()
 
     INFO1("Initial load: %g", load);
     VERB0("Starting...");
+    // first send to inform neighbors about our load
+    send();
     iter = 0;
     while (one_more) {
         ++iter;
@@ -82,7 +91,6 @@ int process::run()
             load -= load_balance(load);
 
         send();
-        comm.flush(false);
 
         if (opt::exit_on_close && close_received)
             one_more = false;
@@ -107,14 +115,14 @@ int process::run()
     return 0;
 }
 
-void process::compute()
+double process::sum_of_to_send() const
 {
-    // fixme: shall we do something special when duration is 0 ?
-    double duration = opt::comp_cost(load);
-    m_task_t task = MSG_task_create("computation", duration, 0.0, NULL);
-    DEBUG2("compute %g flop%s.", duration, ESSE(duration));
-    MSG_task_execute(task);
-    MSG_task_destroy(task);
+    using namespace std::tr1;
+    using namespace std::tr1::placeholders;
+
+    return std::accumulate(neigh.begin(), neigh.end(), 0.0,
+                           bind(std::plus<double>(),
+                                _1, bind(&neighbor::get_to_send, _2)));
 }
 
 double process::load_balance(double /*my_load*/)
@@ -122,6 +130,21 @@ double process::load_balance(double /*my_load*/)
     return 0.0;
 }
 
+void process::compute()
+{
+    // fixme: shall we do something special when duration is 0 ?
+    double duration = opt::comp_cost(load);
+    if (duration > 0)  {
+        m_task_t task = MSG_task_create("computation", duration, 0.0, NULL);
+        DEBUG2("compute %g flop%s.", duration, ESSE(duration));
+        MSG_task_execute(task);
+        MSG_task_destroy(task);
+    } else {
+        xbt_sleep(42);
+        //        xbt_thread_yield();
+    }
+}
+
 void process::send1_no_bookkeeping(neighbor& nb)
 {
     comm.send(nb.get_ctrl_mbox(), new message(message::INFO, load));
@@ -161,16 +184,16 @@ void process::send1_bookkeeping(neighbor& nb)
 
 void process::send()
 {
+    using namespace std::tr1;
+    using namespace std::tr1::placeholders;
+
     // fixme: shall we send data at all iterations?
-    if (opt::bookkeeping) {
+    if (opt::bookkeeping)
         std::for_each(neigh.begin(), neigh.end(),
-                      std::tr1::bind(&process::send1_bookkeeping,
-                                     this, std::tr1::placeholders::_1));
-    } else {
+                      bind(&process::send1_bookkeeping, this, _1));
+    else
         std::for_each(neigh.begin(), neigh.end(),
-                      std::tr1::bind(&process::send1_no_bookkeeping,
-                                     this, std::tr1::placeholders::_1));
-    }
+                      bind(&process::send1_no_bookkeeping, this, _1));
 }
 
 // Returns false if a CLOSE message was received. 
@@ -221,11 +244,13 @@ void process::finalize1(neighbor& nb)
 
 void process::finalize()
 {
+    using namespace std::tr1;
+    using namespace std::tr1::placeholders;
+
     DEBUG2("send CLOSE to %d neighbor%s.",
            (int )neigh.size(), ESSE(neigh.size()));
     std::for_each(neigh.begin(), neigh.end(),
-                  std::tr1::bind(&process::finalize1,
-                                 this, std::tr1::placeholders::_1));
+                  bind(&process::finalize1, this, _1));
 
     DEBUG2("wait for CLOSE from %d neighbor%s.",
            (int )neigh.size(), ESSE(neigh.size()));