5 #include "xbt/asserts.h"
7 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
8 "Messages specific for this msg example");
10 int master(int argc, char *argv[]);
11 int slave(int argc, char *argv[]);
12 MSG_error_t test_all(const char *platform_file, const char *application_file);
19 //keep a pointer to all surf running tasks.
22 double start_time, end_time, elapsed_time;
23 double gl_data_size[NTASKS];
24 m_task_t gl_task_array[NTASKS];
25 const char *slavenames[NTASKS];
26 const char *masternames[NTASKS];
27 int gl_task_array_id = 0;
29 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
32 int master(int argc, char *argv[])
34 char *slavename = NULL;
35 double task_comm_size = 0;
39 //unique id to control statistics
43 INFO1("Strange number of arguments expected 3 got %d", argc - 1);
47 xbt_assert1(sscanf(argv[1], "%lg", &task_comm_size),
48 "Invalid argument %s\n", argv[1]);
53 sprintf(id_alias, "%d", id);
54 slavenames[id] = slavename;
56 TRACE_category (slavename);
58 masternames[id] = MSG_host_get_name(MSG_host_self());
60 { /* Task creation. */
61 char sprintf_buffer[64] = "Task_0";
62 todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
63 TRACE_msg_set_task_category(todo,slavename);
64 //keep track of running tasks
65 gl_task_array[id] = todo;
66 gl_data_size[id] = task_comm_size;
69 { /* Process organisation */
70 slave = MSG_get_host_by_name(slavename);
73 /* time measurement */
74 start_time = MSG_get_clock();
75 MSG_task_send(todo, id_alias);
77 end_time = MSG_get_clock();
78 INFO3("Send completed (to %s). Transfer time: %f\t Agregate bandwidth: %f",
79 slave->name, (end_time - start_time),
80 task_comm_size / (end_time - start_time));
81 INFO2("Completed peer: %s time: %f", slave->name, (end_time - start_time));
86 /** Receiver function */
87 int slave(int argc, char *argv[])
97 INFO1("Strange number of arguments expected 1 got %d", argc - 1);
101 sprintf(id_alias, "%d", id);
103 a = MSG_task_receive(&(task), id_alias);
106 INFO0("Hey?! What's up?");
107 xbt_assert0(0, "Unexpected behavior.");
110 elapsed_time = MSG_get_clock() - start_time;
114 for (id = 0; id < NTASKS; id++) {
115 if (gl_task_array[id] == NULL) {
116 } else if (gl_task_array[id] == task) {
118 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
119 id, gl_data_size[id] / elapsed_time, masternames[id],
120 slavenames[id], 0.0);
122 remaining = MSG_task_get_remaining_communication(gl_task_array[id]);
124 ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f",
125 id, (gl_data_size[id] - remaining) / elapsed_time, masternames[id],
126 slavenames[id], remaining);
132 for (id = 0; id < NTASKS; id++) {
133 if (gl_task_array[id] == task) {
134 MSG_task_destroy(task);
135 gl_task_array[id] = NULL;
144 MSG_error_t test_all(const char *platform_file, const char *application_file)
146 MSG_error_t res = MSG_OK;
148 /* MSG_config("workstation/model", "GTNETS"); */
149 /* MSG_config("workstation/model","KCCFLN05"); */
150 { /* Simulation setting */
151 MSG_set_channel_number(MAX_CHANNEL);
152 MSG_create_environment(platform_file);
154 { /* Application deployment */
155 MSG_function_register("master", master);
156 MSG_function_register("slave", slave);
157 MSG_launch_application(application_file);
161 } /* end_of_test_all */
164 int main(int argc, char *argv[])
166 MSG_error_t res = MSG_OK;
169 TRACE_start ("z_gtnets.trace");
171 MSG_global_init(&argc, argv);
173 printf("Usage: %s platform_file deployment_file\n", argv[0]);
176 res = test_all(argv[1], argv[2]);