#include <algorithm>
#include <tr1/functional>
#include <iterator>
+#include <numeric>
#include <stdexcept>
#include <sstream>
#include <xbt/log.h>
#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<neighbor>());
expected_load = load;
oss << ESSE(neigh.size()) << ": ";
std::transform(neigh.begin(), neigh.end() - 1,
std::ostream_iterator<const char*>(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());
INFO1("Initial load: %g", load);
VERB0("Starting...");
+ // first send to inform neighbors about our load
+ send();
iter = 0;
while (one_more) {
++iter;
load -= load_balance(load);
send();
- comm.flush(false);
if (opt::exit_on_close && close_received)
one_more = false;
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<double>(),
+ _1, bind(&neighbor::get_to_send, _2)));
}
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));
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.
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()));