SRC.loba := main.cpp \
communicator.cpp \
cost_func.cpp \
+ misc.cpp \
neighbor.cpp \
options.cpp \
process.cpp \
--- /dev/null
+#include "misc.h"
+
+namespace misc {
+ const char str_esse[] = "s";
+ const char str_nil[] = "";
+}
#define LOG_ISENABLED(priority) \
(_XBT_LOG_ISENABLEDV((*_XBT_LOGV(default)), (priority)))
-#define ESSE(n) ((n) > 1 ? "s" : "")
+namespace misc {
+ extern const char str_esse[];
+ extern const char str_nil[];
+}
+/* Returns c-string "s" if n > 1, empty string "" otherwise. */
+#define ESSE(n) ((n) > 1 ? misc::str_esse : misc::str_nil)
#endif // !MISC_H
int help_requested = 0;
bool version_requested = false;
+ unsigned log_rate = 1;
+
unsigned maxiter = 4;
bool exit_on_close = false;
int c;
opterr = 0;
- while ((c = getopt(*argc, argv, "bc:ehi:V")) != -1) {
+ while ((c = getopt(*argc, argv, "bc:ehi:l:V")) != -1) {
switch (c) {
case 'b':
opt::bookkeeping = true;
case 'i':
std::istringstream(optarg) >> opt::maxiter;
break;
+ case 'l':
+ std::istringstream(optarg) >> opt::log_rate;
+ break;
case 'V':
opt::version_requested = true;
break;
INFO0(",----[ Simulation parameters ]");
INFO1("| platform_file.......: \"%s\"", opt::platform_file);
INFO1("| application_file....: \"%s\"", opt::application_file);
+ INFO1("| log rate............: %u", opt::log_rate);
INFO1("| maxiter.............: %u", opt::maxiter);
INFO1("| exit on close.......: %s", on_off(opt::exit_on_close));
INFO1("| bookkeeping.........: %s", on_off(opt::bookkeeping));
std::clog << oo("-i", "value")
<< "maximum number of iterations, 0 for infinity ("
<< opt::maxiter << ")\n";
+ std::clog << oo("-l", "value")
+ << "print current load every \"value\" iterations, 0 to disable ("
+ << opt::log_rate << ")\n";
#undef o
#undef oo
extern int help_requested;
extern bool version_requested;
+ extern unsigned log_rate;
+
extern unsigned maxiter;
extern bool exit_on_close;
e_xbt_log_priority_t logp = xbt_log_priority_verbose;
if (!LOG_ISENABLED(logp))
return;
- LOG1(logp, "My initial load is: %g", load);
std::ostringstream oss;
oss << neigh.size() << " neighbor";
if (!neigh.empty()) {
{
bool one_more = true;
unsigned iter = 0;
+
+ INFO1("Initial load: %g", load);
VERB0("Starting...");
while (one_more) {
bool close_received;
+ ++iter;
- if (opt::bookkeeping)
- INFO3("(%u) current load: %g ; expected: %g",
- iter, load, expected_load);
- else
- INFO2("(%u) current load: %g",
- iter, load);
+ if (opt::log_rate && iter % opt::log_rate == 0) {
+ if (opt::bookkeeping)
+ INFO3("(%u) current load: %g ; expected: %g",
+ iter, load, expected_load);
+ else
+ INFO2("(%u) current load: %g",
+ iter, load);
+ }
compute();
close_received = !receive(false);
*/
comm.flush(false);
- ++iter;
if (opt::exit_on_close && close_received)
one_more = false;
*/
VERB0("Done.");
+ if (opt::bookkeeping)
+ INFO4("Final load after %d iteration%s: %g ; expected: %g",
+ iter, ESSE(iter), load, expected_load);
+ else
+ INFO3("Final load after %d iteration%s: %g", iter, ESSE(iter), load);
return 0;
}
#include <sys/time.h>
#include <sys/resource.h>
-#if NEED_TIMERCLEAR
-inline
-void timerclear(struct timeval& a)
-{
- tv.sec = tv.usec = 0;
-}
+#ifdef _BSD_SOURCE
+# define HAVE_TIMERADD
+# define HAVE_TIMERSUB
+# define HAVE_TIMERCLEAR
+#else
+# warning _BSD_SOURCE not defined
+# undef HAVE_TIMERADD
+# undef HAVE_TIMERSUB
+# undef HAVE_TIMERCLEAR
#endif
inline
struct timeval operator+(const struct timeval& a, const struct timeval& b)
{
struct timeval result;
+#ifdef HAVE_TIMERADD
+ timeradd(&a, &b, &result);
+#else
result.tv_sec = a.tv_sec + b.tv_sec;
result.tv_usec = a.tv_usec + b.tv_usec;
if (result.tv_usec >= 1000000) {
++result.tv_sec;
result.tv_usec -= 1000000;
}
+#endif
return result;
}
struct timeval operator-(const struct timeval& a, const struct timeval& b)
{
struct timeval result;
+#ifdef HAVE_TIMERSUB
+ timersub(&a, &b, &result);
+#else
result.tv_sec = a.tv_sec - b.tv_sec;
result.tv_usec = a.tv_usec - b.tv_usec;
if (result.tv_usec < 0) {
- -- result.tv_sec;
+ --result.tv_sec;
result.tv_usec += 1000000;
}
+#endif
return result;
}
-double timertod(const struct timeval& a)
-{
- return a.tv_sec + a.tv_usec / 1e6;
-}
-
class timestamp {
+public:
+ timestamp();
+ ~timestamp();
+ void reset();
+
+ void start();
+ void stop();
+
+ struct timeval tv_duration() const;
+ double duration() const;
+
private:
struct rusage before;
struct rusage after;
struct timeval difference;
-public:
- timestamp()
- {
- reset();
- }
+ static void tv_clear(struct timeval& a);
+ static double timertod(const struct timeval& a);
+};
- void reset()
- {
- timerclear(&before.ru_utime);
- timerclear(&before.ru_stime);
- timerclear(&after.ru_utime);
- timerclear(&after.ru_stime);
- timerclear(&difference);
- }
+inline
+timestamp::timestamp()
+{
+ reset();
+}
- void start()
- {
- getrusage(RUSAGE_SELF, &before);
- }
+inline
+timestamp::~timestamp()
+{
+}
- void stop()
- {
- getrusage(RUSAGE_SELF, &after);
- difference = difference + ((after.ru_utime + after.ru_stime) -
- (before.ru_utime + before.ru_stime));
- }
+inline
+void timestamp::reset()
+{
+ tv_clear(before.ru_utime);
+ tv_clear(before.ru_stime);
+ tv_clear(after.ru_utime);
+ tv_clear(after.ru_stime);
+ tv_clear(difference);
+}
- struct timeval tv_duration() const
- {
- return difference;
- }
+inline
+void timestamp::start()
+{
+ getrusage(RUSAGE_SELF, &before);
+}
- double duration() const
- {
- return timertod(difference);
- }
-};
+inline
+void timestamp::stop()
+{
+ getrusage(RUSAGE_SELF, &after);
+ difference = difference + ((after.ru_utime + after.ru_stime) -
+ (before.ru_utime + before.ru_stime));
+}
+
+inline
+struct timeval timestamp::tv_duration() const
+{
+ return difference;
+}
+
+inline
+double timestamp::duration() const
+{
+ return timertod(difference);
+}
+
+inline
+void timestamp::tv_clear(struct timeval& a)
+{
+#ifdef HAVE_TIMERCLEAR
+ timerclear(&a);
+#else
+ tv.sec = tv.usec = 0;
+#endif
+}
+
+inline
+double timestamp::timertod(const struct timeval& a)
+{
+ return a.tv_sec + a.tv_usec / 1e6;
+}
#endif // !TIMER_H