Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
added dvfs support
[simgrid.git] / examples / msg / energy / e1 / e1.c
1 /* Copyright (c) 2007, 2008, 2009, 2010. 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   XBT_INFO("dvfs start");
30
31   int nb = MSG_get_host_nb_pstates(host);
32   XBT_INFO("Number of Processor states=%d", nb);
33
34   double current_peak = MSG_get_host_current_power_peak(host);
35   XBT_INFO("Current power peak=%lf", current_peak);
36
37   // Run a task
38   task1 = MSG_task_create ("t1", 100E6, 0, NULL);
39   MSG_task_execute (task1);
40   MSG_task_destroy(task1);
41
42   task_time = MSG_get_clock();
43   XBT_INFO("Task1 simulation time: %le", task_time);
44
45   // ========= Change power peak =========
46   int peak_index=2;
47   double peak_at = MSG_get_host_power_peak_at(host, peak_index);
48   XBT_INFO("=========Changing power peak value to %lf (at index %d)", peak_at, peak_index);
49
50   MSG_set_host_power_peak_at(host, peak_index);
51
52   current_peak = MSG_get_host_current_power_peak(host);
53   XBT_INFO("Current power peak=%lf", current_peak);
54
55   // Run a second task
56   task1 = MSG_task_create ("t1", 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: %le", task_time);
62
63   return 0;
64 }
65
66 int main(int argc, char *argv[])
67 {
68   msg_error_t res = MSG_OK;
69
70   MSG_init(&argc, argv);
71
72   if (argc != 3) {
73     XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
74               argv[0]);
75     XBT_CRITICAL
76         ("example: %s msg_platform.xml msg_deployment.xml\n",
77          argv[0]);
78     exit(1);
79   }
80
81   MSG_create_environment(argv[1]);
82
83   /*   Application deployment */
84   MSG_function_register("dvfs_test", dvfs);
85
86   MSG_launch_application(argv[2]);
87
88   res = MSG_main();
89
90   XBT_INFO("Total simulation time: %le", MSG_get_clock());
91
92   if (res == MSG_OK)
93     return 0;
94   else
95     return 1;
96 }
97