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 XBT_INFO("Strange number of arguments expected 3 got %d", argc - 1);
55 read = sscanf(argv[1], "%lg", &task_comm_size);
56 xbt_assert(read, "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();
90 /** Receiver function */
91 int slave(int argc, char *argv[])
97 #ifdef HAVE_LATENCY_BOUND_TRACKING
98 int limited_latency = 0;
100 double remaining = 0;
104 XBT_INFO("Strange number of arguments expected 1 got %d", argc - 1);
108 sprintf(id_alias, "%d", id);
111 a = MSG_task_receive(&(task), id_alias);
114 XBT_INFO("Hey?! What's up?");
115 xbt_die("Unexpected behavior.");
118 elapsed_time = MSG_get_clock() - start_time;
124 for (id = 0; id < NTASKS; id++) {
125 if (gl_task_array[id] == NULL) {
126 } else if (gl_task_array[id] == task) {
127 #ifdef HAVE_LATENCY_BOUND_TRACKING
128 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
129 if (limited_latency) {
130 XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
134 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
135 id, gl_data_size[id] / elapsed_time, masternames[id],
136 slavenames[id], 0.0);
139 MSG_task_get_remaining_communication(gl_task_array[id]);
140 #ifdef HAVE_LATENCY_BOUND_TRACKING
141 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
143 if (limited_latency) {
144 XBT_INFO("WARNING FLOW[%d] is limited by latency!!", id);
148 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
149 id, (gl_data_size[id] - remaining) / elapsed_time,
150 masternames[id], slavenames[id], remaining);
156 snprintf(mark, 100, "flow_%d_finished", trace_id);
157 TRACE_mark("endmark", mark);
159 MSG_task_destroy(task);
164 MSG_error_t test_all(const char *platform_file,
165 const char *application_file)
167 MSG_error_t res = MSG_OK;
169 /* MSG_config("workstation/model", "GTNETS"); */
170 /* MSG_config("workstation/model","KCCFLN05"); */
171 { /* Simulation setting */
172 MSG_set_channel_number(MAX_CHANNEL);
173 MSG_create_environment(platform_file);
176 TRACE_declare_mark("endmark");
178 { /* Application deployment */
179 MSG_function_register("master", master);
180 MSG_function_register("slave", slave);
181 MSG_launch_application(application_file);
185 } /* end_of_test_all */
188 int main(int argc, char *argv[])
190 MSG_error_t res = MSG_OK;
193 MSG_global_init(&argc, argv);
195 printf("Usage: %s platform_file deployment_file\n", argv[0]);
199 res = test_all(argv[1], argv[2]);