]> 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 76058180c01d7a4e08cd008b07eaa043e0575fbf..b30fab4b0a9d8a43838e1d346bade1e06baa64f8 100644 (file)
@@ -4,22 +4,19 @@
 #include <stdexcept>
 #include <sstream>
 #include <xbt/log.h>
 #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);
 
 #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);
 {
     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;
     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,
     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);
     }
     LOG1(logp, "Got %s.", oss.str().c_str());
     print_loads(logp);
@@ -40,7 +37,16 @@ process::process(int argc, char *argv[])
 int process::run()
 {
     INFO0("Coucou !");
 int process::run()
 {
     INFO0("Coucou !");
-    MSG_process_sleep(100.0);   // xxx
+
+    int n = 100;
+    while (n--) {
+        if (load > 0)
+            compute();
+        else
+            xbt_sleep(0.5);     // fixme
+        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;
@@ -48,6 +54,8 @@ int process::run()
      *    compute load balancing;
      *    send tasks to neighbors;
      * }
      *    compute load balancing;
      *    send tasks to neighbors;
      * }
+     * finalize;
+     * wait for pending messages;
      */
 
     /* Open Questions :
      */
 
     /* Open Questions :
@@ -61,14 +69,40 @@ int process::run()
     return 0;
 }
 
     return 0;
 }
 
+void process::receive()
+{
+    message* msg;
+    m_host_t from;
+    while (comm.recv(msg, from)) {
+        switch (msg->get_type()) {
+        case message::INFO:
+            // fixme: update neighbor
+            break;
+        case message::CREDIT:
+            expected_load += msg->get_amount();
+            break;
+        case message::LOAD:
+            load += msg->get_amount();
+            break;
+        }
+        delete msg;
+    }
+}
+
 void process::compute()
 {
     double duration = opt::comp_cost(load);
     m_task_t task = MSG_task_create("computation", duration, 0.0, NULL);
 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);
 }
 
     MSG_task_execute(task);
     MSG_task_destroy(task);
 }
 
+void process::finalize()
+{
+    // fixme
+}
+
 void process::print_loads(e_xbt_log_priority_t logp)
 {
     if (!LOG_ISENABLED(logp))
 void process::print_loads(e_xbt_log_priority_t logp)
 {
     if (!LOG_ISENABLED(logp))
@@ -79,8 +113,8 @@ void process::print_loads(e_xbt_log_priority_t logp)
     } else {
         std::transform(neigh.begin(), neigh.end() - 1,
                        std::ostream_iterator<double>(oss, ", "),
     } 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());
 }
     }
     LOG1(logp, "Neighbor loads: %s", oss.str().c_str());
 }