]> AND Private Git Repository - loba.git/commitdiff
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Remove usage of std::bind. sg_v3_7_1
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Apr 2018 12:16:15 +0000 (14:16 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Apr 2018 12:35:40 +0000 (14:35 +0200)
communicator.cpp
cost_func.cpp
deployment.cpp
hostdata.cpp
loba_2besteffort.cpp
process.cpp
process.h

index 5abb543582c617a948258fc16845abafbf56cfaa..40752c5241ab791d9ec747cd5e714fd50d9105b7 100644 (file)
@@ -1,5 +1,4 @@
 #include <algorithm>
-#include <functional>
 #include <msg/msg.h>
 #include <xbt/log.h>
 
@@ -23,8 +22,7 @@ namespace {
 communicator::communicator()
     : host(static_cast<hostdata*>(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();
 }
 
index d6cba8c88ed667484b1f6af6ce0b95a3ec9244da..4248c5654c568221667a5afd21169941ffec6c4e 100644 (file)
@@ -1,5 +1,4 @@
 #include <algorithm>
-#include <functional>
 #include <numeric>
 #include <iterator>
 #include <sstream>
@@ -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<double>(),
-                                     std::bind(std::multiplies<double>(),
-                                               amount, _1), _2));
+                           [&amount](double a, double b) {
+                               return amount * a + b;
+                           });
 }
 
 std::string cost_func::to_string()
index bbb47e5392a1b55d58d5bb16e1e4a31e9b9df2cd..0a5db8c014078d13c2d41374ce9b2058618d3e73 100644 (file)
@@ -1,7 +1,6 @@
 #include <algorithm>
 #include <cmath>
 #include <cstdlib>
-#include <functional>
 #include <iomanip>
 #include <numeric>
 #include <sstream>
@@ -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<double>(), _1, factor));
+                   [&factor](double a) { return factor * a; });
     if (opt::integer_transfer) {
         double iload;
         double residue = 0.0;
index 88ca6fde2f197305879f8dea66e86521b9a74d5a..be62d4d83129d252bb3edb35ac4e951bf53c8190 100644 (file)
@@ -1,6 +1,5 @@
 #include <algorithm>
 #include <cstring>
-#include <functional>
 #include <stdexcept>
 #include <xbt/log.h>
 #include <xbt/sysdep.h>
@@ -16,19 +15,15 @@ std::vector<hostdata> 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<msg_host_t*>(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<int>(),
-                            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);
 
index 82fcd3659abbe1454367c4dca75f67c8f68197c6..5573714463bb607fe9b3cdb10246e78e1925eff1 100644 (file)
@@ -1,5 +1,4 @@
 #include <cmath>                // std::isfinite
-#include <functional>
 #include <numeric>
 #include <xbt/log.h>
 
@@ -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<double>());
     print_loads_p(false, xbt_log_priority_debug);
 
     double sum = get_load() +
         std::accumulate(pneigh.begin(), pneigh.end(), 0.0,
-                        std::bind(std::plus<double>(), _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);
 
index 3413931f058c1603994fbfa1ece1da06ebb542ca..811804fa81558253c282b3975751673e4d98f1da 100644 (file)
@@ -1,6 +1,5 @@
 #include <algorithm>
 #include <cmath>
-#include <functional>
 #include <iterator>
 #include <numeric>
 #include <stdexcept>
@@ -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<const char*>(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<double>(), _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
index 81e68d9006e8a02ffd6aa798728cf4302f31ccc7..c9873e010b7bdcda562599813656de11a3d3bb2f 100644 (file)
--- a/process.h
+++ b/process.h
@@ -6,7 +6,6 @@
 
 #include <algorithm>
 #include <atomic>
-#include <functional>
 #ifdef USE_UNORDERED_MAP
 #  include <unordered_map>
 #  define MAP_TEMPLATE std::unordered_map
@@ -205,12 +204,10 @@ private:
 template <typename Compare>
 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