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

Private GIT Repository
Add ability to delay the beginning of computations.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 14 Feb 2011 14:07:54 +0000 (15:07 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 14 Feb 2011 14:59:38 +0000 (15:59 +0100)
options.cpp
options.h
process.cpp
process.h

index 107b1804344804456951be5d7131611ae45124c6..9ea0a72927ed0c6d8cac6315c7bf92d53e107569 100644 (file)
@@ -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")
index 8a48ed1e3278cdeb3dcd6a4d5540761214f29d6f..fcb982a5a1e1da3f37c43652015eeb857db9c6dd 100644 (file)
--- 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;
index 65496385f08f45baf7d4e1b8015c78e7f54cf0e4..880bbd0b50c226bb3299470de8bc9ba114103d44 100644 (file)
@@ -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)
index ceca948a39433738d050b20f0864238d5203abf3..3e912f03c68186a860f3a16116f74018c93c7d06 100644 (file)
--- 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();