From 07a0aaa69d81731f3b74c63bdbb311587d9cf4f9 Mon Sep 17 00:00:00 2001
From: Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Date: Mon, 20 Jun 2011 16:10:42 +0200
Subject: [PATCH] Add the possibility to specify the initial load with the
 average among the nodes.

If the value given for the '-L' option is negative, it is the
opposite of the load average.

For backward compatibility, '-L 0' is a synonym for '-L -1' (load
average of 1.0).
---
 main.cpp    |  6 +++++-
 options.cpp | 10 ++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/main.cpp b/main.cpp
index ed8039e..5cf3728 100644
--- a/main.cpp
+++ b/main.cpp
@@ -243,8 +243,12 @@ int main(int argc, char* argv[])
                          opt::auto_depl::nhosts, hostdata::size());
                 opt::auto_depl::nhosts = hostdata::size();
             }
-            if (!opt::auto_depl::load)
+            if (opt::auto_depl::load == 0.0) {
+                XBT_WARN("Initial load is zero!  Falling back on old behaviour.");
                 opt::auto_depl::load = opt::auto_depl::nhosts;
+            } else if (opt::auto_depl::load < 0.0)
+                opt::auto_depl::load =
+                    -opt::auto_depl::load * opt::auto_depl::nhosts;
             MY_launch_application(); // it is already opt::* aware...
         } else {
             MSG_launch_application(opt::deployment_file.c_str());
diff --git a/options.cpp b/options.cpp
index 2eb891d..cac9752 100644
--- a/options.cpp
+++ b/options.cpp
@@ -51,7 +51,7 @@ namespace opt {
         bool        enabled = false;
         std::string topology("clique");
         unsigned    nhosts = 0;
-        double      load = 0.0;
+        double      load = -1.0;
         bool        random_distribution = false;
         unsigned long random_seed = 0;
     }
@@ -379,8 +379,10 @@ void opt::print()
         DESCR("- topology", "%s", auto_depl::topology.c_str());
         DESCR("- number of hosts", "%s", h.val_or_string(auto_depl::nhosts,
                                                          "auto"));
-        DESCR("- initial load", "%s", h.val_or_string(auto_depl::load,
-                                                      "auto"));
+        if (auto_depl::load < 0.0)
+            DESCR("- initial load (average)", "%g", -auto_depl::load);
+        else
+            DESCR("- initial load (total)", "%g", auto_depl::load);
         DESCR("- random initial load distribution", "%s",
               h.on_off(auto_depl::random_distribution));
         DESCR("- random seed", "%s",
@@ -457,7 +459,7 @@ void opt::usage()
     if (opt::help_requested > 1)
         so_list(opt::topologies);
     std::clog << o("-L value")
-              << "total load with auto deployment, 0 for number of hosts"
+              << "total load with auto deployment, average if negative"
               << " [" << opt::auto_depl::load << "]\n";
     std::clog << o("-N value")
               << "number of hosts to use with auto deployment, 0 for max."
-- 
2.39.5