Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[EXAMPLES] Make the HostLoad example more difficult
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Mon, 26 Feb 2018 15:54:44 +0000 (16:54 +0100)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 1 Mar 2018 12:42:50 +0000 (13:42 +0100)
This test now contains more intricate scenarios:
- Change the speed of a host while a computation is running
- Verify that the average load is correctly computed

examples/s4u/plugin-hostload/s4u-plugin-hostload.cpp
examples/s4u/plugin-hostload/s4u-plugin-hostload.tesh
src/surf/plugins/host_load.cpp

index 5ddec37..e043adf 100644 (file)
@@ -12,43 +12,46 @@ static void execute_load_test()
 {
   s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
 
 {
   s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
 
-  XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0)", host->getSpeed(),
-           sg_host_get_computed_flops(host));
+  XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0) and current average load: %.5f (should be 0)", host->getSpeed(),
+           sg_host_get_computed_flops(host), sg_host_get_avg_load(host));
 
   double start = simgrid::s4u::Engine::getClock();
   XBT_INFO("Sleep for 10 seconds");
   simgrid::s4u::this_actor::sleep_for(10);
 
 
   double start = simgrid::s4u::Engine::getClock();
   XBT_INFO("Sleep for 10 seconds");
   simgrid::s4u::this_actor::sleep_for(10);
 
+  double speed = host->getSpeed();
   XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
            "changed)",
            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
 
   // Run a task
   start = simgrid::s4u::Engine::getClock();
   XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
            "changed)",
            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
 
   // Run a task
   start = simgrid::s4u::Engine::getClock();
-  XBT_INFO("Run a task of %.0E flops", 100E6);
-  simgrid::s4u::this_actor::execute(100E6);
+  XBT_INFO("Run a task of %.0E flops at current speed of %.0E flop/s", 200E6, host->getSpeed());
+  simgrid::s4u::this_actor::execute(200E6);
 
 
-  XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
-           "far: %.0E",
-           simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
+  XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s (when I started the computation, the speed was set to %.0E flop/s); number of flops computed so "
+           "far: %.2E, average load as reported by the HostLoad plugin: %.5f (should be %.5f)",
+           simgrid::s4u::Engine::getClock() - start, host->getSpeed(), speed, sg_host_get_computed_flops(host), sg_host_get_avg_load(host),
+           static_cast<double>(200E6)/(10.5*speed*host->getCoreCount()+(simgrid::s4u::Engine::getClock()-start-0.5)*host->getSpeed()*host->getCoreCount()));
 
   // ========= Change power peak =========
 
   // ========= Change power peak =========
-  int pstate = 2;
+  int pstate = 1;
   host->setPstate(pstate);
   host->setPstate(pstate);
-  XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
-           host->getPstateSpeed(pstate), host->getSpeed());
+  XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s, average load is %.5f)", pstate,
+           host->getPstateSpeed(pstate), host->getSpeed(), sg_host_get_avg_load(host));
 
   // Run a second task
   start = simgrid::s4u::Engine::getClock();
   XBT_INFO("Run a task of %.0E flops", 100E6);
   simgrid::s4u::this_actor::execute(100E6);
   XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
 
   // Run a second task
   start = simgrid::s4u::Engine::getClock();
   XBT_INFO("Run a task of %.0E flops", 100E6);
   simgrid::s4u::this_actor::execute(100E6);
   XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
-           "far: %.0E",
+           "far: %.2E",
            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
 
   start = simgrid::s4u::Engine::getClock();
            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
 
   start = simgrid::s4u::Engine::getClock();
-  XBT_INFO("========= Requesting a reset of the computation counter");
+  XBT_INFO("========= Requesting a reset of the computation and load counters");
   sg_host_load_reset(host);
   sg_host_load_reset(host);
+  XBT_INFO("After reset: %.0E flops computed; load is %.5f", sg_host_get_computed_flops(host), sg_host_get_avg_load(host));
   XBT_INFO("Sleep for 4 seconds");
   simgrid::s4u::this_actor::sleep_for(4);
   XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
   XBT_INFO("Sleep for 4 seconds");
   simgrid::s4u::this_actor::sleep_for(4);
   XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
@@ -56,8 +59,8 @@ static void execute_load_test()
 
   // =========== Turn the other host off ==========
   s4u_Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
 
   // =========== Turn the other host off ==========
   s4u_Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
-  XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far.",
-           sg_host_get_computed_flops(host2));
+  XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far and has an average load of %.5f.",
+           sg_host_get_computed_flops(host2), sg_host_get_avg_load(host2));
   host2->turnOff();
   start = simgrid::s4u::Engine::getClock();
   simgrid::s4u::this_actor::sleep_for(10);
   host2->turnOff();
   start = simgrid::s4u::Engine::getClock();
   simgrid::s4u::this_actor::sleep_for(10);
