Logo AND Algorithmique Numérique Distribuée

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