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. */
8 #include "simgrid/msg.h"
9 #include "simgrid/plugins/energy.h"
11 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
13 static int dvfs(int argc, char *argv[])
15 msg_host_t host = MSG_host_by_name("MyHost1");
17 XBT_INFO("Energetic profile: %s",MSG_host_get_property_value(host,"watt_per_state"));
18 XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", MSG_host_get_current_power_peak(host),
19 sg_host_get_consumed_energy(host));
21 double start = MSG_get_clock();
22 XBT_INFO("Sleep for 10 seconds");
23 MSG_process_sleep(10);
24 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J", MSG_get_clock()-start,
25 MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
28 start = MSG_get_clock();
29 msg_task_t task1 = MSG_task_create ("t1", 100E6, 0, NULL);
30 XBT_INFO("Run a task of %.0E flops",MSG_task_get_flops_amount(task1));
31 MSG_task_execute (task1);
32 MSG_task_destroy(task1);
33 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW"
34 " depending on load; Energy dissipated=%.0f J", MSG_get_clock()-start,
35 MSG_host_get_current_power_peak(host), sg_host_get_wattmin_at(host,MSG_host_get_pstate(host)),
36 sg_host_get_wattmax_at(host,MSG_host_get_pstate(host)), sg_host_get_consumed_energy(host));
38 // ========= Change power peak =========
40 MSG_host_set_pstate(host, pstate);
41 XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)",
42 pstate, MSG_host_get_power_peak_at(host, pstate), MSG_host_get_current_power_peak(host));
45 start = MSG_get_clock();
46 task1 = MSG_task_create ("t2", 100E6, 0, NULL);
47 XBT_INFO("Run a task of %.0E flops",MSG_task_get_flops_amount(task1));
48 MSG_task_execute (task1);
49 MSG_task_destroy(task1);
50 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
51 MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
53 start = MSG_get_clock();
54 XBT_INFO("Sleep for 4 seconds");
56 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
57 MSG_get_clock()-start, MSG_host_get_current_power_peak(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(MSG_host_by_name("MyHost2")) );
62 MSG_host_off(MSG_host_by_name("MyHost2"));
63 start = MSG_get_clock();
64 MSG_process_sleep(10);
65 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
66 MSG_get_clock()-start, MSG_host_get_current_power_peak(host), sg_host_get_consumed_energy(host));
70 int main(int argc, char *argv[])
72 msg_error_t res = MSG_OK;
73 sg_energy_plugin_init();
74 MSG_init(&argc, argv);
76 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
77 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
79 MSG_create_environment(argv[1]);
80 MSG_function_register("dvfs_test", dvfs);
82 MSG_launch_application(argv[2]);
86 XBT_INFO("Total simulation time: %.2f", MSG_get_clock());