+ load_to_send = nb.get_to_send();
+ if (load_to_send >= opt::min_transfer_amount) {
+ nb.set_to_send(0.0);
+ real_load -= load_to_send;
+ } else {
+ load_to_send = 0.0;
+ }
+ }
+ while (load_to_send > 0.0) {
+ double amount;
+ if (opt::max_transfer_amount)
+ amount = std::min(load_to_send, opt::max_transfer_amount);
+ else
+ amount = load_to_send;
+ message* msg = new message(message::LOAD, amount);
+ add_data_send_mesg(msg->get_size());
+ comm.data_send(nb.get_data_mbox(), msg);
+ load_to_send -= amount;
+ }
+}
+
+void process::ctrl_close(neighbor& nb)
+{
+ comm.ctrl_send(nb.get_ctrl_mbox(), new message(message::CTRL_CLOSE, 0.0));
+}
+
+void process::data_close(neighbor& nb)
+{
+ comm.data_send(nb.get_data_mbox(), new message(message::DATA_CLOSE, 0.0));
+}
+
+void process::ctrl_receive(double timeout)
+{
+ message* msg;
+ m_host_t from;
+
+ XBT_DEBUG("%sblocking receive on ctrl (%g)", "\0non-" + !timeout, timeout);
+ while (ctrl_close_pending && comm.ctrl_recv(msg, from, timeout)) {
+ if (msg->get_type() != message::CTRL_CLOSE)
+ add_ctrl_recv_mesg(msg->get_size());
+ handle_message(msg, from);
+ timeout = 0.0;
+ }
+}
+
+void process::data_receive(double timeout)
+{
+ message* msg;
+ m_host_t from;
+
+ XBT_DEBUG("%sblocking receive on data (%g)", "\0non-" + !timeout, timeout);
+ while (data_close_pending && comm.data_recv(msg, from, timeout)) {
+ if (msg->get_type() != message::DATA_CLOSE)
+ add_data_recv_mesg(msg->get_size());
+ handle_message(msg, from);
+ timeout = 0.0;
+ }
+}
+
+void process::handle_message(message* msg, m_host_t from)
+{
+ switch (msg->get_type()) {
+ case message::INFO: {
+ neighbor* n = rev_neigh[from];
+ n->set_load(msg->get_amount() + n->get_to_send());
+ break;
+ }
+ case message::CREDIT:
+ expected_load += msg->get_amount();
+ break;
+ case message::LOAD: {
+ double ld = msg->get_amount();
+ real_load += ld;
+ if (finalizing)
+ total_load_running -= ld;
+ break;