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

Private GIT Repository
Define process::print_loads_p() to print loads by using neighp[]
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 17 Dec 2010 17:04:45 +0000 (18:04 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 17 Dec 2010 17:04:45 +0000 (18:04 +0100)
instead of neigh[].

In order to achieve this cleanly, define neighbor::print().
The logging category is (by default) the default for the current
compilation unit.

I had to torture xbt/log to attain my goal...

15 files changed:
.gitignore
Makefile
communicator.cpp
cost_func.cpp
deployment.cpp
hostdata.cpp
loba_fairstrategy.cpp
loba_simple.cpp
main.cpp
misc.h
neighbor.cpp
neighbor.h
options.cpp
process.cpp
process.h

index 06c52541d74b5cf3da8d3ac976069c22c1a9974d..4995cafae6699f0e445238185afc301469487be6 100644 (file)
@@ -4,6 +4,7 @@
 core
 vgcore.*
 localversion
+misc_autogen.h
 loba
 simple_async
 simgrid-dev
index 2ab9e7bee0393c381fbc4a02d3e0842ea03d6608..c5202cf0239512c9bd9b1c7bb0bcf6666ba05ae7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,9 +28,6 @@ MAKEDEPEND.FLAGS =  $(CPPFLAGS) -MM -MF $@ $<
 MAKEDEPEND.C = $(CC) $(MAKEDEPEND.FLAGS)
 MAKEDEPEND.CXX = $(CXX) $(MAKEDEPEND.FLAGS)
 
-LOCALVERSION := localversion
-SETLOCALVERSION := ./setlocalversion
-
 SRC.loba := main.cpp           \
        communicator.cpp        \
        cost_func.cpp           \
@@ -51,15 +48,14 @@ DEP := $(SRC:%.cpp=%.d)
 
 TARGETS := loba simple_async
 
-$(shell $(SETLOCALVERSION))
-
 .PHONY: all clean realclean
 
 all: $(TARGETS)
 
 clean:
        $(RM) core core.[0-9]* vgcore.[0-9]*
-       $(RM) $(LOCALVERSION)
+       $(RM) misc_autogen.h
+       $(RM) localversion
        $(RM) $(OBJ)
        $(RM) $(DEP)
        $(RM) $(TARGETS)
@@ -70,12 +66,17 @@ realclean: clean
 %.d: %.c ; $(MAKEDEPEND.C)
 %.d: %.cpp ; $(MAKEDEPEND.CXX)
 
+misc_autogen.h: $(SIMGRID_INSTALL_DIR)/include/xbt/log.h
+       grep -C1 '# *define *CLOG' $< \
+       | sed 's/CLOG/XCLOG/;s/_XBT_LOGV\(([^)]*)\)/(*\1)/' > $@
+
 version.o: $(patsubst %.cpp,%.o,$(filter-out version.cpp, $(SRC.loba)))
 
 ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(MAKECMDGOALS),realclean)
--include $(DEP)
-endif
+  ifneq ($(MAKECMDGOALS),realclean)
+    $(shell ./setlocalversion)
+    -include $(DEP)
+  endif
 endif
 
 .SECONDEXPANSION:
index e6653ebda4e9acf52d0c5a40acd8e8c4f09f1d61..054c98a6c53078d1dcd16b81be2ab889e1e9f588 100644 (file)
@@ -1,14 +1,15 @@
-#include "communicator.h"
-
 #include <algorithm>
 #include <tr1/functional>
 #include <sstream>
 #include <msg/msg.h>
 #include <xbt/log.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(comm);
+
 #include "misc.h"
 #include "options.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(comm);