@@ -65,6 +68,15 @@ static void execute_load_test()
            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
 }
 
            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
 }
 
+static void change_speed()
+{
+  s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
+  simgrid::s4u::this_actor::sleep_for(10.5);
+  XBT_INFO("I slept until now, but now I'll change the speed of this host "
+      "while the other process is still computing! This should slow the computation down.");
+  host->setPstate(2);
+}
+
 int main(int argc, char* argv[])
 {
   sg_host_load_plugin_init();
 int main(int argc, char* argv[])
 {
   sg_host_load_plugin_init();
@@ -74,6 +86,7 @@ int main(int argc, char* argv[])
   e.loadPlatform(argv[1]);
 
   simgrid::s4u::Actor::createActor("load_test", simgrid::s4u::Host::by_name("MyHost1"), execute_load_test);
   e.loadPlatform(argv[1]);
 
   simgrid::s4u::Actor::createActor("load_test", simgrid::s4u::Host::by_name("MyHost1"), execute_load_test);
+  simgrid::s4u::Actor::createActor("change_speed", simgrid::s4u::Host::by_name("MyHost1"), change_speed);
 
   e.run();
 
 
   e.run();
 
index 5eef89c..f10e2f0 100644 (file)
@@ -3,17 +3,19 @@
 p This tests the HostLoad plugin (this allows the user to get the current load of a host and the computed flops)
 
 $ ${bindir:=.}/s4u-plugin-hostload$EXEEXT ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
 p This tests the HostLoad plugin (this allows the user to get the current load of a host and the computed flops)
 
 $ ${bindir:=.}/s4u-plugin-hostload$EXEEXT ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (1:load_test@MyHost1) Initial peak speed: 1E+08 flop/s; number of flops computed so far: 0E+00 (should be 0)
+> [  0.000000] (1:load_test@MyHost1) Initial peak speed: 1E+08 flop/s; number of flops computed so far: 0E+00 (should be 0) and current average load: 0.00000 (should be 0)
 > [  0.000000] (1:load_test@MyHost1) Sleep for 10 seconds
 > [ 10.000000] (1:load_test@MyHost1) Done sleeping 10.00s; peak speed: 1E+08 flop/s; number of flops computed so far: 0E+00 (nothing should have changed)
 > [  0.000000] (1:load_test@MyHost1) Sleep for 10 seconds
 > [ 10.000000] (1:load_test@MyHost1) Done sleeping 10.00s; peak speed: 1E+08 flop/s; number of flops computed so far: 0E+00 (nothing should have changed)
-> [ 10.000000] (1:load_test@MyHost1) Run a task of 1E+08 flops
-> [ 11.000000] (1:load_test@MyHost1) Done working on my task; this took 1.00s; current peak speed: 1E+08 flop/s; number of flops computed so far: 1E+08
-> [ 11.000000] (1:load_test@MyHost1) ========= Requesting pstate 2 (speed should be of 2E+07 flop/s and is of 2E+07 flop/s)
-> [ 11.000000] (1:load_test@MyHost1) Run a task of 1E+08 flops
-> [ 16.000000] (1:load_test@MyHost1) Done working on my task; this took 5.00s; current peak speed: 2E+07 flop/s; number of flops computed so far: 2E+08
-> [ 16.000000] (1:load_test@MyHost1) ========= Requesting a reset of the computation counter
-> [ 16.000000] (1:load_test@MyHost1) Sleep for 4 seconds
-> [ 20.000000] (1:load_test@MyHost1) Done sleeping 4.00 s; peak speed: 2E+07 flop/s; number of flops computed so far: 0E+00
-> [ 20.000000] (1:load_test@MyHost1) Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed 0 flops so far.
-> [ 30.000000] (1:load_test@MyHost1) Done sleeping 10.00 s; peak speed: 2E+07 flop/s; number of flops computed so far: 0E+00
-> [ 30.000000] (0:maestro@) Total simulation time: 30.00
+> [ 10.000000] (1:load_test@MyHost1) Run a task of 2E+08 flops at current speed of 1E+08 flop/s
+> [ 10.500000] (2:change_speed@MyHost1) I slept until now, but now I'll change the speed of this host while the other process is still computing! This should slow the computation down.
+> [ 18.000000] (1:load_test@MyHost1) Done working on my task; this took 8.00s; current peak speed: 2E+07 flop/s (when I started the computation, the speed was set to 1E+08 flop/s); number of flops computed so far: 2.00E+08, average load as reported by the HostLoad plugin: 0.04167 (should be 0.04167)
+> [ 18.000000] (1:load_test@MyHost1) ========= Requesting pstate 1 (speed should be of 5E+07 flop/s and is of 5E+07 flop/s, average load is 0.04167)
+> [ 18.000000] (1:load_test@MyHost1) Run a task of 1E+08 flops
+> [ 20.000000] (1:load_test@MyHost1) Done working on my task; this took 2.00s; current peak speed: 5E+07 flop/s; number of flops computed so far: 3.00E+08
+> [ 20.000000] (1:load_test@MyHost1) ========= Requesting a reset of the computation and load counters
+> [ 20.000000] (1:load_test@MyHost1) After reset: 0E+00 flops computed; load is 0.00000
+> [ 20.000000] (1:load_test@MyHost1) Sleep for 4 seconds
+> [ 24.000000] (1:load_test@MyHost1) Done sleeping 4.00 s; peak speed: 5E+07 flop/s; number of flops computed so far: 0E+00
+> [ 24.000000] (1:load_test@MyHost1) Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed 0 flops so far and has an average load of 0.00000.
+> [ 34.000000] (1:load_test@MyHost1) Done sleeping 10.00 s; peak speed: 5E+07 flop/s; number of flops computed so far: 0E+00
+> [ 34.000000] (0:maestro@) Total simulation time: 34.00
index 011b1fd..b33570d 100644 (file)
@@ -49,7 +49,7 @@ private:
   double current_flops     = 0;
   double computed_flops    = 0;
   double idle_time         = 0;
   double current_flops     = 0;
   double computed_flops    = 0;
   double idle_time         = 0;
-  long   theor_max_flops   = 0;
+  double theor_max_flops   = 0;
   bool   was_prev_idle     = true; /* A host is idle at the beginning */
 };
 
   bool   was_prev_idle     = true; /* A host is idle at the beginning */
 };
 
