Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add missing includes
[simgrid.git] / examples / msg / energy / e2 / e2.c
1
2 /* Copyright (c) 2007-2010, 2013. The SimGrid Team.
3  * All rights reserved.                                                     */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include<stdio.h>
9
10 #include "msg/msg.h"
11 #include "xbt/sysdep.h"         /* calloc */
12 #include "simgrid/plugins.h"
13
14 /* Create a log channel to have nice outputs. */
15 #include "xbt/log.h"
16 #include "xbt/asserts.h"
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
19                              "Messages specific for this msg example");
20
21 int dvfs(int argc, char *argv[]);
22
23
24 int dvfs(int argc, char *argv[])
25 {
26   msg_host_t host = NULL;
27   msg_task_t task1 = NULL;
28   double task_time = 0;
29   host = MSG_get_host_by_name("MyHost1");
30
31
32   double current_peak = MSG_get_host_current_power_peak(host);
33   XBT_INFO("Current power peak=%f", current_peak);
34
35   double consumed_energy = MSG_get_host_consumed_energy(host);
36   XBT_INFO("Total energy (Joules): %f", consumed_energy);
37
38   // Run a task
39   task1 = MSG_task_create ("t1", 100E6, 0, NULL);
40   MSG_task_execute (task1);
41   MSG_task_destroy(task1);
42
43   task_time = MSG_get_clock();
44   XBT_INFO("Task1 simulation time: %e", task_time);
45   consumed_energy = MSG_get_host_consumed_energy(host);
46   XBT_INFO("Total energy (Joules): %f", consumed_energy);
47
48   // ========= Change power peak =========
49   int peak_index=2;
50   double peak_at = MSG_get_host_power_peak_at(host, peak_index);
51   XBT_INFO("=========Changing power peak value to %f (at index %d)", peak_at, peak_index);
52
53   MSG_set_host_power_peak_at(host, peak_index);
54
55   // Run a second task
56   task1 = MSG_task_create ("t2", 100E6, 0, NULL);
57   MSG_task_execute (task1);
58   MSG_task_destroy(task1);
59
60   task_time = MSG_get_clock() - task_time;
61   XBT_INFO("Task2 simulation time: %e", task_time);
62
63   consumed_energy = MSG_get_host_consumed_energy(host);
64   XBT_INFO("Total energy (Joules): %f", consumed_energy);
65
66
67   MSG_process_sleep(3);
68
69   task_time = MSG_get_clock() - task_time;
70   XBT_INFO("Task3 (sleep) simulation time: %e", task_time);
71   consumed_energy = MSG_get_host_consumed_energy(host);
72   XBT_INFO("Total energy (Joules): %f", consumed_energy);
73
74   return 0;
75 }
76
77 int main(int argc, char *argv[])
78 {
79   msg_error_t res = MSG_OK;
80   sg_energy_plugin_init();
81   MSG_init(&argc, argv);
82
83   if (argc != 3) {
84     XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
85               argv[0]);
86     XBT_CRITICAL
87         ("example: %s msg_platform.xml msg_deployment.xml\n",
88          argv[0]);
89     exit(1);
90   }
91
92   MSG_create_environment(argv[1]);
93
94   /*   Application deployment */
95   MSG_function_register("dvfs_test", dvfs);
96
97   MSG_launch_application(argv[2]);
98
99   res = MSG_main();
100
101   XBT_INFO("Total simulation time: %e", MSG_get_clock());
102
103   if (res == MSG_OK)
104     return 0;
105   else
106     return 1;
107 }
108