+#include "communicator.h"
 
 std::string message::to_string()
 {
index d102fd90772c1abd310ca54333acfbe1ee49fdab..73111999216e837fe156e5dbc0eb23d0c6ef3f7c 100644 (file)
@@ -1,11 +1,11 @@
-#include "cost_func.h"
-
 #include <algorithm>
 #include <cstdlib>
 #include <cstring>
 #include <iterator>
 #include <sstream>
 
+#include "cost_func.h"
+
 cost_func::cost_func(const char* param)
 {
     int len = strlen(param);
index a28d8d99ab3d75084be9de8a4ddac4e6c4557169..29de927fa45566845a2ea899e311b0674e210973 100644 (file)
@@ -1,14 +1,15 @@
-#include "deployment.h"
-
 #include <iomanip>
 #include <sstream>
 #include <msg/msg.h>
 #include <xbt/dynar.h>
 #include <xbt/log.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
+
 #include "hostdata.h"
 #include "options.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(depl);
+#include "deployment.h"
 
 void MY_launch_application()
 {
index 3ac7b0b540b02f4a5cc3063dadfc0ac2496ae12b..8a86eb976f3c9941ce17b85815167dba10a9a8e8 100644 (file)
@@ -1,14 +1,15 @@
-#include "hostdata.h"
-
 #include <cstring>
 #include <algorithm>
 #include <stdexcept>
 #include <xbt/log.h>
 #include <xbt/sysdep.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
+
 #include "misc.h"
 #include "options.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
+#include "hostdata.h"
 
 std::vector<hostdata> hostdata::hosts;
 
index 81de9e100a7e0941fbe0974e35d9c56e949cb7f3..eb05b492d9adc4222ab64524164e25d1a40a286e 100644 (file)
@@ -1,9 +1,10 @@
-#include "loba_fairstrategy.h"
 #include <algorithm>
 #include <xbt/log.h>
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
 
+#include "loba_fairstrategy.h"
+
 /* simple version:
  *   load balance with a least-loaded neighbor,
  *   without breaking the ping-pong condition
@@ -25,12 +26,7 @@ double loba_fairstrategy::load_balance(double my_load)
 
                std::sort(pneigh.begin(),pneigh.end(),compare());
 
-               //print_loads();
-
-               INFO0("list voisins");
-               for(unsigned i=0;i< pneigh.size() ; ++i) {
-                       INFO2("%s %f ", pneigh[i]->get_name(), pneigh[i]->get_load());
-               }
+               print_loads_p();
 
                double sum_sent=0;
                bool found=true;
index d44a1de27ad855bf4599de5ec291a1d2fa1e073f..d79ead5b41af70f619175c491c0e8c6105d9e943 100644 (file)
@@ -1,9 +1,9 @@
-#include "loba_simple.h"
-
 #include <xbt/log.h>
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
 
+#include "loba_simple.h"
+
 /* simple version:
  *   load balance with a least-loaded neighbor,
  *   without breaking the ping-pong condition
index 3ee3ae1544ea3152b8ce4b8de5a32247442c80d7..fe584f725f6518347b6e4b096ff10198888bb8a0 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -3,13 +3,6 @@
 #include <stdexcept>
 #include <msg/msg.h>
 #include <xbt/log.h>
-#include "deployment.h"
-#include "hostdata.h"
-#include "misc.h"
-#include "options.h"
-#include "process.h"
-#include "timer.h"
-#include "version.h"
 
 // Creates log categories
 XBT_LOG_NEW_CATEGORY(simu, "Root of simulation messages");
@@ -21,6 +14,14 @@ XBT_LOG_NEW_SUBCATEGORY(loba, simu, "Messages from load-balancer");
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
 
+#include "deployment.h"
+#include "hostdata.h"
+#include "misc.h"
+#include "options.h"
+#include "process.h"
+#include "timer.h"
+#include "version.h"
+
 // Failure exit status
 enum {
     EXIT_NO_FAILURE    = 0x00,  // no error
diff --git a/misc.h b/misc.h
index 2ec625b943070406ffde59d903d9e87f12d2b1a5..974f66608ebf3dbea68a531547011a360bd2e304 100644 (file)
--- a/misc.h
+++ b/misc.h
 #define LOG_ISENABLED(priority) \
     (_XBT_LOG_ISENABLEDV((*_XBT_LOGV(default)), (priority)))
 
+/* Defines XCLOGn(...) which behave like CLOGn(...), except that the
+ * given category is not passed through _XBT_LOGV before use.
+ * (auto-generated, like its name says...)
+ */
+#include "misc_autogen.h"
+
 /* Returns c-string "s" if n > 1, empty string "" otherwise. */
 #define ESSE(n) ((n) > 1 ? misc::str_esse : misc::str_nil)
 namespace misc {
index 3340f8f49678998415d94a3fb9f5b83f43b6128d..c45fc8f3c4daa41627b3ec87f2a7ce72d9c85f9e 100644 (file)
@@ -1,8 +1,12 @@
-#include "neighbor.h"
-
 #include <limits>
 #include <msg/msg.h>
 
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(proc); // needed to compile neighbor.h
+
+#include "misc.h"
+
+#include "neighbor.h"
+
 neighbor::neighbor(const char* hostname)
     : host((hostdata* )MSG_host_get_data(MSG_get_host_by_name(hostname)))
     , load(std::numeric_limits<double>::infinity())
@@ -14,3 +18,13 @@ neighbor::neighbor(const char* hostname)
 neighbor::~neighbor()
 {
 }
+
+void neighbor::print(bool verbose,
+                     e_xbt_log_priority_t logp, xbt_log_category_t cat) const
+{
+    if (verbose)
+        XCLOG4(cat, logp, "%s: load = %g ; debt = %g ; to_send = %g",
+              get_name(), get_load(), get_debt(), get_to_send());
+    else
+        XCLOG2(cat, logp, "%s: load = %g", get_name(), get_load());
+}
index 58f6c1cfac6a937ea09691b4d73cd5971b0bdf92..ba50f2e45871f3702e22533f1808d17aa92bd868 100644 (file)
@@ -2,6 +2,7 @@
 #define NEIGHBOR_H
 
 #include <utility>
+#include <xbt/log.h>
 #include "hostdata.h"
 
 class neighbor {
@@ -27,6 +28,12 @@ public:
     void set_to_send(double amount)     { to_send = amount; }
     void add_to_send(double amount)     { to_send += amount; }
 
+    // Prints its name and load on given category, with given
+    // priority.  If verbose is true, prints debt and to_send too.
+    void print(bool verbose = false,
+               e_xbt_log_priority_t logp = xbt_log_priority_info,
+               xbt_log_category_t cat = _XBT_LOGV(default)) const;
+
 private:
     const hostdata* host;       // pointer to this neighbor's hostdata
 
index e41347071d8194c0d8977e251ce12f0e3d310626..a8178a9e6c8231237b393afbdae542580a3ec9ad 100644 (file)
@@ -1,14 +1,15 @@
-#include "options.h"
-
 #include <iomanip>
 #include <iostream>
 #include <sstream>
 #include <unistd.h>             // getopt
 #include <xbt/log.h>
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
+
 #include "loba_simple.h"
 #include "loba_fairstrategy.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
+#include "options.h"
 
 namespace opt {
 
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:
index df0cfe5fc19682172030a5e27769708a25877aa4..68dcd9b71fecc45abc4dbc9f27c51b5e07348c34 100644 (file)
--- a/process.h
+++ b/process.h
@@ -13,6 +13,7 @@
 #  define MAP_TEMPLATE std::map
 #endif
 #include <msg/msg.h>
+#include <xbt/log.h>
 #include "communicator.h"
 #include "neighbor.h"
 
@@ -35,12 +36,20 @@ protected:
 
     // Returns the sum of "to_send" for all neighbors.
     double sum_of_to_send() const;
-    // Print with given priority what we know about our neighbors' loads
-    void print_loads(e_xbt_log_priority_t logp = xbt_log_priority_info);
+
+    // Calls neighbor::print(verbose, logp, cat) for each member of neigh.
+    void print_loads(bool verbose = false,
+                     e_xbt_log_priority_t logp = xbt_log_priority_info,
+                     xbt_log_category_t cat = _XBT_LOGV(default)) const;
+
+    // Calls neighbor::print(verbose, logp, cat) for each member of pneigh.
+    void print_loads_p(bool verbose = false,
+                       e_xbt_log_priority_t logp = xbt_log_priority_info,
+                       xbt_log_category_t cat = _XBT_LOGV(default)) const;
 
 private:
-    static double total_load_init;
-    static double total_load_exit;
+    static double total_load_init; // sum of neighbor loads at init
+    static double total_load_exit; // sum of neighbor loads at exit
 
     typedef MAP_TEMPLATE<m_host_t, neighbor*> rev_neigh_type;
     neigh_type neigh;           // list of neighbors (do not alter
@@ -84,8 +93,6 @@ private:
     // all of them to answer.
     void finalize1(neighbor& nb);
     void finalize();
-
-
 };
 
 #endif // !PROCESS_H