1 /* Copyright (c) 2007-2015. 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. */
9 #include "simgrid/msg.h"
11 #include "xbt/asserts.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14 "Messages specific for this msg example");
16 /** @addtogroup MSG_examples
18 * - <b>gtnets</b> Simple ping-pong using GTNeTs instead of the SimGrid network models.
21 int master(int argc, char *argv[]);
22 int slave(int argc, char *argv[]);
23 msg_error_t test_all(const char *platform_file,
24 const char *application_file);
28 //keep a pointer to all surf running tasks.
31 double start_time, end_time, elapsed_time;
32 double gl_data_size[NTASKS];
33 msg_task_t gl_task_array[NTASKS];
34 const char *slavenames[NTASKS];
35 const char *masternames[NTASKS];
36 int gl_task_array_id = 0;
37 int count_finished = 0;
40 int master(int argc, char *argv[])
42 char *slavename = NULL;
43 double task_comm_size = 0;
46 //unique id to control statistics
49 xbt_assert(argc == 4, "Strange number of arguments expected 3 got %d",
54 read = sscanf(argv[1], "%lg", &task_comm_size);
55 xbt_assert(read, "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 MSG_task_set_category(todo, id_alias);
70 //keep track of running tasks
71 gl_task_array[id] = todo;
72 gl_data_size[id] = task_comm_size;
77 /* time measurement */
78 sprintf(id_alias, "%d", id);
79 start_time = MSG_get_clock();
80 MSG_task_send(todo, id_alias);
81 end_time = MSG_get_clock();
87 /** Receiver function */
88 int slave(int argc, char *argv[])
91 msg_task_t task = NULL;
94 #ifdef HAVE_LATENCY_BOUND_TRACKING
95 int limited_latency = 0;
100 xbt_assert(argc == 2, "Strange number of arguments expected 1 got %d",
104 sprintf(id_alias, "%d", id);
107 a = MSG_task_receive(&(task), id_alias);
110 if(count_finished == 0){
114 xbt_assert(a == MSG_OK,"Hey?! What's up? Unexpected behavior");
116 elapsed_time = MSG_get_clock() - start_time;
121 for (id = 0; id < NTASKS; id++) {
122 if (gl_task_array[id] == NULL) continue;
123 if (gl_task_array[id] == task) {
124 #ifdef HAVE_LATENCY_BOUND_TRACKING
125 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
126 if (limited_latency) {
127 XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
131 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
132 id, gl_data_size[id] / elapsed_time, masternames[id],
133 slavenames[id], 0.0);
134 MSG_task_destroy(gl_task_array[id]);
135 gl_task_array[id]=NULL;
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 XBT_INFO("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);
151 MSG_task_destroy(gl_task_array[id]);
152 gl_task_array[id]=NULL;
159 snprintf(mark, 100, "flow_%d_finished", trace_id);
160 TRACE_mark("endmark", mark);
162 if(bool_printed==2 && gl_task_array[trace_id]) MSG_task_destroy(gl_task_array[trace_id]);
168 msg_error_t test_all(const char *platform_file,
169 const char *application_file)
171 msg_error_t res = MSG_OK;
173 { /* Simulation setting */
174 MSG_create_environment(platform_file);
177 TRACE_declare_mark("endmark");
179 { /* Application deployment */
180 MSG_function_register("master", master);
181 MSG_function_register("slave", slave);
183 MSG_launch_application(application_file);
187 } /* end_of_test_all */
190 int main(int argc, char *argv[])
192 msg_error_t res = MSG_OK;
195 MSG_init(&argc, argv);
196 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
197 "\tExample: %s platform.xml deployment.xml\n",
200 res = test_all(argv[1], argv[2]);
202 return res != MSG_OK;