Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
python: add exec-dvfs example
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 18 Mar 2019 00:38:41 +0000 (01:38 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 19 Mar 2019 08:37:02 +0000 (09:37 +0100)
Plus cosmetics on my way, including in the CPP example.

examples/python/CMakeLists.txt
examples/python/actor-join/actor-join.tesh
examples/python/exec-async/exec-async.py
examples/python/exec-dvfs/exec-dvfs.py [new file with mode: 0644]
examples/python/exec-dvfs/exec-dvfs.tesh [new file with mode: 0644]
examples/s4u/README.rst
examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp
examples/s4u/exec-dvfs/s4u-exec-dvfs.tesh
src/bindings/python/simgrid_python.cpp

index 7e4cdb1..3077640 100644 (file)
@@ -1,6 +1,6 @@
 foreach(example actor-create actor-daemon actor-join actor-kill actor-migrate actor-suspend actor-yield # actor-lifetime
                 async-wait async-waitall async-waitany
-                exec-basic exec-async exec-remote)
+                exec-async exec-basic exec-dvfs exec-remote)
   set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
   set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.py)
 
index 824ec05..a9f6a31 100644 (file)
@@ -1,4 +1,4 @@
-$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${bindir:=.}/actor-join.py ${platfdir}/small_platform.xml
+$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/actor-join.py ${platfdir}/small_platform.xml
 > [Tremblay:master:(1) 0.000000] [python/INFO] Start sleeper
 > [Tremblay:sleeper from master:(2) 0.000000] [python/INFO] Sleeper started
 > [Tremblay:master:(1) 0.000000] [python/INFO] Join the sleeper (timeout 2)
index 1f74851..42313ea 100644 (file)
@@ -54,6 +54,8 @@ class Canceller:
 
 if __name__ == '__main__':
     e = Engine(sys.argv)
+    if len(sys.argv) < 2:
+        raise AssertionError("Usage: exec-async.py platform_file [other parameters]")
 
     e.load_platform(sys.argv[1])
 
