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, const char *application_file);
25 //keep a pointer to all surf running tasks.
28 double start_time, end_time, elapsed_time;
29 double gl_data_size[NTASKS];
30 m_task_t gl_task_array[NTASKS];
31 const char *slavenames[NTASKS];
32 const char *masternames[NTASKS];
33 int gl_task_array_id = 0;
35 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
38 int master(int argc, char *argv[])
40 char *slavename = NULL;
41 double task_comm_size = 0;
45 //unique id to control statistics
49 INFO1("Strange number of arguments expected 3 got %d", argc - 1);
53 xbt_assert1(sscanf(argv[1], "%lg", &task_comm_size),
54 "Invalid argument %s\n", argv[1]);
59 sprintf(id_alias, "flow_%d", id);
60 slavenames[id] = slavename;
61 TRACE_category (id_alias);
63 masternames[id] = MSG_host_get_name(MSG_host_self());
65 { /* Task creation. */
66 char sprintf_buffer[64] = "Task_0";
67 todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
68 TRACE_msg_set_task_category(todo,id_alias);
69 //keep track of running tasks
70 gl_task_array[id] = todo;
71 gl_data_size[id] = task_comm_size;
74 { /* Process organisation */
75 slave = MSG_get_host_by_name(slavename);
78 /* time measurement */
79 sprintf(id_alias, "%d", id);
80 start_time = MSG_get_clock();
81 MSG_task_send(todo, id_alias);
82 end_time = MSG_get_clock();
86 INFO3("Send completed (to %s). Transfer time: %f\t Agregate bandwidth: %f",
87 slave->name, (end_time - start_time),
88 task_comm_size / (end_time - start_time));
89 INFO2("Completed peer: %s time: %f", slave->name, (end_time - start_time));
94 /** Receiver function */
95 int slave(int argc, char *argv[])
101 int limited_latency=0;
102 double remaining = 0;
106 INFO1("Strange number of arguments expected 1 got %d", argc - 1);
110 sprintf(id_alias, "%d", id);
112 a = MSG_task_receive(&(task), id_alias);
115 INFO0("Hey?! What's up?");
116 xbt_assert0(0, "Unexpected behavior.");
119 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 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
128 INFO1("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);
135 remaining = MSG_task_get_remaining_communication(gl_task_array[id]);
136 limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]);
139 INFO1("WARNING FLOW[%d] is limited by latency!!", id);
142 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
143 id, (gl_data_size[id] - remaining) / elapsed_time, masternames[id],
144 slavenames[id], remaining);
148 TRACE_mark ("endmark", "finished");
151 MSG_task_destroy(task);
156 MSG_error_t test_all(const char *platform_file, const char *application_file)
158 MSG_error_t res = MSG_OK;
160 /* MSG_config("workstation/model", "GTNETS"); */
161 /* MSG_config("workstation/model","KCCFLN05"); */
162 { /* Simulation setting */
163 MSG_set_channel_number(MAX_CHANNEL);
164 MSG_create_environment(platform_file);
166 { /* Application deployment */
167 MSG_function_register("master", master);
168 MSG_function_register("slave", slave);
169 MSG_launch_application(application_file);
173 } /* end_of_test_all */
176 int main(int argc, char *argv[])
178 MSG_error_t res = MSG_OK;
181 MSG_global_init(&argc, argv);
183 printf("Usage: %s platform_file deployment_file\n", argv[0]);
189 res = test_all(argv[1], argv[2]);