Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6f82f4ea2f5665f0ecd17b2eeaf5be4d18b55837
[simgrid.git] / examples / s4u / energy-pstate / s4u-energy-pstate.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
9 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Pstate properties test");
10
11 static int dvfs(std::vector<std::string> args)
12 {
13   double workload = 100E6;
14   sg_host_t host = simgrid::s4u::this_actor::getHost();
15
16   int nb = sg_host_get_nb_pstates(host);
17   XBT_INFO("Count of Processor states=%d", nb);
18
19   XBT_INFO("Current power peak=%f", host->getSpeed());
20
21   // Run a task
22   simgrid::s4u::this_actor::execute(workload);
23
24   double task_time = simgrid::s4u::Engine::getClock();
25   XBT_INFO("Task1 simulation time: %e", task_time);
26
27   // Change power peak
28   int new_pstate = 2;
29
30   XBT_INFO("Changing power peak value to %f (at index %d)", host->getPstateSpeed(new_pstate), new_pstate);
31
32   sg_host_set_pstate(host, new_pstate);
33
34   XBT_INFO("Current power peak=%f", host->getSpeed());
35
36   // Run a second task
37   simgrid::s4u::this_actor::execute(workload);
38
39   task_time = simgrid::s4u::Engine::getClock() - task_time;
40   XBT_INFO("Task2 simulation time: %e", task_time);
41
42   // Verify the default pstate is set to 0
43   host = simgrid::s4u::Host::by_name_or_null("MyHost2");
44   XBT_INFO("Count of Processor states=%d", sg_host_get_nb_pstates(host));
45
46   XBT_INFO("Current power peak=%f", host->getSpeed());
47   return 0;
48 }
49
50 int main(int argc, char *argv[])
51 {
52   simgrid::s4u::Engine e(&argc, argv);
53   std::vector<std::string> args;
54
55   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
56
57    e.loadPlatform(argv[1]); /* - Load the platform description */
58
59    simgrid::s4u::Actor::createActor("dvfs_test", simgrid::s4u::Host::by_name("MyHost1"), dvfs, args);
60    simgrid::s4u::Actor::createActor("dvfs_test", simgrid::s4u::Host::by_name("MyHost2"), dvfs, args);
61
62    e.run();
63
64   XBT_INFO("Total simulation time: %e", e.getClock());
65
66   return 0;
67 }