]> 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 d1576cef6f6330589d79edaec9d2e7a396045163..4ee3647d6895c4eef6586f92f29ffc498b45b14e 100644 (file)
@@ -4,22 +4,19 @@
 #include <stdexcept>
 #include <sstream>
 #include <xbt/log.h>
+#include <xbt/time.h>
 #include "misc.h"
 #include "options.h"
 #include "process.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
 
-struct message {
-    double measure;
-    double transfer;
-};
-
-process::process(int argc, char *argv[])
+process::process(int argc, char* argv[])
 {
     if (argc < 2 || !(std::istringstream(argv[1]) >> load))
         throw std::invalid_argument("bad or missing initial load");
     neigh.assign(argv + 2, argv + argc);
+    expected_load = load;
     e_xbt_log_priority_t logp = xbt_log_priority_verbose;
     if (!LOG_ISENABLED(logp))
         return;
@@ -29,9 +26,9 @@ process::process(int argc, char *argv[])
     if (!neigh.empty()) {
         oss << (neigh.size() > 1 ? "s: " : ": ");
         std::transform(neigh.begin(), neigh.end() - 1,
-                       std::ostream_iterator<std::string>(oss, ", "),
-                       std::mem_fun_ref(&neighbor::getName));
-        oss << neigh.back().getName();
+                       std::ostream_iterator<const char*>(oss, ", "),
+                       std::mem_fun_ref(&neighbor::get_name));
+        oss << neigh.back().get_name();
     }
     LOG1(logp, "Got %s.", oss.str().c_str());
     print_loads(logp);
@@ -43,7 +40,10 @@ int process::run()
 
     int n = 100;
     while (n--) {
-        compute();
+        if (load > 0)
+            compute();
+        else
+            xbt_sleep(0.5);     // fixme
         receive();
     }
     //    MSG_process_sleep(100.0);   // xxx
@@ -69,16 +69,24 @@ int process::run()
 
 void process::receive()
 {
-    m_task_t task;
-    while ((task = comm.recv())) {
-        message *msg = (message *)MSG_task_get_data(task);
-        DEBUG3("Received load: %g, info: %g from %s",
-               msg->transfer, msg->measure,
-               MSG_host_get_name(MSG_task_get_source(task)));
-        load += msg->transfer;
-        // fixme: what is xxx ???
-        // neigh[xxx].setLoad(msg->measure);
-    }
+    bool received;
+    do {
+        double amount;
+        m_host_t from;
+        received = false;
+        if (comm.recv_info(amount, from)) {
+            // fixme: update neighbor
+            received = true;
+        }
+        if (comm.recv_credit(amount, from)) {
+            expected_load += amount;
+            received = true;
+        }
+        if (comm.recv_load(amount, from)) {
+            load += amount;
+            received = true;
+        }
+    } while (received);
 }
 
 void process::compute()
@@ -100,8 +108,8 @@ void process::print_loads(e_xbt_log_priority_t logp)
     } else {
         std::transform(neigh.begin(), neigh.end() - 1,
                        std::ostream_iterator<double>(oss, ", "),
-                       std::mem_fun_ref(&neighbor::getLoad));
-        oss << neigh.back().getLoad();
+                       std::mem_fun_ref(&neighbor::get_load));
+        oss << neigh.back().get_load();
     }
     LOG1(logp, "Neighbor loads: %s", oss.str().c_str());
 }