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 static int dvfs(int argc, char *argv[]);
21 static int process_code(int argc, char *argv[]);
23 static int process_code(int argc, char *argv[])
25 msg_task_t task1 = NULL;
27 double task_time = MSG_get_clock();
31 /* Run a sleep task */
32 double sleep_task = atof(argv[1]);
34 MSG_process_sleep(sleep_task);
35 task_time = MSG_get_clock() - task_time;
36 XBT_INFO("Process %s executed task sleep cpu=%f, duration = %f",
37 MSG_process_get_name(MSG_process_self()), 0.0, task_time);
38 XBT_INFO("==================================================");
43 cpu_task = atof(argv[0]);
44 task1 = MSG_task_create ("task", cpu_task, 0, NULL);
45 MSG_task_execute (task1);
46 MSG_task_destroy(task1);
48 task_time = MSG_get_clock() - task_time;
49 XBT_INFO("Process %s executed task cpu=%f, duration = %f",
50 MSG_process_get_name(MSG_process_self()), cpu_task, task_time);
51 XBT_INFO("==================================================");
56 static int dvfs(int argc, char *argv[])
58 msg_host_t host = NULL;
60 host = MSG_host_self();
62 double current_peak = MSG_get_host_current_power_peak(host);
64 XBT_INFO("Current power peak=%f", current_peak);
65 double consumed_energy = MSG_get_host_consumed_energy(host);
66 XBT_INFO("Total energy (Joules): %f", consumed_energy);
68 // Process 1 - long CPU task
70 char** params1 = xbt_malloc0(sizeof(char *) * argc1);
71 params1[0] = xbt_strdup("400.0E6");
72 MSG_process_create_with_arguments("proc1", process_code, NULL, host, argc1, params1);
74 // Process 2 - sleep 2 sec + CPU task
76 char** params2 = xbt_malloc0(sizeof(char *) * argc2);
77 params2[0] = xbt_strdup("100.0E6");
78 params2[1] = xbt_strdup("2");
79 MSG_process_create_with_arguments("proc2", process_code, NULL, host, argc2, params2);
81 // Process 3 - sleep 2 sec + CPU task
83 char** params3 = xbt_malloc0(sizeof(char *) * argc3);
84 params3[0] = xbt_strdup("100.0E6");
85 params3[1] = xbt_strdup("2");
86 MSG_process_create_with_arguments("proc3", process_code, NULL, host, argc3, params3);
92 task_time = MSG_get_clock() - task_time;
93 XBT_INFO("Task simulation time: %e", task_time);
94 consumed_energy = MSG_get_host_consumed_energy(host);
95 XBT_INFO("Total energy (Joules): %f", consumed_energy);
100 int main(int argc, char *argv[])
102 msg_error_t res = MSG_OK;
103 sg_energy_plugin_init();
104 MSG_init(&argc, argv);
107 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
110 ("example: %s msg_platform.xml msg_deployment.xml\n",
115 MSG_create_environment(argv[1]);
117 /* Application deployment */
118 MSG_function_register("dvfs_test", dvfs);
120 MSG_launch_application(argv[2]);
124 XBT_INFO("Total simulation time: %e", MSG_get_clock());