]> 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 8ceb4692fd00c9e2c2e5a28b45555a7ec9b7efe5..d1576cef6f6330589d79edaec9d2e7a396045163 100644 (file)
@@ -5,6 +5,7 @@
 #include <sstream>
 #include <xbt/log.h>
 #include "misc.h"
 #include <sstream>
 #include <xbt/log.h>
 #include "misc.h"
+#include "options.h"
 #include "process.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
 #include "process.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
@@ -36,26 +37,16 @@ process::process(int argc, char *argv[])
     print_loads(logp);
 }
 
     print_loads(logp);
 }
 
-void process::print_loads(e_xbt_log_priority_t logp)
-{
-    if (!LOG_ISENABLED(logp))
-        return;
-    std::ostringstream oss;
-    if (neigh.empty()) {
-        oss << "no neighbor!";
-    } else {
-        std::transform(neigh.begin(), neigh.end() - 1,
-                       std::ostream_iterator<double>(oss, ", "),
-                       std::mem_fun_ref(&neighbor::getLoad));
-        oss << neigh.back().getLoad();
-    }
-    LOG1(logp, "Neighbor loads: %s", oss.str().c_str());
-}
-
 int process::run()
 {
     INFO0("Coucou !");
 int process::run()
 {
     INFO0("Coucou !");
-    MSG_process_sleep(100.0);   // xxx
+
+    int n = 100;
+    while (n--) {
+        compute();
+        receive();
+    }
+    //    MSG_process_sleep(100.0);   // xxx
     /* xxx:
      * while (there is something to do) {
      *    compute some task;
     /* xxx:
      * while (there is something to do) {
      *    compute some task;
@@ -76,6 +67,45 @@ int process::run()
     return 0;
 }
 
     return 0;
 }
 
+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);
+    }
+}
+
+void process::compute()
+{
+    double duration = opt::comp_cost(load);
+    m_task_t task = MSG_task_create("computation", duration, 0.0, NULL);
+    DEBUG2("Compute %g flop%s.", duration, duration > 1 ? "s" : "");
+    MSG_task_execute(task);
+    MSG_task_destroy(task);
+}
+
+void process::print_loads(e_xbt_log_priority_t logp)
+{
+    if (!LOG_ISENABLED(logp))
+        return;
+    std::ostringstream oss;
+    if (neigh.empty()) {
+        oss << "no neighbor!";
+    } else {
+        std::transform(neigh.begin(), neigh.end() - 1,
+                       std::ostream_iterator<double>(oss, ", "),
+                       std::mem_fun_ref(&neighbor::getLoad));
+        oss << neigh.back().getLoad();
+    }
+    LOG1(logp, "Neighbor loads: %s", oss.str().c_str());
+}
+
 // Local variables:
 // mode: c++
 // End:
 // Local variables:
 // mode: c++
 // End: