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

Private GIT Repository
Wip++...
[loba.git] / communicator.cpp
index 4b54161108fd6808bb47c8bb8b4ad6cbb163b045..f3de918962815d0c0822fc6aa9f42f7b1b767390 100644 (file)
@@ -7,10 +7,9 @@
 #include <xbt/log.h>
 #include "simgrid_features.h"
 #include "misc.h"
+#include "options.h"
 
-// XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(comm, simu,
-                                "Messages from asynchronous pipes");
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(comm);
 
 std::string message::to_string()
 {
@@ -21,8 +20,11 @@ std::string message::to_string()
     return oss.str();
 }
 
+const int communicator::send_count_before_flush = 128;
+
 communicator::communicator()
     : host((hostdata* )MSG_host_get_data(MSG_host_self()))
+    , send_counter(0)
     , ctrl_task(NULL)
     , ctrl_comm(NULL)
     , ctrl_close_is_last(false)
@@ -53,10 +55,15 @@ void communicator::send(const char* dest, message* msg)
 {
     double msg_size = sizeof *msg;
     if (msg->get_type() == message::LOAD)
-        msg_size += msg->get_amount();
+        msg_size += opt::comm_cost(msg->get_amount());
     m_task_t task = MSG_task_create("message", 0.0, msg_size, msg);    
     msg_comm_t comm = MSG_task_isend(task, dest);
     sent_comm.push_back(comm);
+
+    if (++send_counter >= send_count_before_flush) {
+        flush(false);
+        send_counter = 0;
+    }
 }
 
 bool communicator::recv(message*& msg, m_host_t& from, bool wait)
@@ -103,13 +110,16 @@ bool communicator::recv(message*& msg, m_host_t& from, bool wait)
 
 void communicator::flush(bool wait)
 {
+    using namespace std::tr1;
+    using namespace std::tr1::placeholders;
+
     sent_comm.remove_if(comm_test_n_destroy);
     if (wait && !sent_comm.empty()) {
         xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
         while (!sent_comm.empty()) {
             std::for_each(sent_comm.begin(), sent_comm.end(),
-                          std::tr1::bind(comm_push_in_dynar,
-                                         comms, std::tr1::placeholders::_1));
+                          bind(xbt_dynar_push,
+                               comms, bind(misc::address<msg_comm_t>(), _1)));
             MSG_comm_waitany(comms);
             xbt_dynar_reset(comms);
             sent_comm.remove_if(comm_test_n_destroy);
@@ -128,11 +138,6 @@ void communicator::next_close_on_data_is_last()
     data_close_is_last = true;
 }
 
-void communicator::comm_push_in_dynar(xbt_dynar_t dynar, msg_comm_t comm)
-{
-    xbt_dynar_push(dynar, &comm);
-}
-
 bool communicator::comm_test_n_destroy(msg_comm_t comm)
 {
     if (MSG_comm_test(comm)) {