1 /* Copyright (c) 2007, 2008, 2009, 2010. 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. */
11 #include "xbt/asserts.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14 "Messages specific for this msg example");
16 int master(int argc, char *argv[]);
17 int slave(int argc, char *argv[]);
18 int timer(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file,
20 const char *application_file);
24 //keep a pointer to all surf running tasks.
27 double start_time, end_time, elapsed_time;
28 double gl_data_size[NTASKS];
29 m_task_t gl_task_array[NTASKS];
30 const char *slavenames[NTASKS];
31 const char *masternames[NTASKS];
32 int gl_task_array_id = 0;
33 int count_finished = 0;
35 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
38 int master(int argc, char *argv[])
40 char *slavename = NULL;
41 double task_comm_size = 0;
44 //unique id to control statistics
48 XBT_INFO("Strange number of arguments expected 3 got %d", argc - 1);
53 read = sscanf(argv[1], "%lg", &task_comm_size);
54 xbt_assert(read, "Invalid argument %s\n", argv[1]);
59 sprintf(id_alias, "flow_%d", id);
60 slavenames[id] = slavename;
61 TRACE_category(id_alias);
63 masternames[id] = MSG_host_get_name(MSG_host_self());
65 { /* Task creation. */
66 char sprintf_buffer[64] = "Task_0";
67 todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
68 TRACE_msg_set_task_category(todo, id_alias);
69 //keep track of running tasks
70 gl_task_array[id] = todo;
71 gl_data_size[id] = task_comm_size;
76 /* time measurement */
77 sprintf(id_alias, "%d", id);
78 start_time = MSG_get_clock();
79 MSG_task_send(todo, id_alias);
80 end_time = MSG_get_clock();
88 int timer(int argc, char *argv[])
94 XBT_INFO("Strange number of arguments expected 2 got %d", argc - 1);
97 sscanf(argv[1], "%d", &first_sleep);
98 sscanf(argv[2], "%d", &sleep_time);
101 MSG_process_sleep(first_sleep);
105 MSG_process_sleep(sleep_time);
111 /** Receiver function */
112 int slave(int argc, char *argv[])
115 m_task_t task = NULL;
118 #ifdef HAVE_LATENCY_BOUND_TRACKING
119 int limited_latency = 0;
121 double remaining = 0;
125 XBT_INFO("Strange number of arguments expected 1 got %d", argc - 1);
129 sprintf(id_alias, "%d", id);
132 a = MSG_task_receive(&(task), id_alias);
135 if(count_finished == 0){
142 XBT_INFO("Hey?! What's up?");
143 xbt_die("Unexpected behavior.");
146 elapsed_time = MSG_get_clock() - start_time;
152 for (id = 0; id < NTASKS; id++) {
153 if (gl_task_array[id] == NULL) continue;
154 if (gl_task_array[id] == task) {
155 #ifdef HAVE_LATENCY_BOUND_TRACKING
156 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
157 if (limited_latency) {
158 XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
162 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
163 id, gl_data_size[id] / elapsed_time, masternames[id],
164 slavenames[id], 0.0);
165 MSG_task_destroy(gl_task_array[id]);
166 gl_task_array[id]=NULL;
169 MSG_task_get_remaining_communication(gl_task_array[id]);
170 #ifdef HAVE_LATENCY_BOUND_TRACKING
171 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
173 if (limited_latency) {
174 XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
178 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
179 id, (gl_data_size[id] - remaining) / elapsed_time,
180 masternames[id], slavenames[id], remaining);
182 MSG_task_destroy(gl_task_array[id]);
183 gl_task_array[id]=NULL;
190 snprintf(mark, 100, "flow_%d_finished", trace_id);
191 TRACE_mark("endmark", mark);
193 if(bool_printed==2 && gl_task_array[trace_id]) MSG_task_destroy(gl_task_array[trace_id]);
199 MSG_error_t test_all(const char *platform_file,
200 const char *application_file)
202 MSG_error_t res = MSG_OK;
204 /* MSG_config("workstation/model", "GTNETS"); */
205 /* MSG_config("workstation/model","KCCFLN05"); */
206 { /* Simulation setting */
207 MSG_create_environment(platform_file);
210 TRACE_declare_mark("endmark");
212 { /* Application deployment */
213 MSG_function_register("master", master);
214 MSG_function_register("slave", slave);
215 MSG_function_register("timer", timer);
217 MSG_launch_application(application_file);
221 } /* end_of_test_all */
224 int main(int argc, char *argv[])
226 MSG_error_t res = MSG_OK;
229 MSG_global_init(&argc, argv);
231 printf("Usage: %s platform_file deployment_file\n", argv[0]);
235 res = test_all(argv[1], argv[2]);