From: Martin Quinson Date: Mon, 18 Mar 2019 00:38:41 +0000 (+0100) Subject: python: add exec-dvfs example X-Git-Tag: v3_22~62 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/bc3a566b71f9e9acf92551b1799abf0a9b891aca python: add exec-dvfs example Plus cosmetics on my way, including in the CPP example. --- diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt index 7e4cdb1d80..3077640264 100644 --- a/examples/python/CMakeLists.txt +++ b/examples/python/CMakeLists.txt @@ -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) diff --git a/examples/python/actor-join/actor-join.tesh b/examples/python/actor-join/actor-join.tesh index 824ec0590f..a9f6a31118 100644 --- a/examples/python/actor-join/actor-join.tesh +++ b/examples/python/actor-join/actor-join.tesh @@ -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) diff --git a/examples/python/exec-async/exec-async.py b/examples/python/exec-async/exec-async.py index 1f74851dd5..42313ea363 100644 --- a/examples/python/exec-async/exec-async.py +++ b/examples/python/exec-async/exec-async.py @@ -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 index 0000000000..f84b67348a --- /dev/null +++ b/examples/python/exec-dvfs/exec-dvfs.py @@ -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 index 0000000000..0e6b08b25e --- /dev/null +++ b/examples/python/exec-dvfs/exec-dvfs.tesh @@ -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 diff --git a/examples/s4u/README.rst b/examples/s4u/README.rst index eb18e34460..8fce725878 100644 --- a/examples/s4u/README.rst +++ b/examples/s4u/README.rst @@ -220,10 +220,14 @@ Executions on the CPU |br| `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 `_ - |br| `examples/platforms/energy_platform.xml `_ + `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 `_ + :cpp:func:`simgrid::s4u::Host::get_pstate_speed` and :cpp:func:`simgrid::s4u::Host::set_pstate`. + - |py| `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 ---------------------- diff --git a/examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp b/examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp index 7b89ba8b75..5fde1fd8cc 100644 --- a/examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp +++ b/examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp @@ -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"); diff --git a/examples/s4u/exec-dvfs/s4u-exec-dvfs.tesh b/examples/s4u/exec-dvfs/s4u-exec-dvfs.tesh index 4ac2d9bef6..1b2aecd073 100644 --- a/examples/s4u/exec-dvfs/s4u-exec-dvfs.tesh +++ b/examples/s4u/exec-dvfs/s4u-exec-dvfs.tesh @@ -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 diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 0c42847448..57fb111115 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -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_>(m, "Host", "Simulation Engine, see :ref:`class 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_>(m, "Mailbox", "Mailbox, see :ref:`class s4u::Mailbox `")