X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/5279f43fc9be71815091e79c76d5bc04c8c88421..f7a78d4e11841dea09a3c0cb60f55a689856a22f:/communicator.cpp?ds=sidebyside diff --git a/communicator.cpp b/communicator.cpp index 0c64b5b..1570b10 100644 --- a/communicator.cpp +++ b/communicator.cpp @@ -3,38 +3,35 @@ #include #include #include -#include "communicator.h" -#include "simgrid_features.h" + +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(comm); + #include "misc.h" +#include "options.h" -// XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu); -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(comm, simu, - "Messages from asynchronous pipes"); +#include "communicator.h" std::string message::to_string() { static const char* str[] = { "INFO", "CREDIT", "LOAD", "CTRL_CLOSE", "DATA_CLOSE" }; std::ostringstream oss; - oss << str[type] << " (" << amount << ")"; + oss << str[type] << ": " << amount; return oss.str(); } +const int communicator::send_count_before_flush = 4; + 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) + , data_task(NULL) + , data_comm(NULL) + , data_close_is_last(false) { - const char* hostname = MSG_host_get_name(MSG_host_self()); - - ctrl_mbox = hostname; - ctrl_mbox += "_ctrl"; - ctrl_task = NULL; - ctrl_comm = NULL; - ctrl_close_is_last = false; - - data_mbox = hostname; - data_mbox += "_data"; - data_task = NULL; - data_comm = NULL; - data_close_is_last = false; } communicator::~communicator() @@ -56,12 +53,18 @@ void communicator::listen() void communicator::send(const char* dest, message* msg) { + DEBUG2("send %s to %s", msg->to_string().c_str(), dest); 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,18 +106,25 @@ bool communicator::recv(message*& msg, m_host_t& from, bool wait) } } while (restart); + if (msg) + DEBUG2("received %s from %s", + msg->to_string().c_str(), MSG_host_get_name(from)); + return msg != NULL; } 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(), _1))); MSG_comm_waitany(comms); xbt_dynar_reset(comms); sent_comm.remove_if(comm_test_n_destroy); @@ -133,11 +143,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)) {