diff --git a/examples/python/exec-dvfs/exec-dvfs.py b/examples/python/exec-dvfs/exec-dvfs.py
new file mode 100644 (file)
index 0000000..f84b673
--- /dev/null
@@ -0,0 +1,56 @@
+# Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the license (GNU LGPL) which comes with this package. 
+
+import sys
+from simgrid import *
+
+
+class dvfs:
+    def __call__(self):
+        workload = 100E6
+        host = this_actor.get_host()
+
+        nb = host.get_pstate_count()
+        this_actor.info("Count of Processor states={:d}".format(nb))
+
+        this_actor.info("Current power peak={:f}".format(host.speed))
+
+        # Run a task
+        this_actor.execute(workload)
+
+        task_time = Engine.get_clock()
+        this_actor.info("Task1 duration: {:.2f}".format(task_time))
+
+        # Change power peak
+        new_pstate = 2
+
+        this_actor.info("Changing power peak value to {:f} (at index {:d})".format( host.get_pstate_speed(new_pstate), new_pstate))
+
+        host.pstate = new_pstate
+
+        this_actor.info("Current power peak={:f}".format(host.speed))
+
+        # Run a second task
+        this_actor.execute(workload)
+
+        task_time = Engine.get_clock() - task_time
+        this_actor.info("Task2 duration: {:.2f}".format(task_time))
+
+        # Verify that the default pstate is set to 0
+        host2 = Host.by_name("MyHost2")
+        this_actor.info("Count of Processor states={:d}".format(host2.get_pstate_count()))
+
+        this_actor.info("Current power peak={:f}".format(host2.speed))
+
+if __name__ == '__main__':
+    e = Engine(sys.argv)
+    if len(sys.argv) < 2:
+        raise AssertionError("Usage: exec-dvfs.py platform_file [other parameters] (got {:d} params)".format(len(sys.argv)))
+                
+    e.load_platform(sys.argv[1])
+    Actor.create("dvfs_test", Host.by_name("MyHost1"), dvfs())
+    Actor.create("dvfs_test", Host.by_name("MyHost2"), dvfs())
+
+    e.run()
diff --git a/examples/python/exec-dvfs/exec-dvfs.tesh b/examples/python/exec-dvfs/exec-dvfs.tesh
new file mode 100644 (file)
index 0000000..0e6b08b
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env tesh
+
+p Testing the DVFS-related functions
+
+$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/exec-dvfs.py ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:dvfs_test@MyHost1) Count of Processor states=3
+> [  0.000000] (1:dvfs_test@MyHost1) Current power peak=100000000.000000
+> [  0.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
+> [  0.000000] (2:dvfs_test@MyHost2) Current power peak=100000000.000000
+> [  1.000000] (1:dvfs_test@MyHost1) Task1 duration: 1.00
+> [  1.000000] (2:dvfs_test@MyHost2) Task1 duration: 1.00
+> [  1.000000] (1:dvfs_test@MyHost1) Changing power peak value to 20000000.000000 (at index 2)
+> [  1.000000] (2:dvfs_test@MyHost2) Changing power peak value to 20000000.000000 (at index 2)
+> [  1.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
+> [  1.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
+> [  6.000000] (1:dvfs_test@MyHost1) Task2 duration: 5.00
+> [  6.000000] (1:dvfs_test@MyHost1) Count of Processor states=3
+> [  6.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
+> [  6.000000] (2:dvfs_test@MyHost2) Task2 duration: 5.00
+> [  6.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
+> [  6.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
+
+$ ${pythoncmd:=python3} ${PYTHON_TOOL_OPTIONS:=} ${srcdir:=.}/exec-dvfs.py ${platfdir}/energy_cluster.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:dvfs_test@MyHost1) Count of Processor states=3
+> [  0.000000] (1:dvfs_test@MyHost1) Current power peak=100000000.000000
+> [  0.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
+> [  0.000000] (2:dvfs_test@MyHost2) Current power peak=100000000.000000
+> [  1.000000] (1:dvfs_test@MyHost1) Task1 duration: 1.00
+> [  1.000000] (2:dvfs_test@MyHost2) Task1 duration: 1.00
+> [  1.000000] (1:dvfs_test@MyHost1) Changing power peak value to 20000000.000000 (at index 2)
+> [  1.000000] (2:dvfs_test@MyHost2) Changing power peak value to 20000000.000000 (at index 2)
+> [  1.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
+> [  1.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
+> [  6.000000] (1:dvfs_test@MyHost1) Task2 duration: 5.00
+> [  6.000000] (1:dvfs_test@MyHost1) Count of Processor states=3
+> [  6.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
+> [  6.000000] (2:dvfs_test@MyHost2) Task2 duration: 5.00
+> [  6.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
+> [  6.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
index eb18e34..8fce725 100644 (file)
@@ -220,10 +220,14 @@ Executions on the CPU
     |br| `examples/s4u/exec-ptask/s4u-exec-ptask.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/exec-ptask/s4u-exec-ptask.cpp>`_
     
   - **Using Pstates on a host:**
-    Shows how define a set of pstatesfor a host in the XML, and how the current
-    pstate can be accessed/changed with :cpp:func:`simgrid::s4u::Host::get_pstate_speed` and :cpp:func:`simgrid::s4u::Host::set_pstate`.
-    |br| `examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp>`_
-    |br| `examples/platforms/energy_platform.xml <https://framagit.org/simgrid/simgrid/tree/master/examples/platforms/energy_platform.xml>`_
+    `examples/platforms/energy_platform.xml <https://framagit.org/simgrid/simgrid/tree/master/examples/platforms/energy_platform.xml>`_
+    shows how define a set of pstates in the XML. The current pstate
+    of an host can then be accessed and changed from the program.
+
+    - |cpp| `examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp>`_
+      :cpp:func:`simgrid::s4u::Host::get_pstate_speed` and :cpp:func:`simgrid::s4u::Host::set_pstate`.
+    - |py|  `examples/python/exec-dvfs/exec-dvfs.py <https://framagit.org/simgrid/simgrid/tree/master/examples/python/exec-dvfs/exec-dvfs.py>`_
+      :py:func:`Host.get_pstate_speed` and :py:func:`Host.set_pstate`.
 
 I/O on Disks and Files
 ----------------------
index 7b89ba8..5fde1fd 100644 (file)
@@ -21,7 +21,7 @@ static int dvfs()
   simgrid::s4u::this_actor::execute(workload);
 
   double task_time = simgrid::s4u::Engine::get_clock();
-  XBT_INFO("Task1 simulation time: %e", task_time);
+  XBT_INFO("Task1 duration: %.2f", task_time);
 
   // Change power peak
   int new_pstate = 2;
@@ -36,7 +36,7 @@ static int dvfs()
   simgrid::s4u::this_actor::execute(workload);
 
   task_time = simgrid::s4u::Engine::get_clock() - task_time;
-  XBT_INFO("Task2 simulation time: %e", task_time);
+  XBT_INFO("Task2 duration: %.2f", task_time);
 
   // Verify that the default pstate is set to 0
   host = simgrid::s4u::Host::by_name_or_null("MyHost2");
index 4ac2d9b..1b2aecd 100644 (file)
@@ -7,16 +7,16 @@ $ ${bindir:=.}/s4u-exec-dvfs$EXEEXT ${platfdir}/energy_platform.xml "--log=root.
 > [  0.000000] (1:dvfs_test@MyHost1) Current power peak=100000000.000000
 > [  0.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
 > [  0.000000] (2:dvfs_test@MyHost2) Current power peak=100000000.000000
-> [  1.000000] (1:dvfs_test@MyHost1) Task1 simulation time: 1.000000e+00
-> [  1.000000] (2:dvfs_test@MyHost2) Task1 simulation time: 1.000000e+00
+> [  1.000000] (1:dvfs_test@MyHost1) Task1 duration: 1.00
+> [  1.000000] (2:dvfs_test@MyHost2) Task1 duration: 1.00
 > [  1.000000] (1:dvfs_test@MyHost1) Changing power peak value to 20000000.000000 (at index 2)
 > [  1.000000] (2:dvfs_test@MyHost2) Changing power peak value to 20000000.000000 (at index 2)
 > [  1.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
 > [  1.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
-> [  6.000000] (1:dvfs_test@MyHost1) Task2 simulation time: 5.000000e+00
+> [  6.000000] (1:dvfs_test@MyHost1) Task2 duration: 5.00
 > [  6.000000] (1:dvfs_test@MyHost1) Count of Processor states=3
 > [  6.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
-> [  6.000000] (2:dvfs_test@MyHost2) Task2 simulation time: 5.000000e+00
+> [  6.000000] (2:dvfs_test@MyHost2) Task2 duration: 5.00
 > [  6.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
 > [  6.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
 > [  6.000000] (0:maestro@) Total simulation time: 6.000000e+00
@@ -26,16 +26,16 @@ $ ${bindir:=.}/s4u-exec-dvfs$EXEEXT ${platfdir}/energy_cluster.xml "--log=root.f
 > [  0.000000] (1:dvfs_test@MyHost1) Current power peak=100000000.000000
 > [  0.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
 > [  0.000000] (2:dvfs_test@MyHost2) Current power peak=100000000.000000
-> [  1.000000] (1:dvfs_test@MyHost1) Task1 simulation time: 1.000000e+00
-> [  1.000000] (2:dvfs_test@MyHost2) Task1 simulation time: 1.000000e+00
+> [  1.000000] (1:dvfs_test@MyHost1) Task1 duration: 1.00
+> [  1.000000] (2:dvfs_test@MyHost2) Task1 duration: 1.00
 > [  1.000000] (1:dvfs_test@MyHost1) Changing power peak value to 20000000.000000 (at index 2)
 > [  1.000000] (2:dvfs_test@MyHost2) Changing power peak value to 20000000.000000 (at index 2)
 > [  1.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
 > [  1.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
-> [  6.000000] (1:dvfs_test@MyHost1) Task2 simulation time: 5.000000e+00
+> [  6.000000] (1:dvfs_test@MyHost1) Task2 duration: 5.00
 > [  6.000000] (1:dvfs_test@MyHost1) Count of Processor states=3
 > [  6.000000] (1:dvfs_test@MyHost1) Current power peak=20000000.000000
-> [  6.000000] (2:dvfs_test@MyHost2) Task2 simulation time: 5.000000e+00
+> [  6.000000] (2:dvfs_test@MyHost2) Task2 duration: 5.00
 > [  6.000000] (2:dvfs_test@MyHost2) Count of Processor states=3
 > [  6.000000] (2:dvfs_test@MyHost2) Current power peak=20000000.000000
 > [  6.000000] (0:maestro@) Total simulation time: 6.000000e+00
index 0c42847..57fb111 100644 (file)
@@ -109,8 +109,8 @@ PYBIND11_MODULE(simgrid, m)
         // Currently this can be dangling, we should wrap this somehow.
         return new simgrid::s4u::Engine(&argc, argv.get());
       }))
+      .def_static("get_clock", &Engine::get_clock, "The simulation time, ie the amount of simulated seconds since the simulation start.")
       .def("get_all_hosts", &Engine::get_all_hosts, "Returns the list of all hosts found in the platform")
-      .def("get_clock", &Engine::get_clock, "Retrieve the simulation time (in seconds)")
       .def("load_platform", &Engine::load_platform,
            "Load a platform file describing the environment, see :cpp:func:`simgrid::s4u::Engine::load_platform()`")
       .def("load_deployment", &Engine::load_deployment,
@@ -149,14 +149,18 @@ PYBIND11_MODULE(simgrid, m)
   /* Class Host */
   py::class_<simgrid::s4u::Host, std::unique_ptr<Host, py::nodelete>>(m, "Host", "Simulation Engine, see :ref:`class s4u::Host <API_s4u_Host>`")
       .def("by_name", &Host::by_name, "Retrieves a host from its name, or die")
+      .def("get_pstate_count", &Host::get_pstate_count, "Retrieve the cound of defined pstate levels, see :cpp:func:`simgrid::s4u::Host::get_pstate_count`")
+      .def("get_pstate_speed", &Host::get_pstate_speed, "Retrieve the maximal speed at the given pstate, see :cpp:func:`simgrid::s4u::Host::get_pstate_speed`")
+      .def_property("pstate", &Host::get_pstate, &Host::set_pstate, "The current pstate")
+
       .def("current", &Host::current, "Retrieves the host on which the running actor is located, see :cpp:func:`simgrid::s4u::Host::current()`")
       .def_property_readonly("name", [](Host* self) -> const std::string {
           return std::string(self->get_name().c_str()); // Convert from xbt::string because of MC
         }, "The name of this host")
       .def_property_readonly("load", &Host::get_load,
-          "Returns the current computation load (in flops per second), see :cpp:func:`simgrid::s4u::Host::get_load()`")
+          "Returns the current computation load (in flops per second). This is the currently achieved speed. See :cpp:func:`simgrid::s4u::Host::get_load()`")
       .def_property_readonly("speed", &Host::get_speed,
-          "The peak computing speed in flops/s at the current pstate, taking the external load into account, see :cpp:func:`simgrid::s4u::Host::get_speed()`");
+          "The peak computing speed in flops/s at the current pstate, taking the external load into account. This is the max potential speed. See :cpp:func:`simgrid::s4u::Host::get_speed()`");
 
   /* Class Mailbox */
   py::class_<simgrid::s4u::Mailbox, std::unique_ptr<Mailbox, py::nodelete>>(m, "Mailbox", "Mailbox, see :ref:`class s4u::Mailbox <API_s4u_Mailbox>`")