- DEBUG2("send CLOSE to %d neighbor%s.",
- (int )neigh.size(), ESSE(neigh.size()));
- std::for_each(neigh.begin(), neigh.end(),
- bind(&process::finalize1, this, _1));
+ double balance;
+ if (nb.get_credit() > 0.0)
+ balance = nb.get_debt() - nb.get_credit();
+ else
+ balance = nb.get_debt();
+ load_to_send = std::min(excess_load,
+ std::max(0.0, balance));
+
+ // adjust load to send (rounding, truncation, etc.)
+ load_to_send = compute_load_to_send(load_to_send);
+ if (load_to_send > 0.0)
+ nb.set_debt(nb.get_debt() - load_to_send);
+ } else { // !bookkeeping
+ load_to_send = compute_load_to_send(nb.get_to_send());
+ if (load_to_send > 0.0)
+ nb.set_to_send(nb.get_to_send() - load_to_send);
+ }
+ real_load -= load_to_send;
+ 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::DATA, 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));
+}