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...
core
vgcore.*
localversion
+misc_autogen.h
loba
simple_async
simgrid-dev
MAKEDEPEND.C = $(CC) $(MAKEDEPEND.FLAGS)
MAKEDEPEND.CXX = $(CXX) $(MAKEDEPEND.FLAGS)
-LOCALVERSION := localversion
-SETLOCALVERSION := ./setlocalversion
-
SRC.loba := main.cpp \
communicator.cpp \
cost_func.cpp \
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)
%.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:
-#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()
{
-#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);
-#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()
{
-#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;
-#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
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;
-#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
#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");
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
#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 {
-#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())
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());
+}
#define NEIGHBOR_H
#include <utility>
+#include <xbt/log.h>
#include "hostdata.h"
class neighbor {
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
-#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 {
-#include "process.h"
-
#include <algorithm>
#include <tr1/functional>
#include <iterator>
#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;
oss << neigh.back().get_name();
}
LOG1(logp, "Got %s.", oss.str().c_str());
- print_loads(logp);
+ print_loads(true, logp);
}
process::~process()
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);
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:
# define MAP_TEMPLATE std::map
#endif
#include <msg/msg.h>
+#include <xbt/log.h>
#include "communicator.h"
#include "neighbor.h"
// 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
// all of them to answer.
void finalize1(neighbor& nb);
void finalize();
-
-
};
#endif // !PROCESS_H