X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/4f8948b8f67d26726a2e53c9afe1a110c037ce4b..325b135f0ee33c6c0242a14e2f58a54fb571b032:/process.cpp diff --git a/process.cpp b/process.cpp index e1232f2..9988def 100644 --- a/process.cpp +++ b/process.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,18 +11,24 @@ #include "misc.h" #include "options.h" -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu); +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(proc); process::process(int argc, char* argv[]) { + using namespace std::tr1; + using namespace std::tr1::placeholders; + if (argc < 2 || !(std::istringstream(argv[1]) >> load)) throw std::invalid_argument("bad or missing initial load"); neigh.assign(argv + 2, argv + argc); std::for_each(neigh.begin(), neigh.end(), - std::tr1::bind(&process::insert_neighbor_in_map, - this, std::tr1::placeholders::_1)); + bind(&process::insert_neighbor_in_map, this, _1)); + + pneigh.resize(neigh.size()); + std::transform(neigh.begin(), neigh.end(), pneigh.begin(), + misc::address()); expected_load = load; @@ -42,7 +49,7 @@ process::process(int argc, char* argv[]) oss << ESSE(neigh.size()) << ": "; std::transform(neigh.begin(), neigh.end() - 1, std::ostream_iterator(oss, ", "), - std::tr1::mem_fn(&neighbor::get_name)); + mem_fn(&neighbor::get_name)); oss << neigh.back().get_name(); } LOG1(logp, "Got %s.", oss.str().c_str()); @@ -59,6 +66,8 @@ int process::run() INFO1("Initial load: %g", load); VERB0("Starting..."); + // first send to inform neighbors about our load + send(); iter = 0; while (one_more) { ++iter; @@ -82,7 +91,6 @@ int process::run() load -= load_balance(load); send(); - comm.flush(false); if (opt::exit_on_close && close_received) one_more = false; @@ -107,14 +115,14 @@ int process::run() return 0; } -void process::compute() +double process::sum_of_to_send() const { - // fixme: shall we do something special when duration is 0 ? - double duration = opt::comp_cost(load); - m_task_t task = MSG_task_create("computation", duration, 0.0, NULL); - DEBUG2("compute %g flop%s.", duration, ESSE(duration)); - MSG_task_execute(task); - MSG_task_destroy(task); + using namespace std::tr1; + using namespace std::tr1::placeholders; + + return std::accumulate(neigh.begin(), neigh.end(), 0.0, + bind(std::plus(), + _1, bind(&neighbor::get_to_send, _2))); } double process::load_balance(double /*my_load*/) @@ -122,6 +130,21 @@ double process::load_balance(double /*my_load*/) return 0.0; } +void process::compute() +{ + // fixme: shall we do something special when duration is 0 ? + double duration = opt::comp_cost(load); + if (duration > 0) { + m_task_t task = MSG_task_create("computation", duration, 0.0, NULL); + DEBUG2("compute %g flop%s.", duration, ESSE(duration)); + MSG_task_execute(task); + MSG_task_destroy(task); + } else { + xbt_sleep(42); + // xbt_thread_yield(); + } +} + void process::send1_no_bookkeeping(neighbor& nb) { comm.send(nb.get_ctrl_mbox(), new message(message::INFO, load)); @@ -161,16 +184,16 @@ void process::send1_bookkeeping(neighbor& nb) void process::send() { + using namespace std::tr1; + using namespace std::tr1::placeholders; + // fixme: shall we send data at all iterations? - if (opt::bookkeeping) { + if (opt::bookkeeping) std::for_each(neigh.begin(), neigh.end(), - std::tr1::bind(&process::send1_bookkeeping, - this, std::tr1::placeholders::_1)); - } else { + bind(&process::send1_bookkeeping, this, _1)); + else std::for_each(neigh.begin(), neigh.end(), - std::tr1::bind(&process::send1_no_bookkeeping, - this, std::tr1::placeholders::_1)); - } + bind(&process::send1_no_bookkeeping, this, _1)); } // Returns false if a CLOSE message was received. @@ -221,11 +244,13 @@ void process::finalize1(neighbor& nb) void process::finalize() { + using namespace std::tr1; + using namespace std::tr1::placeholders; + DEBUG2("send CLOSE to %d neighbor%s.", (int )neigh.size(), ESSE(neigh.size())); std::for_each(neigh.begin(), neigh.end(), - std::tr1::bind(&process::finalize1, - this, std::tr1::placeholders::_1)); + bind(&process::finalize1, this, _1)); DEBUG2("wait for CLOSE from %d neighbor%s.", (int )neigh.size(), ESSE(neigh.size()));