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. */
9 #include "simgrid/msg.h"
10 #include "xbt/sysdep.h" /* calloc */
11 #include "simgrid/plugins/energy.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 static void simulate_bootup(msg_host_t host) {
22 int previous_pstate = MSG_host_get_pstate(host);
24 XBT_INFO("Switch to virtual pstate 3, that encodes the shutting down state in the XML file of that example");
25 MSG_host_set_pstate(host,3);
27 msg_host_t host_list[1] = {host};
28 double flops_amount[1] = {1};
29 double bytes_amount[1] = {0};
31 XBT_INFO("Actually start the host");
34 XBT_INFO("Simulate the boot up by executing one flop on that host");
35 // We use a parallel task to run some task on a remote host.
36 msg_task_t bootup = MSG_parallel_task_create("boot up", 1, host_list, flops_amount, bytes_amount, NULL);
37 MSG_task_execute(bootup);
38 MSG_task_destroy(bootup);
40 XBT_INFO("Switch back to previously selected pstate %d", previous_pstate);
41 MSG_host_set_pstate(host, previous_pstate);
44 static void simulate_shutdown(msg_host_t host) {
46 int previous_pstate = MSG_host_get_pstate(host);
48 XBT_INFO("Switch to virtual pstate 4, that encodes the shutting down state in the XML file of that example");
49 MSG_host_set_pstate(host,4);
51 msg_host_t host_list[1] = {host};
52 double flops_amount[1] = {1};
53 double bytes_amount[1] = {0};
55 XBT_INFO("Simulate the shutdown by executing one flop on that remote host (using a parallel task)");
56 msg_task_t shutdown = MSG_parallel_task_create("shutdown", 1, host_list, flops_amount, bytes_amount, NULL);
57 MSG_task_execute(shutdown);
58 MSG_task_destroy(shutdown);
60 XBT_INFO("Switch back to previously selected pstate %d", previous_pstate);
61 MSG_host_set_pstate(host, previous_pstate);
63 XBT_INFO("Actually shutdown the host");
67 static int onoff(int argc, char *argv[]) {
68 msg_host_t host1 = MSG_host_by_name("MyHost1");
70 XBT_INFO("Energetic profile: %s",
71 MSG_host_get_property_value(host1,"watt_per_state"));
72 XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
73 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
75 XBT_INFO("Sleep for 10 seconds");
76 MSG_process_sleep(10);
77 XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
78 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
80 simulate_shutdown(host1);
81 XBT_INFO("Host1 is now OFF. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
82 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
84 XBT_INFO("Sleep for 10 seconds");
85 MSG_process_sleep(10);
86 XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
87 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
89 simulate_bootup(host1);
90 XBT_INFO("Host1 is now ON again. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
91 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
97 int main(int argc, char *argv[])
99 msg_error_t res = MSG_OK;
100 sg_energy_plugin_init();
101 MSG_init(&argc, argv);
104 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
107 ("example: %s msg_platform.xml msg_deployment.xml\n",
112 MSG_create_environment(argv[1]);
114 /* Application deployment */
115 MSG_function_register("onoff_test", onoff);
117 MSG_launch_application(argv[2]);
121 XBT_INFO("Total simulation time: %.2f", MSG_get_clock());