Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fb5db642a29762afd54afbaefc0b750c35d46dcb
[simgrid.git] / examples / c / exec-dvfs / exec-dvfs.c
1 /* Copyright (c) 2007-2020. 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/actor.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/host.h"
10 #include "xbt/asserts.h"
11 #include "xbt/config.h"
12 #include "xbt/log.h"
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Pstate properties test");
15
16 static void dvfs(int argc, char* argv[])
17 {
18   sg_host_t host = sg_host_self();
19
20   int nb = sg_host_get_nb_pstates(host);
21   XBT_INFO("Count of Processor states=%d", nb);
22
23   double current_peak = sg_host_get_speed(host);
24   XBT_INFO("Current power peak=%f", current_peak);
25
26   sg_actor_execute(100E6);
27
28   double task_time = simgrid_get_clock();
29   XBT_INFO("Task1 simulation time: %e", task_time);
30
31   // Change power peak
32   int new_pstate = 2;
33   xbt_assert(new_pstate < nb, "Cannot set the host %s at pstate %d because it only provides %d pstates.",
34              sg_host_get_name(host), new_pstate, nb);
35
36   double peak_at = sg_host_get_pstate_speed(host, new_pstate);
37   XBT_INFO("Changing power peak value to %f (at index %d)", peak_at, new_pstate);
38
39   sg_host_set_pstate(host, new_pstate);
40
41   current_peak = sg_host_get_speed(host);
42   XBT_INFO("Current power peak=%f", current_peak);
43
44   sg_actor_execute(100E6);
45
46   task_time = simgrid_get_clock() - task_time;
47   XBT_INFO("Task2 simulation time: %e", task_time);
48
49   // Verify the default pstate is set to 0
50   host    = sg_host_by_name("MyHost2");
51   int nb2 = sg_host_get_nb_pstates(host);
52   XBT_INFO("Count of Processor states=%d", nb2);
53
54   double current_peak2 = sg_host_get_speed(host);
55   XBT_INFO("Current power peak=%f", current_peak2);
56 }
57
58 int main(int argc, char* argv[])
59 {
60   simgrid_init(&argc, argv);
61
62   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
63
64   simgrid_load_platform(argv[1]);
65
66   sg_actor_create("dvfs_test", sg_host_by_name("MyHost1"), dvfs, 0, NULL);
67   sg_actor_create("dvfs_test", sg_host_by_name("MyHost2"), dvfs, 0, NULL);
68
69   simgrid_run();
70
71   XBT_INFO("Total simulation time: %e", simgrid_get_clock());
72
73   return 0;
74 }