11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simu);
18 process::process(int argc, char *argv[])
20 if (argc < 2 || !(std::istringstream(argv[1]) >> load))
21 throw std::invalid_argument("bad or missing initial load");
22 neigh.assign(argv + 2, argv + argc);
23 e_xbt_log_priority_t logp = xbt_log_priority_verbose;
24 if (!LOG_ISENABLED(logp))
26 LOG1(logp, "My initial load is: %g", load);
27 std::ostringstream oss;
28 oss << neigh.size() << " neighbor";
30 oss << (neigh.size() > 1 ? "s: " : ": ");
31 std::transform(neigh.begin(), neigh.end() - 1,
32 std::ostream_iterator<std::string>(oss, ", "),
33 std::mem_fun_ref(&neighbor::getName));
34 oss << neigh.back().getName();
36 LOG1(logp, "Got %s.", oss.str().c_str());
49 // MSG_process_sleep(100.0); // xxx
51 * while (there is something to do) {
54 * compute load balancing;
55 * send tasks to neighbors;
60 * - definition of load on heterogeneous hosts ?
61 * - how to detect convergence ?
62 * - how to manage link failures ?
65 // xxx: shall we retrieve pending tasks?
70 void process::receive()
73 while ((task = comm.recv())) {
74 message *msg = (message *)MSG_task_get_data(task);
75 DEBUG3("Received load: %g, info: %g from %s",
76 msg->transfer, msg->measure,
77 MSG_host_get_name(MSG_task_get_source(task)));
78 load += msg->transfer;
79 // fixme: what is xxx ???
80 // neigh[xxx].setLoad(msg->measure);
84 void process::compute()
86 double duration = opt::comp_cost(load);
87 m_task_t task = MSG_task_create("computation", duration, 0.0, NULL);
88 DEBUG2("Compute %g flop%s.", duration, duration > 1 ? "s" : "");
89 MSG_task_execute(task);
90 MSG_task_destroy(task);
93 void process::print_loads(e_xbt_log_priority_t logp)
95 if (!LOG_ISENABLED(logp))
97 std::ostringstream oss;
99 oss << "no neighbor!";
101 std::transform(neigh.begin(), neigh.end() - 1,
102 std::ostream_iterator<double>(oss, ", "),
103 std::mem_fun_ref(&neighbor::getLoad));
104 oss << neigh.back().getLoad();
106 LOG1(logp, "Neighbor loads: %s", oss.str().c_str());