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);
29 //keep a pointer to all surf running tasks.
32 double start_time, end_time, elapsed_time;
33 double gl_data_size[NTASKS];
34 m_task_t gl_task_array[NTASKS];
35 const char *slavenames[NTASKS];
36 const char *masternames[NTASKS];
37 int gl_task_array_id = 0;
38 int count_finished = 0;
40 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
43 int master(int argc, char *argv[])
45 char *slavename = NULL;
46 double task_comm_size = 0;
50 //unique id to control statistics
54 XBT_INFO("Strange number of arguments expected 3 got %d", argc - 1);
59 read = sscanf(argv[1], "%lg", &task_comm_size);
60 xbt_assert(read, "Invalid argument %s\n", argv[1]);
65 sprintf(id_alias, "flow_%d", id);
66 slavenames[id] = slavename;
67 TRACE_category(id_alias);
69 masternames[id] = MSG_host_get_name(MSG_host_self());
71 { /* Task creation. */
72 char sprintf_buffer[64] = "Task_0";
73 todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
74 TRACE_msg_set_task_category(todo, id_alias);
75 //keep track of running tasks
76 gl_task_array[id] = todo;
77 gl_data_size[id] = task_comm_size;
80 { /* Process organisation */
81 slave = MSG_get_host_by_name(slavename);
86 /* time measurement */
87 sprintf(id_alias, "%d", id);
88 start_time = MSG_get_clock();
89 MSG_task_send(todo, id_alias);
90 end_time = MSG_get_clock();
98 int timer(int argc, char *argv[])
104 XBT_INFO("Strange number of arguments expected 2 got %d", argc - 1);
107 sscanf(argv[1], "%d", &first_sleep);
108 sscanf(argv[2], "%d", &sleep_time);
111 MSG_process_sleep(first_sleep);
115 MSG_process_sleep(sleep_time);
121 /** Receiver function */
122 int slave(int argc, char *argv[])
125 m_task_t task = NULL;
128 #ifdef HAVE_LATENCY_BOUND_TRACKING
129 int limited_latency = 0;
131 double remaining = 0;
135 XBT_INFO("Strange number of arguments expected 1 got %d", argc - 1);
139 sprintf(id_alias, "%d", id);
142 a = MSG_task_receive(&(task), id_alias);
145 if(count_finished == 0){
152 XBT_INFO("Hey?! What's up?");
153 xbt_die("Unexpected behavior.");
156 elapsed_time = MSG_get_clock() - start_time;
162 for (id = 0; id < NTASKS; id++) {
163 if (gl_task_array[id] == NULL) {
164 } else if (gl_task_array[id] == task) {
165 #ifdef HAVE_LATENCY_BOUND_TRACKING
166 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
167 if (limited_latency) {
168 XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
172 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
173 id, gl_data_size[id] / elapsed_time, masternames[id],
174 slavenames[id], 0.0);
177 MSG_task_get_remaining_communication(gl_task_array[id]);
178 #ifdef HAVE_LATENCY_BOUND_TRACKING
179 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
181 if (limited_latency) {
182 XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
186 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
187 id, (gl_data_size[id] - remaining) / elapsed_time,
188 masternames[id], slavenames[id], remaining);
194 snprintf(mark, 100, "flow_%d_finished", trace_id);
195 TRACE_mark("endmark", mark);
197 MSG_task_destroy(task);
203 MSG_error_t test_all(const char *platform_file,
204 const char *application_file)
206 MSG_error_t res = MSG_OK;
208 /* MSG_config("workstation/model", "GTNETS"); */
209 /* MSG_config("workstation/model","KCCFLN05"); */
210 { /* Simulation setting */
211 MSG_set_channel_number(MAX_CHANNEL);
212 MSG_create_environment(platform_file);
215 TRACE_declare_mark("endmark");
217 { /* Application deployment */
218 MSG_function_register("master", master);
219 MSG_function_register("slave", slave);
220 MSG_function_register("timer", timer);
222 MSG_launch_application(application_file);
226 } /* end_of_test_all */
229 int main(int argc, char *argv[])
231 MSG_error_t res = MSG_OK;
234 MSG_global_init(&argc, argv);
236 printf("Usage: %s platform_file deployment_file\n", argv[0]);
240 res = test_all(argv[1], argv[2]);