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

Private GIT Repository
Define process::print_loads_p() to print loads by using neighp[]
[loba.git] / process.cpp
index 1556f3c4f8ba72df25c2ab9a98f3bfc09e0c42e7..214b9d05a785d80edeb436f14466a6d8140545d9 100644 (file)
@@ -1,5 +1,3 @@
-#include "process.h"
-
 #include <algorithm>
 #include <tr1/functional>
 #include <iterator>
@@ -8,10 +6,13 @@
 #include <sstream>
 #include <xbt/log.h>
 #include <xbt/time.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(proc);
+
 #include "misc.h"
 #include "options.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(proc);
+#include "process.h"
 
 double process::total_load_init = 0.0;
 double process::total_load_exit = 0.0;
@@ -55,7 +56,7 @@ process::process(int argc, char* argv[])
         oss << neigh.back().get_name();
     }
     LOG1(logp, "Got %s.", oss.str().c_str());
-    print_loads(logp);
+    print_loads(true, logp);
 }
 
 process::~process()
@@ -82,7 +83,7 @@ int process::run()
                 INFO2("(%u) current load: %g",
                       iter, load);
         }
-        print_loads(xbt_log_priority_debug);
+        print_loads(true, xbt_log_priority_debug);
 
         if (opt::bookkeeping)
             expected_load -= load_balance(expected_load);
@@ -281,23 +282,31 @@ void process::finalize()
     comm.flush(true);
 }
 
-void process::print_loads(e_xbt_log_priority_t logp)
+#define print_loads_generic(vec, verbose, logp, cat)                    \
+    if (_XBT_LOG_ISENABLEDV((*cat), logp)) {                            \
+        using namespace std::tr1;                                       \
+        using namespace std::tr1::placeholders;                         \
+        XCLOG0(cat, logp, "Neighbor loads:");                           \
+        std::for_each(vec.begin(), vec.end(),                           \
+                      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
 {
-    if (!LOG_ISENABLED(logp))
-        return;
+    print_loads_generic(neigh, verbose, logp, cat);
+}
 
-    std::ostringstream oss;
-    if (neigh.empty()) {
-        oss << "no neighbor!";
-    } else {
-        std::transform(neigh.begin(), neigh.end() - 1,
-                       std::ostream_iterator<double>(oss, ", "),
-                       std::tr1::mem_fn(&neighbor::get_load));
-        oss << neigh.back().get_load();
-    }
-    LOG1(logp, "Neighbor loads: %s", oss.str().c_str());
+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);
 }
 
+#undef print_loads_generic
+
 // Local variables:
 // mode: c++
 // End: