12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
14 process::process(int argc, char* argv[])
16 if (argc < 2 || !(std::istringstream(argv[1]) >> load))
17 throw std::invalid_argument("bad or missing initial load");
18 neigh.assign(argv + 2, argv + argc);
20 e_xbt_log_priority_t logp = xbt_log_priority_verbose;
21 if (!LOG_ISENABLED(logp))
23 LOG1(logp, "My initial load is: %g", load);
24 std::ostringstream oss;
25 oss << neigh.size() << " neighbor";
27 oss << (neigh.size() > 1 ? "s: " : ": ");
28 std::transform(neigh.begin(), neigh.end() - 1,
29 std::ostream_iterator<const char*>(oss, ", "),
30 std::mem_fun_ref(&neighbor::get_name));
31 oss << neigh.back().get_name();
33 LOG1(logp, "Got %s.", oss.str().c_str());
46 xbt_sleep(0.5); // fixme
49 // MSG_process_sleep(100.0); // xxx
51 * while (there is something to do) {
54 * compute load balancing;
55 * send tasks to neighbors;
58 * wait for pending messages;
62 * - definition of load on heterogeneous hosts ?
63 * - how to detect convergence ?
64 * - how to manage link failures ?
67 // xxx: shall we retrieve pending tasks?
72 void process::receive()
76 while (comm.recv(msg, from)) {
77 switch (msg->get_type()) {
79 // fixme: update neighbor
82 expected_load += msg->get_amount();
85 load += msg->get_amount();
92 void process::compute()
94 double duration = opt::comp_cost(load);
95 m_task_t task = MSG_task_create("computation", duration, 0.0, NULL);
96 DEBUG2("Compute %g flop%s.", duration, duration > 1 ? "s" : "");
97 MSG_task_execute(task);
98 MSG_task_destroy(task);
101 void process::finalize()
106 void process::print_loads(e_xbt_log_priority_t logp)
108 if (!LOG_ISENABLED(logp))
110 std::ostringstream oss;
112 oss << "no neighbor!";
114 std::transform(neigh.begin(), neigh.end() - 1,
115 std::ostream_iterator<double>(oss, ", "),
116 std::mem_fun_ref(&neighbor::get_load));
117 oss << neigh.back().get_load();
119 LOG1(logp, "Neighbor loads: %s", oss.str().c_str());