Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[DVFS] Update HostDvfs class documentation
[simgrid.git] / examples / s4u / plugin-hostload / s4u-plugin-hostload.cpp
1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u.hpp"
7 #include "simgrid/plugins/load.h"
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
10
11 static void execute_load_test()
12 {
13   s4u_Host* host = simgrid::s4u::Host::by_name("MyHost1");
14
15   XBT_INFO("Initial peak speed: %.0E flop/s; number of flops computed so far: %.0E (should be 0)", host->getSpeed(),
16            sg_host_get_computed_flops(host));
17
18   double start = simgrid::s4u::Engine::getClock();
19   XBT_INFO("Sleep for 10 seconds");
20   simgrid::s4u::this_actor::sleep_for(10);
21
22   XBT_INFO("Done sleeping %.2fs; peak speed: %.0E flop/s; number of flops computed so far: %.0E (nothing should have "
23            "changed)",
24            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
25
26   // Run a task
27   start = simgrid::s4u::Engine::getClock();
28   XBT_INFO("Run a task of %.0E flops", 100E6);
29   simgrid::s4u::this_actor::execute(100E6);
30
31   XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
32            "far: %.0E",
33            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
34
35   // ========= Change power peak =========
36   int pstate = 2;
37   host->setPstate(pstate);
38   XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
39            host->getPstateSpeed(pstate), host->getSpeed());
40
41   // Run a second task
42   start = simgrid::s4u::Engine::getClock();
43   XBT_INFO("Run a task of %.0E flops", 100E6);
44   simgrid::s4u::this_actor::execute(100E6);
45   XBT_INFO("Done working on my task; this took %.2fs; current peak speed: %.0E flop/s; number of flops computed so "
46            "far: %.0E",
47            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
48
49   start = simgrid::s4u::Engine::getClock();
50   XBT_INFO("========= Requesting a reset of the computation counter");
51   sg_host_load_reset(host);
52   XBT_INFO("Sleep for 4 seconds");
53   simgrid::s4u::this_actor::sleep_for(4);
54   XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
55            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
56
57   // =========== Turn the other host off ==========
58   s4u_Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
59   XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 computed %.0f flops so far.",
60            sg_host_get_computed_flops(host2));
61   host2->turnOff();
62   start = simgrid::s4u::Engine::getClock();
63   simgrid::s4u::this_actor::sleep_for(10);
64   XBT_INFO("Done sleeping %.2f s; peak speed: %.0E flop/s; number of flops computed so far: %.0E",
65            simgrid::s4u::Engine::getClock() - start, host->getSpeed(), sg_host_get_computed_flops(host));
66 }
67
68 int main(int argc, char* argv[])
69 {
70   sg_host_load_plugin_init();
71   simgrid::s4u::Engine e(&argc, argv);
72
73   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
74   e.loadPlatform(argv[1]);
75
76   simgrid::s4u::Actor::createActor("load_test", simgrid::s4u::Host::by_name("MyHost1"), execute_load_test);
77
78   e.run();
79
80   XBT_INFO("Total simulation time: %.2f", simgrid::s4u::Engine::getClock());
81
82   return 0;
83 }