Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5e1bd00f349fea5721fd471b377f7940036452a7
[simgrid.git] / examples / msg / energy / consumption / consumption.c
1 /* Copyright (c) 2007-2010, 2013-2015. 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
8 #include "simgrid/msg.h"
9 #include "simgrid/plugins/energy.h"
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
12
13 static int dvfs(int argc, char *argv[])
14 {
15   msg_host_t host = MSG_host_by_name("MyHost1");
16
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));
20
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));
26
27   // Run a task
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));
37
38   // ========= Change power peak =========
39   int pstate=2;
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));
43
44   // Run a second task
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));
52
53   start = MSG_get_clock();
54   XBT_INFO("Sleep for 4 seconds");
55   MSG_process_sleep(4);
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));
58
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));
67   return 0;
68 }
69
70 int main(int argc, char *argv[])
71 {
72   msg_error_t res = MSG_OK;
73   sg_energy_plugin_init();
74   MSG_init(&argc, argv);
75
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]);
78
79   MSG_create_environment(argv[1]);
80   MSG_function_register("dvfs_test", dvfs);
81
82   MSG_launch_application(argv[2]);
83
84   res = MSG_main();
85
86   XBT_INFO("Total simulation time: %.2f", MSG_get_clock());
87
88   return res != MSG_OK;
89 }