@@ -71,23 +71,22 @@ HostLoad::~HostLoad() = default;
 void HostLoad::update()
 {
   double now = surf_get_clock();
 void HostLoad::update()
 {
   double now = surf_get_clock();
-  if (last_updated < now) {
-    /* flops == pstate_speed * cores_being_currently_used */
-    computed_flops += (now - last_updated) * current_flops;
 
 
-    /* Current flop per second computed by the cpu; current_flops = k * pstate_speed_in_flops, k \in {0, 1, ..., cores}
-     * number of active cores */
-    current_flops = host->pimpl_cpu->constraint()->get_usage();
+  /* Current flop per second computed by the cpu; current_flops = k * pstate_speed_in_flops, k \in {0, 1, ..., cores}
+   * number of active cores */
+  current_flops = host->pimpl_cpu->constraint()->get_usage();
 
 
-    if (was_prev_idle) {
-      idle_time += (now - last_updated);
-    }
+  /* flops == pstate_speed * cores_being_currently_used */
+  computed_flops += (now - last_updated) * current_flops;
 
 
-    theor_max_flops += current_speed * host->getCoreCount() * (now - last_updated);
-    current_speed    = host->getSpeed();
-    last_updated     = now;
-    was_prev_idle    = (current_flops == 0);
+  if (was_prev_idle) {
+    idle_time += (now - last_updated);
   }
   }
+
+  theor_max_flops += current_speed * host->getCoreCount() * (now - last_updated);
+  current_speed    = host->getSpeed();
+  last_updated     = now;
+  was_prev_idle    = (current_flops == 0);
 }
 
 /**
 }
 
 /**
@@ -116,13 +115,15 @@ double HostLoad::getIdleTime() {
 
 double HostLoad::getAverageLoad()
 {
 
 double HostLoad::getAverageLoad()
 {
-  return getComputedFlops() / theor_max_flops;
+  if (theor_max_flops == 0) { // Avoid division by 0
+    return 0;
+  }
+
+  return computed_flops / theor_max_flops;
 }
 
 double HostLoad::getComputedFlops()
 {
 }
 
 double HostLoad::getComputedFlops()
 {
-  update();
-
   return computed_flops;
 }
 
   return computed_flops;
 }
 
@@ -137,6 +138,7 @@ void HostLoad::reset()
   computed_flops  = 0;
   theor_max_flops = 0;
   current_flops   = host->pimpl_cpu->constraint()->get_usage();
   computed_flops  = 0;
   theor_max_flops = 0;
   current_flops   = host->pimpl_cpu->constraint()->get_usage();
+  current_speed   = host->getSpeed();
   was_prev_idle   = (current_flops == 0);
 }
 }
   was_prev_idle   = (current_flops == 0);
 }
 }