From 245565c060611ddfed5067ab4000e91e440c402c Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 29 Feb 2012 16:59:19 +0100 Subject: [PATCH] Add option -G, to exit on detection of global convergence. --- options.cpp | 9 ++++++++- options.h | 1 + process.cpp | 9 +++++++++ process.h | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/options.cpp b/options.cpp index 7c5a649..2db9aeb 100644 --- a/options.cpp +++ b/options.cpp @@ -80,6 +80,7 @@ namespace opt { unsigned lb_maxiter = 0; unsigned comp_maxiter = 0; double time_limit = 0; + bool exit_on_convergence = false; bool exit_on_close = true; // Named parameters lists @@ -233,7 +234,7 @@ bool opt::parse_args(int* argc, char* argv[]) opterr = 0; while ((c = getopt(*argc, argv, "%:" - "a:bc:C:d:D:eEhi:I:k:l:L:m:M:N:r:Rs:S:t:T:vVx:X:Z")) + "a:bc:C:d:D:eEGhi:I:k:l:L:m:M:N:r:Rs:S:t:T:vVx:X:Z")) != -1) { switch (c) { case '%': @@ -279,6 +280,9 @@ bool opt::parse_args(int* argc, char* argv[]) case 'E': opt::egocentric = !opt::egocentric; break; + case 'G': + opt::exit_on_convergence = !opt::exit_on_convergence; + break; case 'h': opt::help_requested++; break; @@ -443,6 +447,7 @@ void opt::print() h.val_or_string(comp_maxiter, "no limit")); DESCR("convergence is assumed within (\%)", "%g", opt::avg_load_ratio); DESCR("time limit", "%s", h.val_or_string(time_limit, "no limit")); + DESCR("exit on convergence", "%s", h.on_off(exit_on_convergence)); DESCR("exit on close", "%s", h.on_off(exit_on_close)); XBT_INFO("`----"); @@ -564,6 +569,8 @@ void opt::usage() std::clog << o("-% value") << "percent of the load average to assume the convergence" << " [" << opt::avg_load_ratio << "]\n"; + std::clog << o("-G") << "toggle exit on detection of convergence" + << " [" << opt_helper::on_off(opt::exit_on_convergence) << "]\n"; std::clog << o("-t value") << "time limit (simulated time), 0 for no limit" << " [" << opt::time_limit << "]\n"; diff --git a/options.h b/options.h index 264a566..ccb56bd 100644 --- a/options.h +++ b/options.h @@ -63,6 +63,7 @@ namespace opt { extern unsigned lb_maxiter; extern unsigned comp_maxiter; extern double time_limit; + extern bool exit_on_convergence; extern bool exit_on_close; // Named parameters lists diff --git a/process.cpp b/process.cpp index 36bdff0..dfbf123 100644 --- a/process.cpp +++ b/process.cpp @@ -26,6 +26,8 @@ int process::process_counter = 0; double process::total_load_average; double process::load_diff_threshold; +std::atomic process::convergence_counter(0); + namespace { void sleep_until_date(double& date, double duration) @@ -69,6 +71,7 @@ process::process(int argc, char* argv[]) proc_mutex->acquire(); process_counter++; + convergence_counter++; total_load_init += real_load; total_load_running += real_load; total_load_average = total_load_running / process_counter; @@ -291,12 +294,14 @@ void process::convergence_check() XBT_VERB("current load has diverged: %g (%.4g%%)", real_load, 100.0 * load_diff / average); convergence = -1.0; + convergence_counter++; } } else { if (converged) { XBT_VERB("current load has converged: %g (%.4g%%)", real_load, 100.0 * load_diff / average); convergence = MSG_get_clock(); + convergence_counter--; } } } @@ -324,6 +329,10 @@ bool process::still_running() XBT_VERB("Reached comp_maxiter: %d/%d", comp_iter, opt::comp_maxiter); last_status = false; + } else if (opt::exit_on_convergence && convergence_counter == 0) { + XBT_VERB("Global convergence detected"); + last_status = false; + } else if (opt::exit_on_close && close_received) { XBT_VERB("Close received"); last_status = false; diff --git a/process.h b/process.h index 901d381..5e1faa6 100644 --- a/process.h +++ b/process.h @@ -16,6 +16,7 @@ #include #include #include +#include "atomic_compat.h" #include "communicator.h" #include "misc.h" #include "msg_thread.h" @@ -98,6 +99,8 @@ private: static double total_load_average; static double load_diff_threshold; + static std::atomic convergence_counter; + typedef MAP_TEMPLATE rev_neigh_type; neigh_type neigh; // list of neighbors (do not alter // after construction!) -- 2.39.5