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 MSG_error_t test_all(const char *platform_file,
19 const char *application_file);
26 //keep a pointer to all surf running tasks.
29 double start_time, end_time, elapsed_time;
30 double gl_data_size[NTASKS];
31 m_task_t gl_task_array[NTASKS];
32 const char *slavenames[NTASKS];
33 const char *masternames[NTASKS];
34 int gl_task_array_id = 0;
36 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
39 int master(int argc, char *argv[])
41 char *slavename = NULL;
42 double task_comm_size = 0;
46 //unique id to control statistics
50 INFO1("Strange number of arguments expected 3 got %d", argc - 1);
54 xbt_assert1(sscanf(argv[1], "%lg", &task_comm_size),
55 "Invalid argument %s\n", argv[1]);
60 sprintf(id_alias, "flow_%d", id);
61 slavenames[id] = slavename;
62 TRACE_category(id_alias);
64 masternames[id] = MSG_host_get_name(MSG_host_self());
66 { /* Task creation. */
67 char sprintf_buffer[64] = "Task_0";
68 todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
69 TRACE_msg_set_task_category(todo, id_alias);
70 //keep track of running tasks
71 gl_task_array[id] = todo;
72 gl_data_size[id] = task_comm_size;
75 { /* Process organisation */
76 slave = MSG_get_host_by_name(slavename);
79 /* time measurement */
80 sprintf(id_alias, "%d", id);
81 start_time = MSG_get_clock();
82 MSG_task_send(todo, id_alias);
83 end_time = MSG_get_clock();
89 /** Receiver function */
90 int slave(int argc, char *argv[])
96 #ifdef HAVE_LATENCY_BOUND_TRACKING
97 int limited_latency = 0;
103 INFO1("Strange number of arguments expected 1 got %d", argc - 1);
107 sprintf(id_alias, "%d", id);
110 a = MSG_task_receive(&(task), id_alias);
113 INFO0("Hey?! What's up?");
114 xbt_assert0(0, "Unexpected behavior.");
117 elapsed_time = MSG_get_clock() - start_time;
123 for (id = 0; id < NTASKS; id++) {
124 if (gl_task_array[id] == NULL) {
125 } else if (gl_task_array[id] == task) {
126 #ifdef HAVE_LATENCY_BOUND_TRACKING
127 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
128 if (limited_latency) {
129 INFO1("WARNING FLOW[%d] is limited by latency!!", id);
133 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
134 id, gl_data_size[id] / elapsed_time, masternames[id],
135 slavenames[id], 0.0);
138 MSG_task_get_remaining_communication(gl_task_array[id]);
139 #ifdef HAVE_LATENCY_BOUND_TRACKING
140 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
142 if (limited_latency) {
143 INFO1("WARNING FLOW[%d] is limited by latency!!", id);
147 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
148 id, (gl_data_size[id] - remaining) / elapsed_time,
149 masternames[id], slavenames[id], remaining);
155 snprintf(mark, 100, "flow_%d_finished", trace_id);
156 TRACE_mark("endmark", mark);
158 MSG_task_destroy(task);
163 MSG_error_t test_all(const char *platform_file,
164 const char *application_file)
166 MSG_error_t res = MSG_OK;
168 /* MSG_config("workstation/model", "GTNETS"); */
169 /* MSG_config("workstation/model","KCCFLN05"); */
170 { /* Simulation setting */
171 MSG_set_channel_number(MAX_CHANNEL);
172 MSG_create_environment(platform_file);
174 { /* Application deployment */
175 MSG_function_register("master", master);
176 MSG_function_register("slave", slave);
177 MSG_launch_application(application_file);
181 } /* end_of_test_all */
184 int main(int argc, char *argv[])
186 MSG_error_t res = MSG_OK;
189 MSG_global_init(&argc, argv);
191 printf("Usage: %s platform_file deployment_file\n", argv[0]);
195 TRACE_declare_mark("endmark");
197 res = test_all(argv[1], argv[2]);