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"
12 #include "gras_config.h" //for HAVE_LATENCY_BOUND_TRACKING
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15 "Messages specific for this msg example");
17 int master(int argc, char *argv[]);
18 int slave(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file,
20 const char *application_file);
27 //keep a pointer to all surf running tasks.
30 double start_time, end_time, elapsed_time;
31 double gl_data_size[NTASKS];
32 m_task_t gl_task_array[NTASKS];
33 const char *slavenames[NTASKS];
34 const char *masternames[NTASKS];
35 int gl_task_array_id = 0;
37 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
40 int master(int argc, char *argv[])
42 char *slavename = NULL;
43 double task_comm_size = 0;
47 //unique id to control statistics
51 INFO1("Strange number of arguments expected 3 got %d", argc - 1);
55 xbt_assert1(sscanf(argv[1], "%lg", &task_comm_size),
56 "Invalid argument %s\n", argv[1]);
61 sprintf(id_alias, "flow_%d", id);
62 slavenames[id] = slavename;
63 TRACE_category(id_alias);
65 masternames[id] = MSG_host_get_name(MSG_host_self());
67 { /* Task creation. */
68 char sprintf_buffer[64] = "Task_0";
69 todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
70 TRACE_msg_set_task_category(todo, id_alias);
71 //keep track of running tasks
72 gl_task_array[id] = todo;
73 gl_data_size[id] = task_comm_size;
76 { /* Process organisation */
77 slave = MSG_get_host_by_name(slavename);
80 /* time measurement */
81 sprintf(id_alias, "%d", id);
82 start_time = MSG_get_clock();
83 MSG_task_send(todo, id_alias);
84 end_time = MSG_get_clock();
89 ("Send completed (to %s). Transfer time: %f\t Agregate bandwidth: %f",
90 slave->name, (end_time - start_time),
91 task_comm_size / (end_time - start_time));
92 INFO2("Completed peer: %s time: %f", slave->name,
93 (end_time - start_time));
98 /** Receiver function */
99 int slave(int argc, char *argv[])
102 m_task_t task = NULL;
105 #ifdef HAVE_LATENCY_BOUND_TRACKING
106 int limited_latency = 0;
108 double remaining = 0;
112 INFO1("Strange number of arguments expected 1 got %d", argc - 1);
116 sprintf(id_alias, "%d", id);
119 a = MSG_task_receive(&(task), id_alias);
122 INFO0("Hey?! What's up?");
123 xbt_assert0(0, "Unexpected behavior.");
126 elapsed_time = MSG_get_clock() - start_time;
130 for (id = 0; id < NTASKS; id++) {
131 if (gl_task_array[id] == NULL) {
132 } else if (gl_task_array[id] == task) {
133 #ifdef HAVE_LATENCY_BOUND_TRACKING
134 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
135 if (limited_latency) {
136 INFO1("WARNING FLOW[%d] is limited by latency!!", id);
140 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
141 id, gl_data_size[id] / elapsed_time, masternames[id],
142 slavenames[id], 0.0);
145 MSG_task_get_remaining_communication(gl_task_array[id]);
146 #ifdef HAVE_LATENCY_BOUND_TRACKING
147 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
149 if (limited_latency) {
150 INFO1("WARNING FLOW[%d] is limited by latency!!", id);
154 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
155 id, (gl_data_size[id] - remaining) / elapsed_time,
156 masternames[id], slavenames[id], remaining);
162 snprintf(mark, 100, "flow_%d_finished", trace_id);
163 TRACE_mark("endmark", mark);
165 MSG_task_destroy(task);
170 MSG_error_t test_all(const char *platform_file,
171 const char *application_file)
173 MSG_error_t res = MSG_OK;
175 /* MSG_config("workstation/model", "GTNETS"); */
176 /* MSG_config("workstation/model","KCCFLN05"); */
177 { /* Simulation setting */
178 MSG_set_channel_number(MAX_CHANNEL);
179 MSG_create_environment(platform_file);
181 { /* Application deployment */
182 MSG_function_register("master", master);
183 MSG_function_register("slave", slave);
184 MSG_launch_application(application_file);
188 } /* end_of_test_all */
191 int main(int argc, char *argv[])
193 MSG_error_t res = MSG_OK;
196 MSG_global_init(&argc, argv);
198 printf("Usage: %s platform_file deployment_file\n", argv[0]);
203 TRACE_declare_mark("endmark");
205 res = test_all(argv[1], argv[2]);