1 /* Copyright (c) 2007-2010, 2013. 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 */
12 /* Create a log channel to have nice outputs. */
14 #include "xbt/asserts.h"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
17 "Messages specific for this msg example");
19 static int dvfs(int argc, char *argv[]);
20 static int process_code(int argc, char *argv[]);
22 static int process_code(int argc, char *argv[])
24 msg_task_t task1 = NULL;
26 double task_time = MSG_get_clock();
30 /* Run a sleep task */
31 double sleep_task = atof(argv[1]);
33 MSG_process_sleep(sleep_task);
34 task_time = MSG_get_clock() - task_time;
35 XBT_INFO("Process %s executed task sleep cpu=%f, duration = %f",
36 MSG_process_get_name(MSG_process_self()), 0.0, task_time);
37 XBT_INFO("==================================================");
42 cpu_task = atof(argv[0]);
43 task1 = MSG_task_create ("task", cpu_task, 0, NULL);
44 MSG_task_execute (task1);
45 MSG_task_destroy(task1);
47 task_time = MSG_get_clock() - task_time;
48 XBT_INFO("Process %s executed task cpu=%f, duration = %f",
49 MSG_process_get_name(MSG_process_self()), cpu_task, task_time);
50 XBT_INFO("==================================================");
55 static int dvfs(int argc, char *argv[])
57 msg_host_t host = NULL;
59 host = MSG_host_self();
61 double current_peak = MSG_get_host_current_power_peak(host);
63 XBT_INFO("Current power peak=%f", current_peak);
64 double consumed_energy = MSG_get_host_consumed_energy(host);
65 XBT_INFO("Total energy (Joules): %f", consumed_energy);
67 // Process 1 - long CPU task
69 char** params1 = xbt_malloc0(sizeof(char *) * argc1);
70 params1[0] = xbt_strdup("400.0E6");
71 MSG_process_create_with_arguments("proc1", process_code, NULL, host, argc1, params1);
73 // Process 2 - sleep 2 sec + CPU task
75 char** params2 = xbt_malloc0(sizeof(char *) * argc2);
76 params2[0] = xbt_strdup("100.0E6");
77 params2[1] = xbt_strdup("2");
78 MSG_process_create_with_arguments("proc2", process_code, NULL, host, argc2, params2);
80 // Process 3 - sleep 2 sec + CPU task
82 char** params3 = xbt_malloc0(sizeof(char *) * argc3);
83 params3[0] = xbt_strdup("100.0E6");
84 params3[1] = xbt_strdup("2");
85 MSG_process_create_with_arguments("proc3", process_code, NULL, host, argc3, params3);
91 task_time = MSG_get_clock() - task_time;
92 XBT_INFO("Task simulation time: %e", task_time);
93 consumed_energy = MSG_get_host_consumed_energy(host);
94 XBT_INFO("Total energy (Joules): %f", consumed_energy);
99 int main(int argc, char *argv[])
101 msg_error_t res = MSG_OK;
103 MSG_init(&argc, argv);
106 XBT_CRITICAL("Usage: %s platform_file deployment_file\n",
109 ("example: %s msg_platform.xml msg_deployment.xml\n",
114 MSG_create_environment(argv[1]);
116 /* Application deployment */
117 MSG_function_register("dvfs_test", dvfs);
119 MSG_launch_application(argv[2]);
123 XBT_INFO("Total simulation time: %e", MSG_get_clock());