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

Private GIT Repository
Add option -G, to exit on detection of global convergence.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 29 Feb 2012 15:59:19 +0000 (16:59 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 29 Feb 2012 15:59:19 +0000 (16:59 +0100)
options.cpp
options.h
process.cpp
process.h

index 7c5a649561c17d672ba42124ea72c7a3a6797081..2db9aeba5b71285803460e83ff1e053903fa4ec7 100644 (file)
@@ -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";
index 264a566f25564831680df3027fc28ff9c5213180..ccb56bd0b8ada2d17761d2aa4888fff8b2cae817 100644 (file)
--- 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
index 36bdff07cfbe8d18bf4eaf1b81d5f0cfa6b8f064..dfbf1239a24b19ee80a5407cb9e51d03d9dec451 100644 (file)
@@ -26,6 +26,8 @@ int process::process_counter = 0;
 double process::total_load_average;
 double process::load_diff_threshold;
 
+std::atomic<int> 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;
index 901d381fabeea8d2dc0025401d7b5966cefac9a4..5e1faa62a152f0bee9ce6f7a5dcd5920c2d50501 100644 (file)
--- a/process.h
+++ b/process.h
@@ -16,6 +16,7 @@
 #include <vector>
 #include <msg/msg.h>
 #include <xbt/log.h>
+#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<int> convergence_counter;
+
     typedef MAP_TEMPLATE<m_host_t, neighbor*> rev_neigh_type;
     neigh_type neigh;           // list of neighbors (do not alter
                                 // after construction!)