1 /* Copyright (c) 2007-2010, 2013-2014. 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. */
10 #include "xbt/sysdep.h" /* calloc */
11 #include "simgrid/plugins.h"
13 /* Create a log channel to have nice outputs. */
15 #include "xbt/asserts.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
18 "Messages specific for this msg example");
20 int dvfs(int argc, char *argv[]);
23 int dvfs(int argc, char *argv[])
25 msg_host_t host = NULL;
26 msg_task_t task1 = NULL;
27 host = MSG_get_host_by_name("MyHost1");
30 XBT_INFO("Energetic profile: %s",
31 MSG_host_get_property_value(host,"watt_per_state"));
32 XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
33 MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
35 double start = MSG_get_clock();
36 XBT_INFO("Sleep for 10 seconds");
37 MSG_process_sleep(10);
38 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J",
39 MSG_get_clock()-start,
40 MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
43 start = MSG_get_clock();
44 XBT_INFO("Run a task for 100E6 flops");
45 task1 = MSG_task_create ("t1", 100E6, 0, NULL);
46 MSG_task_execute (task1);
47 MSG_task_destroy(task1);
48 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
49 MSG_get_clock()-start,
50 MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
52 // ========= Change power peak =========
54 MSG_host_set_pstate(host, pstate);
55 XBT_INFO("========= Requesting pstate %d (speed should be of %.2f flop/s and is of %.2f flop/s)",
57 MSG_host_get_power_peak_at(host, pstate),
58 MSG_host_get_current_power_peak(host));
61 start = MSG_get_clock();
62 XBT_INFO("Run a task for 100E6 flops");
63 task1 = MSG_task_create ("t2", 100E6, 0, NULL);
64 MSG_task_execute (task1);
65 MSG_task_destroy(task1);
66 XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
67 MSG_get_clock()-start,
68 MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
70 start = MSG_get_clock();
71 XBT_INFO("Sleep for 4 seconds");
73 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
74 MSG_get_clock()-start,
75 MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
77 // =========== Turn the other host off ==========
78 XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 disipated %.0f J so far.",
79 MSG_host_get_consumed_energy(MSG_get_host_by_name("MyHost2")) );
80 MSG_host_off(MSG_get_host_by_name("MyHost2"));
81 start = MSG_get_clock();
82 MSG_process_sleep(10);
83 XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
84 MSG_get_clock()-start,
85 MSG_host_get_current_power_peak(host), MSG_host_get_consumed_energy(host));
89 int main(int argc, char *argv[])
91 msg_error_t res = MSG_OK;
92 sg_energy_plugin_init();
93 MSG_init(&argc, argv);
96 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
99 ("example: %s msg_platform.xml msg_deployment.xml\n",
104 MSG_create_environment(argv[1]);
106 /* Application deployment */
107 MSG_function_register("dvfs_test", dvfs);
109 MSG_launch_application(argv[2]);
113 XBT_INFO("Total simulation time: %.2f", MSG_get_clock());