1 /* Copyright (c) 2007-2023. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/actor.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/host.h"
10 #include "simgrid/plugins/energy.h"
11 #include "xbt/asserts.h"
12 #include "xbt/config.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(energy_exec, "Messages specific for this example");
17 static void dvfs(int argc, char* argv[])
19 sg_host_t host = sg_host_by_name("MyHost1");
21 XBT_INFO("Energetic profile: %s", sg_host_get_property_value(host, "wattage_per_state"));
22 XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", sg_host_get_speed(host),
23 sg_host_get_consumed_energy(host));
25 double start = simgrid_get_clock();
26 XBT_INFO("Sleep for 10 seconds");
27 sg_actor_sleep_for(10);
28 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J",
29 simgrid_get_clock() - start, sg_host_get_speed(host), sg_host_get_consumed_energy(host));
32 start = simgrid_get_clock();
33 XBT_INFO("Run a task of %.0E flops", 100E6);
34 sg_actor_execute(100E6);
35 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW"
36 " depending on load; Energy dissipated=%.0f J",
37 simgrid_get_clock() - start, sg_host_get_speed(host), sg_host_get_wattmin_at(host, sg_host_get_pstate(host)),
38 sg_host_get_wattmax_at(host, sg_host_get_pstate(host)), sg_host_get_consumed_energy(host));
40 // ========= Change power peak =========
42 sg_host_set_pstate(host, pstate);
43 XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
44 sg_host_get_pstate_speed(host, pstate), sg_host_get_speed(host));
47 start = simgrid_get_clock();
48 XBT_INFO("Run a task of %.0E flops", 100E6);
49 sg_actor_execute(100E6);
50 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
51 simgrid_get_clock() - start, sg_host_get_speed(host), sg_host_get_consumed_energy(host));
53 start = simgrid_get_clock();
54 XBT_INFO("Sleep for 4 seconds");
55 sg_actor_sleep_for(4);
56 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
57 simgrid_get_clock() - start, sg_host_get_speed(host), sg_host_get_consumed_energy(host));
59 // =========== Turn the other host off ==========
60 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.",
61 sg_host_get_consumed_energy(sg_host_by_name("MyHost2")));
62 sg_host_turn_off(sg_host_by_name("MyHost2"));
63 start = simgrid_get_clock();
64 sg_actor_sleep_for(10);
65 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
66 simgrid_get_clock() - start, sg_host_get_speed(host), sg_host_get_consumed_energy(host));
69 int main(int argc, char* argv[])
71 simgrid_init(&argc, argv);
72 sg_cfg_set_string("plugin", "host_energy");
74 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
76 simgrid_load_platform(argv[1]);
77 sg_actor_create("dvfs_test", sg_host_by_name("MyHost1"), dvfs, 0, NULL);
81 XBT_INFO("End of simulation");