From: Arnaud Giersch Date: Mon, 14 Feb 2011 14:07:54 +0000 (+0100) Subject: Add ability to delay the beginning of computations. X-Git-Tag: v0.1~130 X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/commitdiff_plain/fb7c087879f5cfc2657a4fc04847106b5f75c122 Add ability to delay the beginning of computations. --- diff --git a/options.cpp b/options.cpp index 107b180..9ea0a72 100644 --- a/options.cpp +++ b/options.cpp @@ -53,6 +53,8 @@ namespace opt { cost_func comp_cost("1e9, 0"); // fixme: find better defaults cost_func comm_cost("1e6, 0"); // fixme: find better defaults double min_comp_iter_duration = 1.0; // fixme: find better defaults + unsigned comp_iter_delay = 0; // fixme: find better defaults + double comp_time_delay = 0.0; // fixme: find better defaults // Parameters for the end of the simulation unsigned lb_maxiter = 0; @@ -194,7 +196,8 @@ bool opt::parse_args(int* argc, char* argv[]) int c; opterr = 0; - while ((c = getopt(*argc, argv, "a:bc:C:ehi:I:l:L:N:s:S:t:T:vV")) != -1) { + while ((c = getopt(*argc, argv, + "a:bc:C:d:D:ehi:I:l:L:N:s:S:t:T:vV")) != -1) { switch (c) { case 'a': opt::loba_algo = optarg; @@ -228,6 +231,12 @@ bool opt::parse_args(int* argc, char* argv[]) result = false; } break; + case 'd': + PARSE_ARG(opt::comp_iter_delay); + break; + case 'D': + PARSE_ARG(opt::comp_time_delay); + break; case 'i': PARSE_ARG(opt::lb_maxiter); break; @@ -322,6 +331,8 @@ void opt::print() DESCR("computation cost factors", "[%s]", comp_cost.to_string().c_str()); DESCR("communication cost factors", "[%s]", comm_cost.to_string().c_str()); DESCR("minimum duration between comp. iterations", "%g", min_comp_iter_duration); + DESCR("computations start after lb. iter", "%u", comp_iter_delay); + DESCR("computations start after time", "%g", comp_time_delay); DESCR("maximum number of lb. iterations", "%s", h.val_or_string(lb_maxiter, "infinity")); DESCR("maximum number of comp. iterations", "%s", @@ -402,6 +413,12 @@ void opt::usage() std::clog << o("-S value") << "minimum duration between comp. iterations" << " [" << opt::min_comp_iter_duration << "]\n"; + std::clog << o("-d value") + << "start computations after given number of lb iterations" + << " [" << opt::comp_iter_delay << "]\n"; + std::clog << o("-D value") + << "start computations after given time" + << " [" << opt::comp_time_delay << "]\n"; std::clog << "\nParameters for the end of the simulation\n"; std::clog << o("-i value") diff --git a/options.h b/options.h index 8a48ed1..fcb982a 100644 --- a/options.h +++ b/options.h @@ -39,6 +39,8 @@ namespace opt { extern std::string loba_algo; extern bool bookkeeping; extern double min_lb_iter_duration; + extern unsigned comp_iter_delay; + extern double comp_time_delay; // Application parameters extern cost_func comp_cost; diff --git a/process.cpp b/process.cpp index 6549638..880bbd0 100644 --- a/process.cpp +++ b/process.cpp @@ -99,7 +99,14 @@ int process::run() if (opt::log_rate >= 0) XBT_INFO("Initial load: %g", real_load); XBT_VERB("Starting..."); + mutex.acquire(); lb_thread->start(); + while (lb_iter <= opt::comp_iter_delay) + cond.wait(mutex); + mutex.release(); + double sleep_duration = opt::comp_time_delay - MSG_get_clock(); + if (sleep_duration > 0.0) + MSG_process_sleep(sleep_duration); compute_loop(); lb_thread->wait(); XBT_VERB("Done."); @@ -113,7 +120,14 @@ void process::load_balance_loop() double next_iter_after_date = MSG_get_clock() + opt::min_lb_iter_duration; while (still_running()) { - ++lb_iter; + if (lb_iter == opt::comp_iter_delay) { + mutex.acquire(); + ++lb_iter; + cond.signal(); + mutex.release(); + } else { + ++lb_iter; + } if (opt::log_rate && lb_iter % opt::log_rate == 0) { if (opt::bookkeeping) diff --git a/process.h b/process.h index ceca948..3e912f0 100644 --- a/process.h +++ b/process.h @@ -21,6 +21,7 @@ #include "msg_thread.h" #include "neighbor.h" #include "options.h" +#include "synchro.h" class process { public: @@ -97,6 +98,9 @@ private: double real_load; // current load double expected_load; // expected load in bookkeeping mode + mutex_t mutex; // synchronization between threads + condition_t cond; + // Load-balancing loop msg_thread* lb_thread; void load_balance_loop();