1 /* Copyright (c) 2007-2010, 2013-2015. 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/msg.h"
8 #include "simgrid/plugins/energy.h"
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
12 static int dvfs(int argc, char *argv[])
14 msg_host_t host = MSG_host_by_name("MyHost1");
16 XBT_INFO("Energetic profile: %s",MSG_host_get_property_value(host,"watt_per_state"));
17 XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", MSG_host_get_current_power_peak(host),
18 sg_host_get_consumed_energy(host));
20 double start = MSG_get_clock();
21 XBT_INFO("Sleep for 10 seconds");
22 MSG_process_sleep(10);
23 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J", MSG_get_clock()-start,
24 MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
27 start = MSG_get_clock();
28 msg_task_t task1 = MSG_task_create ("t1", 100E6, 0, NULL);
29 XBT_INFO("Run a task of %.0E flops",MSG_task_get_flops_amount(task1));
30 MSG_task_execute (task1);
31 MSG_task_destroy(task1);
32 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW"
33 " depending on load; Energy dissipated=%.0f J", MSG_get_clock()-start,
34 MSG_host_get_current_power_peak(host), sg_host_get_wattmin_at(host,MSG_host_get_pstate(host)),
35 sg_host_get_wattmax_at(host,MSG_host_get_pstate(host)), sg_host_get_consumed_energy(host));
37 // ========= Change power peak =========
39 MSG_host_set_pstate(host, pstate);
40 XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)",
41 pstate, MSG_host_get_power_peak_at(host, pstate), MSG_host_get_current_power_peak(host));
44 start = MSG_get_clock();
45 task1 = MSG_task_create ("t2", 100E6, 0, NULL);
46 XBT_INFO("Run a task of %.0E flops",MSG_task_get_flops_amount(task1));
47 MSG_task_execute (task1);
48 MSG_task_destroy(task1);
49 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
50 MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
52 start = MSG_get_clock();
53 XBT_INFO("Sleep for 4 seconds");
55 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
56 MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
58 // =========== Turn the other host off ==========
59 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.",
60 sg_host_get_consumed_energy(MSG_host_by_name("MyHost2")) );
61 MSG_host_off(MSG_host_by_name("MyHost2"));
62 start = MSG_get_clock();
63 MSG_process_sleep(10);
64 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
65 MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
69 int main(int argc, char *argv[])
71 msg_error_t res = MSG_OK;
72 sg_energy_plugin_init();
73 MSG_init(&argc, argv);
75 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
77 MSG_create_environment(argv[1]);
78 MSG_process_create("dvfs_test", dvfs, NULL, MSG_get_host_by_name("MyHost1"));
82 XBT_INFO("Total simulation time: %.2f", MSG_get_clock());