Logo AND Algorithmique Numérique Distribuée

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