From: Arnaud Giersch Date: Mon, 30 Apr 2018 12:16:15 +0000 (+0200) Subject: Remove usage of std::bind. X-Git-Tag: sg_v3_7_1 X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/commitdiff_plain/d9fabc892aa327eabb9cae3e2fa7f5f330077220?ds=sidebyside Remove usage of std::bind. --- diff --git a/communicator.cpp b/communicator.cpp index 5abb543..40752c5 100644 --- a/communicator.cpp +++ b/communicator.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -23,8 +22,7 @@ namespace { communicator::communicator() : host(static_cast(MSG_host_get_data(MSG_host_self()))) { - receiver_thread = new_msg_thread("receiver", - std::bind(&communicator::receiver, this)); + receiver_thread = new_msg_thread("receiver", [this]() { this->receiver(); }); receiver_thread->start(); } diff --git a/cost_func.cpp b/cost_func.cpp index d6cba8c..4248c56 100644 --- a/cost_func.cpp +++ b/cost_func.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -30,12 +29,10 @@ cost_func::~cost_func() double cost_func::operator()(double amount) const { - using std::placeholders::_1; - using std::placeholders::_2; return std::accumulate(++factors.begin(), factors.end(), factors.front(), - std::bind(std::plus(), - std::bind(std::multiplies(), - amount, _1), _2)); + [&amount](double a, double b) { + return amount * a + b; + }); } std::string cost_func::to_string() diff --git a/deployment.cpp b/deployment.cpp index bbb47e5..0a5db8c 100644 --- a/deployment.cpp +++ b/deployment.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -51,8 +50,6 @@ void deployment_generator::set_link(int host1, int host2) void deployment_generator::distribute_load() { - using std::placeholders::_1; - if (!opt::auto_depl::random_distribution) { set_load(0, opt::auto_depl::load); return; @@ -67,7 +64,7 @@ void deployment_generator::distribute_load() double factor = opt::auto_depl::load / std::accumulate(loads.begin(), loads.end(), 0.0); std::transform(loads.begin(), loads.end(), loads.begin(), - std::bind(std::multiplies(), _1, factor)); + [&factor](double a) { return factor * a; }); if (opt::integer_transfer) { double iload; double residue = 0.0; diff --git a/hostdata.cpp b/hostdata.cpp index 88ca6fd..be62d4d 100644 --- a/hostdata.cpp +++ b/hostdata.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -16,19 +15,15 @@ std::vector hostdata::hosts; void hostdata::create() { - using std::placeholders::_1; - using std::placeholders::_2; - xbt_dynar_t host_dynar = MSG_hosts_as_dynar(); int nhosts = xbt_dynar_length(host_dynar); msg_host_t* host_list = static_cast(xbt_dynar_to_array(host_dynar)); // only sort hosts for automatically created deployment if (opt::auto_depl::enabled) std::sort(host_list, host_list + nhosts, - std::bind(std::less(), - std::bind(strcmp, - std::bind(MSG_host_get_name, _1), - std::bind(MSG_host_get_name, _2)), 0)); + [](msg_host_t a, msg_host_t b) { + return std::strcmp(MSG_host_get_name(a), MSG_host_get_name(b)) < 0; + }); hosts.assign(host_list, host_list + nhosts); xbt_free(host_list); diff --git a/loba_2besteffort.cpp b/loba_2besteffort.cpp index 82fcd36..5573714 100644 --- a/loba_2besteffort.cpp +++ b/loba_2besteffort.cpp @@ -1,5 +1,4 @@ #include // std::isfinite -#include #include #include @@ -9,16 +8,14 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba); void loba_2besteffort::load_balance() { - using std::placeholders::_1; - using std::placeholders::_2; - pneigh_sort_by_load(std::less()); print_loads_p(false, xbt_log_priority_debug); double sum = get_load() + std::accumulate(pneigh.begin(), pneigh.end(), 0.0, - std::bind(std::plus(), _1, - std::bind(&neighbor::get_load, _2))); + [](double x, const neighbor* n) { + return x + n->get_load(); + }); double mean = sum / (pneigh.size() + 1); XBT_DEBUG("sum = %g ; mean = %g", sum, mean); diff --git a/process.cpp b/process.cpp index 3413931..811804f 100644 --- a/process.cpp +++ b/process.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -90,8 +89,7 @@ process::process(int argc, char* argv[]) all_comp_iter = comp_iter = lb_iter = 0; - lb_thread = new_msg_thread("loba", - std::bind(&process::load_balance_loop, this)); + lb_thread = new_msg_thread("loba", [this]() { this->load_balance_loop(); }); e_xbt_log_priority_t logp = xbt_log_priority_verbose; if (!LOG_ISENABLED(logp)) @@ -102,7 +100,7 @@ process::process(int argc, char* argv[]) oss << ESSE(neigh.size()) << ": "; std::transform(neigh.begin(), neigh.end() - 1, std::ostream_iterator(oss, ", "), - std::mem_fn(&neighbor::get_name)); + [](const neighbor& neigh) { return neigh.get_name(); }); oss << neigh.back().get_name(); } XBT_LOG(logp, "Got %s.", oss.str().c_str()); @@ -170,8 +168,6 @@ int process::run() void process::load_balance_loop() { - using std::placeholders::_1; - double next_iter_after_date = MSG_get_clock() + opt::min_lb_iter_duration; while (still_running()) { if (lb_iter == opt::comp_iter_delay) { @@ -203,8 +199,8 @@ void process::load_balance_loop() // send comm.ctrl_flush(false); - std::for_each(neigh.begin(), neigh.end(), - std::bind(&process::ctrl_send, this, _1)); + for (neighbor& n : neigh) + ctrl_send(n); prev_load_broadcast = expected_load; mutex.release(); @@ -214,8 +210,8 @@ void process::load_balance_loop() XBT_VERB("Going to finalize for %s...", __func__); XBT_DEBUG("send CTRL_CLOSE to %zu neighbor%s", neigh.size(), ESSE(neigh.size())); - std::for_each(neigh.begin(), neigh.end(), - std::bind(&process::ctrl_close, this, _1)); + for (neighbor& n : neigh) + ctrl_close(n); while (ctrl_close_pending) { comm.ctrl_flush(false); XBT_DEBUG("waiting for %d CTRL_CLOSE", ctrl_close_pending); @@ -226,8 +222,6 @@ void process::load_balance_loop() void process::compute_loop() { - using std::placeholders::_1; - double next_iter_after_date = MSG_get_clock() + opt::min_comp_iter_duration; double idle_since_date = 0.0; while (still_running()) { @@ -241,8 +235,8 @@ void process::compute_loop() mutex.acquire(); real_load += received_load; received_load = 0.0; - std::for_each(neigh.begin(), neigh.end(), - std::bind(&process::data_send, this, _1)); + for (neighbor& n : neigh) + data_send(n); mutex.release(); ++all_comp_iter; @@ -272,8 +266,8 @@ void process::compute_loop() finalizing = true; XBT_DEBUG("send DATA_CLOSE to %zu neighbor%s", neigh.size(), ESSE(neigh.size())); - std::for_each(neigh.begin(), neigh.end(), - std::bind(&process::data_close, this, _1)); + for (neighbor& n : neigh) + data_close(n); while (data_close_pending) { comm.data_flush(false); XBT_DEBUG("waiting for %d DATA_CLOSE", data_close_pending); @@ -362,12 +356,10 @@ bool process::still_running() double process::get_sum_of_to_send() const { - using std::placeholders::_1; - using std::placeholders::_2; - return std::accumulate(neigh.begin(), neigh.end(), 0.0, - std::bind(std::plus(), _1, - std::bind(&neighbor::get_to_send, _2))); + [](double x, const neighbor& neigh) { + return x + neigh.get_to_send(); + }); } void process::load_balance() @@ -521,27 +513,28 @@ void process::handle_message(message* msg, msg_host_t from) delete msg; } -#define print_loads_generic(vec, verbose, logp, cat) \ - if (_XBT_LOG_ISENABLEDV((*cat), logp)) { \ - using std::placeholders::_1; \ - XBT_XCLOG(cat, logp, "My load: %g (real); %g (expected). " \ - "Neighbor loads:", real_load, expected_load); \ - std::for_each(vec.begin(), vec.end(), \ - std::bind(&neighbor::print, _1, verbose, logp, cat)); \ - } else ((void)0) - void process::print_loads(bool verbose, e_xbt_log_priority_t logp, xbt_log_category_t cat) const { - print_loads_generic(neigh, verbose, logp, cat); + if (!_XBT_LOG_ISENABLEDV((*cat), logp)) + return; + XBT_XCLOG(cat, logp, "My load: %g (real); %g (expected). Neighbor loads:", + real_load, expected_load); + for (const neighbor& n : neigh) + n.print(verbose, logp, cat); } void process::print_loads_p(bool verbose, e_xbt_log_priority_t logp, xbt_log_category_t cat) const { - print_loads_generic(pneigh, verbose, logp, cat); + if (!_XBT_LOG_ISENABLEDV((*cat), logp)) + return; + XBT_XCLOG(cat, logp, "My load: %g (real); %g (expected). Neighbor loads:", + real_load, expected_load); + for (const neighbor* n : pneigh) + n->print(verbose, logp, cat); } #undef print_loads_generic diff --git a/process.h b/process.h index 81e68d9..c9873e0 100644 --- a/process.h +++ b/process.h @@ -6,7 +6,6 @@ #include #include -#include #ifdef USE_UNORDERED_MAP # include # define MAP_TEMPLATE std::unordered_map @@ -205,12 +204,10 @@ private: template void process::pneigh_sort_by_load(const Compare& comp) { - using std::placeholders::_1; - using std::placeholders::_2; std::sort(pneigh.begin(), pneigh.end(), - std::bind(comp, - std::bind(&neighbor::get_load, _1), - std::bind(&neighbor::get_load, _2))); + [&comp](const neighbor* a, const neighbor* b) { + return comp(a->get_load(), b->get_load()); + }); } #endif // !PROCESS_H