1 /* Copyright (c) 2007-2010, 2013-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
10 #include "xbt/sysdep.h" /* calloc */
11 #include "simgrid/plugins.h"
13 /* Create a log channel to have nice outputs. */
15 #include "xbt/asserts.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
18 "Messages specific for this msg example");
20 int dvfs(int argc, char *argv[]);
23 int dvfs(int argc, char *argv[])
25 msg_host_t host = NULL;
26 msg_task_t task1 = NULL;
28 host = MSG_get_host_by_name("MyHost1");
31 double current_peak = MSG_get_host_current_power_peak(host);
32 XBT_INFO("Current power peak=%f", current_peak);
34 double consumed_energy = MSG_get_host_consumed_energy(host);
35 XBT_INFO("Total energy (Joules): %f", consumed_energy);
38 task1 = MSG_task_create ("t1", 100E6, 0, NULL);
39 MSG_task_execute (task1);
40 MSG_task_destroy(task1);
42 task_time = MSG_get_clock();
43 XBT_INFO("Task1 simulation time: %e", task_time);
44 consumed_energy = MSG_get_host_consumed_energy(host);
45 XBT_INFO("Total energy (Joules): %f", consumed_energy);
47 // ========= Change power peak =========
49 double peak_at = MSG_get_host_power_peak_at(host, peak_index);
50 XBT_INFO("=========Changing power peak value to %f (at index %d)", peak_at, peak_index);
52 MSG_set_host_power_peak_at(host, peak_index);
55 task1 = MSG_task_create ("t2", 100E6, 0, NULL);
56 MSG_task_execute (task1);
57 MSG_task_destroy(task1);
59 task_time = MSG_get_clock() - task_time;
60 XBT_INFO("Task2 simulation time: %e", task_time);
62 consumed_energy = MSG_get_host_consumed_energy(host);
63 XBT_INFO("Total energy (Joules): %f", consumed_energy);
68 task_time = MSG_get_clock() - task_time;
69 XBT_INFO("Task3 (sleep) simulation time: %e", task_time);
70 consumed_energy = MSG_get_host_consumed_energy(host);
71 XBT_INFO("Total energy (Joules): %f", consumed_energy);
76 int main(int argc, char *argv[])
78 msg_error_t res = MSG_OK;
79 sg_energy_plugin_init();
80 MSG_init(&argc, argv);
83 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
86 ("example: %s msg_platform.xml msg_deployment.xml\n",
91 MSG_create_environment(argv[1]);
93 /* Application deployment */
94 MSG_function_register("dvfs_test", dvfs);
96 MSG_launch_application(argv[2]);
100 XBT_INFO("Total simulation time: %e", MSG_get_clock());