Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Unused parameters argc/argv.
[simgrid.git] / teshsuite / msg / energy-consumption / energy-consumption.c
1 /* Copyright (c) 2007-2019. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "simgrid/plugins/energy.h"
8 #include "simgrid/msg.h"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11
12 static int dvfs(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
13 {
14   msg_host_t host = MSG_host_by_name("MyHost1");
15
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_speed(host),
18            sg_host_get_consumed_energy(host));
19
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",
24            MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_consumed_energy(host));
25
26   // Run a task
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",
34            MSG_get_clock() - start, MSG_host_get_speed(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));
36
37   // ========= Change power peak =========
38   int pstate = 2;
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)", pstate,
41            MSG_host_get_power_peak_at(host, pstate), MSG_host_get_speed(host));
42
43   // Run a second task
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_speed(host), sg_host_get_consumed_energy(host));
51
52   start = MSG_get_clock();
53   XBT_INFO("Sleep for 4 seconds");
54   MSG_process_sleep(4);
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_speed(host), sg_host_get_consumed_energy(host));
57
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_speed(host), sg_host_get_consumed_energy(host));
66   return 0;
67 }
68
69 int main(int argc, char* argv[])
70 {
71   MSG_init(&argc, argv);
72   MSG_config("plugin", "host_energy");
73
74   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
75
76   MSG_create_environment(argv[1]);
77   MSG_process_create("dvfs_test", dvfs, NULL, MSG_get_host_by_name("MyHost1"));
78
79   msg_error_t res = MSG_main();
80
81   XBT_INFO("Total simulation time: %.2f", MSG_get_clock());
82
83   return res != MSG_OK;
84 }