1 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/s4u.hpp"
7 #include "simgrid/plugins/energy.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
13 simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1");
14 simgrid::s4u::Host* host2 = simgrid::s4u::Host::by_name("MyHost2");
16 XBT_INFO("Energetic profile: %s", host1->get_property("wattage_per_state"));
17 XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", host1->get_speed(),
18 sg_host_get_consumed_energy(host1));
20 double start = simgrid::s4u::Engine::get_clock();
21 XBT_INFO("Sleep for 10 seconds");
22 simgrid::s4u::this_actor::sleep_for(10);
23 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J",
24 simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
27 start = simgrid::s4u::Engine::get_clock();
28 double flopAmount = 100E6;
29 XBT_INFO("Run a task of %.0E flops", flopAmount);
30 simgrid::s4u::this_actor::execute(flopAmount);
31 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW"
32 " depending on load; Energy dissipated=%.0f J",
33 simgrid::s4u::Engine::get_clock() - start, host1->get_speed(),
34 sg_host_get_wattmin_at(host1, host1->get_pstate()), sg_host_get_wattmax_at(host1, host1->get_pstate()),
35 sg_host_get_consumed_energy(host1));
37 // ========= Change power peak =========
39 host1->set_pstate(pstate);
40 XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate,
41 host1->get_pstate_speed(pstate), host1->get_speed());
44 start = simgrid::s4u::Engine::get_clock();
45 XBT_INFO("Run a task of %.0E flops", flopAmount);
46 simgrid::s4u::this_actor::execute(flopAmount);
47 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
48 simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
50 start = simgrid::s4u::Engine::get_clock();
51 XBT_INFO("Sleep for 4 seconds");
52 simgrid::s4u::this_actor::sleep_for(4);
53 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
54 simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
56 // =========== Turn the other host off ==========
57 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.",
58 sg_host_get_consumed_energy(host2));
60 start = simgrid::s4u::Engine::get_clock();
61 simgrid::s4u::this_actor::sleep_for(10);
62 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
63 simgrid::s4u::Engine::get_clock() - start, host1->get_speed(), sg_host_get_consumed_energy(host1));
66 int main(int argc, char* argv[])
68 sg_host_energy_plugin_init();
69 simgrid::s4u::Engine e(&argc, argv);
71 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/energy_platform.xml\n", argv[0], argv[0]);
73 e.load_platform(argv[1]);
74 simgrid::s4u::Actor::create("dvfs_test", simgrid::s4u::Host::by_name("MyHost1"), dvfs);
78 XBT_INFO("End of simulation.");