Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove superfluous simcall.
[simgrid.git] / examples / s4u / exec-dvfs / s4u-exec-dvfs.cpp
1 /* Copyright (c) 2007-2019. 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()
11 {
12   double workload = 100E6;
13   simgrid::s4u::Host* host = simgrid::s4u::this_actor::get_host();
14
15   int nb = host->get_pstate_count();
16   XBT_INFO("Count of Processor states=%d", nb);
17
18   XBT_INFO("Current power peak=%f", host->get_speed());
19
20   // Run a task
21   simgrid::s4u::this_actor::execute(workload);
22
23   double task_time = simgrid::s4u::Engine::get_clock();
24   XBT_INFO("Task1 duration: %.2f", 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->get_pstate_speed(new_pstate), new_pstate);
30
31   host->set_pstate(new_pstate);
32
33   XBT_INFO("Current power peak=%f", host->get_speed());
34
35   // Run a second task
36   simgrid::s4u::this_actor::execute(workload);
37
38   task_time = simgrid::s4u::Engine::get_clock() - task_time;
39   XBT_INFO("Task2 duration: %.2f", task_time);
40
41   // Verify that 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", host->get_pstate_count());
44
45   XBT_INFO("Current power peak=%f", host->get_speed());
46   return 0;
47 }
48
49 int main(int argc, char* argv[])
50 {
51   simgrid::s4u::Engine e(&argc, argv);
52
53   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
54
55   e.load_platform(argv[1]);
56
57   simgrid::s4u::Actor::create("dvfs_test", simgrid::s4u::Host::by_name("MyHost1"), dvfs);
58   simgrid::s4u::Actor::create("dvfs_test", simgrid::s4u::Host::by_name("MyHost2"), dvfs);
59
60   e.run();
61
62   XBT_INFO("Total simulation time: %e", e.get_clock());
63
64   return 0;
65 }