Logo AND Algorithmique Numérique Distribuée

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