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

Private GIT Repository
Merge INFO and CREDIT messages.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 24 May 2011 07:02:01 +0000 (09:02 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 24 May 2011 07:48:40 +0000 (09:48 +0200)
It reduces the number of control messages with bookkeeping, and makes
the simulation about 40% faster.

messages.cpp
messages.h
process.cpp

index 025871a12f8f1e4bce39d3674108bee40e9dbed1..2eed581f2bcab777938f898947112893105b4dca 100644 (file)
@@ -8,24 +8,33 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(comm);
 
 #include "messages.h"
 
 
 #include "messages.h"
 
+message::message(message_type t, double a, double c)
+    : type(t), amount(a) , credit(c)
+{
+    // compute message size
+    // arbitrary: 8 for type, and 8 for each double
+    switch (type) {
+    case INFO:
+        size = opt::bookkeeping ? 24 : 16; // type + amount + (credit)?
+        break;
+    case LOAD:
+        size = 16 + opt::comm_cost(amount); // type + amount + data size
+        break;
+    default:
+        size = 8;               // type
+        break;
+    }
+}
+
 std::string message::to_string()
 {
 std::string message::to_string()
 {
-    static const char* str[] = { "INFO", "CREDIT", "LOAD",
-                                 "CTRL_CLOSE", "DATA_CLOSE" };
+    static const char* str[DATA_CLOSE + 1] = { "INFO", "LOAD",
+                                               "CTRL_CLOSE", "DATA_CLOSE" };
     std::ostringstream oss;
     oss << str[type] << ": " << amount;
     return oss.str();
 }
 
     std::ostringstream oss;
     oss << str[type] << ": " << amount;
     return oss.str();
 }
 
-double message::get_size() const
-{
-    // arbitrary: 8 for type, and 8 for amount
-    double size = 16;
-    if (type == LOAD)
-        size += opt::comm_cost(amount);
-    return size;
-}
-
 void message_queue::push(m_task_t task)
 {
     if (queue.push(task)) {
 void message_queue::push(m_task_t task)
 {
     if (queue.push(task)) {
index 8de464ab8f390cb4fb77cc4a647b05f4d5e864e3..1906fdf9b5cd87edaa67ddabdcf0c5be1968e4bd 100644 (file)
@@ -9,19 +9,22 @@
 
 class message {
 public:
 
 class message {
 public:
-    enum message_type { INFO, CREDIT, LOAD, CTRL_CLOSE, DATA_CLOSE };
+    enum message_type { INFO, LOAD, CTRL_CLOSE, DATA_CLOSE };
 
 
-    message(message_type t, double a): type(t), amount(a) { }
+    message(message_type t, double a, double c = 0.0);
 
     message_type get_type() const       { return type;   }
     double get_amount() const           { return amount; }
 
     message_type get_type() const       { return type;   }
     double get_amount() const           { return amount; }
-    double get_size() const;
+    double get_credit() const           { return credit; }
+    double get_size() const             { return size;   }
 
     std::string to_string();
 
 private:
     message_type type;
     double amount;
 
     std::string to_string();
 
 private:
     message_type type;
     double amount;
+    double credit;
+    double size;
 };
 
 class message_queue {
 };
 
 class message_queue {
index b36b000f385309ee102c283c7139244d4c3e8a26..491898d4fae320f56be3f20a2931e0d1fc98bda8 100644 (file)
@@ -286,20 +286,20 @@ void process::send(neighbor& nb, double amount)
 void process::ctrl_send(neighbor& nb)
 {
     double info_to_send = expected_load;
 void process::ctrl_send(neighbor& nb)
 {
     double info_to_send = expected_load;
-    if (info_to_send != prev_load_broadcast) {
-        message* msg = new message(message::INFO, info_to_send);
-        add_ctrl_send_mesg(msg->get_size());
-        comm.ctrl_send(nb.get_ctrl_mbox(), msg);
-    }
-    if (opt::bookkeeping) {
-        double debt_to_send = nb.get_to_send();
+    double debt_to_send;
+    if (opt::bookkeeping) {     // bookkeeping
+        debt_to_send = nb.get_to_send();
         if (debt_to_send > 0.0) {
             nb.set_to_send(0.0);
             nb.set_debt(nb.get_debt() + debt_to_send);
         if (debt_to_send > 0.0) {
             nb.set_to_send(0.0);
             nb.set_debt(nb.get_debt() + debt_to_send);
-            message* msg = new message(message::CREDIT, debt_to_send);
-            add_ctrl_send_mesg(msg->get_size());
-            comm.ctrl_send(nb.get_ctrl_mbox(), msg);
         }
         }
+    } else {                    // !bookkeeping
+        debt_to_send = 0.0;
+    }
+    if (info_to_send != prev_load_broadcast || debt_to_send > 0.0) {
+        message* msg = new message(message::INFO, info_to_send, debt_to_send);
+        add_ctrl_send_mesg(msg->get_size());
+        comm.ctrl_send(nb.get_ctrl_mbox(), msg);
     }
 }
 
     }
 }
 
@@ -380,11 +380,9 @@ void process::handle_message(message* msg, m_host_t from)
     case message::INFO: {
         neighbor* n = rev_neigh[from];
         n->set_load(msg->get_amount() + n->get_to_send());
     case message::INFO: {
         neighbor* n = rev_neigh[from];
         n->set_load(msg->get_amount() + n->get_to_send());
+        expected_load += msg->get_credit(); // may be 0.0 if !opt::bookkeeping
         break;
     }
         break;
     }
-    case message::CREDIT:
-        expected_load += msg->get_amount();
-        break;
     case message::LOAD: {
         double ld = msg->get_amount();
         real_load += ld;
     case message::LOAD: {
         double ld = msg->get_amount();
         real_load += ld;