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 void simulate_bootup(msg_host_t host) {
13 int previous_pstate = MSG_host_get_pstate(host);
15 XBT_INFO("Switch to virtual pstate 3, that encodes the shutting down state in the XML file of that example");
16 MSG_host_set_pstate(host,3);
18 msg_host_t host_list[1] = {host};
19 double flops_amount[1] = {1};
20 double bytes_amount[1] = {0};
22 XBT_INFO("Actually start the host");
25 XBT_INFO("Simulate the boot up by executing one flop on that host");
26 // We use a parallel task to run some task on a remote host.
27 msg_task_t bootup = MSG_parallel_task_create("boot up", 1, host_list, flops_amount, bytes_amount, NULL);
28 MSG_task_execute(bootup);
29 MSG_task_destroy(bootup);
31 XBT_INFO("Switch back to previously selected pstate %d", previous_pstate);
32 MSG_host_set_pstate(host, previous_pstate);
35 static void simulate_shutdown(msg_host_t host) {
36 int previous_pstate = MSG_host_get_pstate(host);
38 XBT_INFO("Switch to virtual pstate 4, that encodes the shutting down state in the XML file of that example");
39 MSG_host_set_pstate(host,4);
41 msg_host_t host_list[1] = {host};
42 double flops_amount[1] = {1};
43 double bytes_amount[1] = {0};
45 XBT_INFO("Simulate the shutdown by executing one flop on that remote host (using a parallel task)");
46 msg_task_t shutdown = MSG_parallel_task_create("shutdown", 1, host_list, flops_amount, bytes_amount, NULL);
47 MSG_task_execute(shutdown);
48 MSG_task_destroy(shutdown);
50 XBT_INFO("Switch back to previously selected pstate %d", previous_pstate);
51 MSG_host_set_pstate(host, previous_pstate);
53 XBT_INFO("Actually shutdown the host");
57 static int onoff(int argc, char *argv[]) {
58 msg_host_t host1 = MSG_host_by_name("MyHost1");
60 XBT_INFO("Energetic profile: %s", MSG_host_get_property_value(host1,"watt_per_state"));
61 XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J",
62 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
64 XBT_INFO("Sleep for 10 seconds");
65 MSG_process_sleep(10);
66 XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
67 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
69 simulate_shutdown(host1);
70 XBT_INFO("Host1 is now OFF. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
71 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
73 XBT_INFO("Sleep for 10 seconds");
74 MSG_process_sleep(10);
75 XBT_INFO("Done sleeping. Current peak speed=%.0E; Energy dissipated=%.2f J",
76 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
78 simulate_bootup(host1);
79 XBT_INFO("Host1 is now ON again. Current peak speed=%.0E flop/s; Energy dissipated=%.0f J",
80 MSG_host_get_current_power_peak(host1), sg_host_get_consumed_energy(host1));
85 int main(int argc, char *argv[])
87 msg_error_t res = MSG_OK;
88 sg_energy_plugin_init();
89 MSG_init(&argc, argv);
91 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
93 MSG_create_environment(argv[1]);
95 MSG_process_create("onoff_test", onoff, NULL, MSG_get_host_by_name("MyHost2"));
99 XBT_INFO("Total simulation time: %.2f", MSG_get_clock());
101 return res != MSG_OK;