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. */
9 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
10 #include "xbt/sysdep.h" /* calloc */
12 /* Create a log channel to have nice outputs. */
14 #include "xbt/asserts.h"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
17 "Messages specific for this msg example");
19 int sender(int argc, char *argv[]);
20 int receiver(int argc, char *argv[]);
22 MSG_error_t test_all(const char *platform_file,
23 const char *application_file);
25 double task_comm_size_lat = 10e0;
26 double task_comm_size_bw = 10e8;
28 /** Emitter function */
29 int sender(int argc, char *argv[])
33 m_task_t task_la = NULL;
34 m_task_t task_bw = NULL;
35 char sprintf_buffer_la[64];
36 char sprintf_buffer_bw[64];
40 /*host = xbt_new0(m_host_t,1); */
42 XBT_INFO("host = %s", argv[1]);
44 host = MSG_get_host_by_name(argv[1]);
47 XBT_INFO("Unknown host %s. Stopping Now! ", argv[1]);
52 time = MSG_get_clock();
53 sprintf(sprintf_buffer_la, "latency task");
55 MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL);
56 task_la->data = xbt_new(double, 1);
57 *(double *) task_la->data = time;
58 XBT_INFO("task_la->data = %le", *((double *) task_la->data));
59 MSG_task_send(task_la, argv[1]);
62 time = MSG_get_clock();
63 sprintf(sprintf_buffer_bw, "bandwidth task");
65 MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL);
66 task_bw->data = xbt_new(double, 1);
67 *(double *) task_bw->data = time;
68 XBT_INFO("task_bw->data = %le", *((double *) task_bw->data));
69 MSG_task_send(task_bw, argv[1]);
74 /** Receiver function */
75 int receiver(int argc, char *argv[])
77 double time, time1, sender_time;
78 m_task_t task_la = NULL;
79 m_task_t task_bw = NULL;
81 double communication_time = 0;
85 time = MSG_get_clock();
88 a = MSG_task_receive(&task_la,MSG_host_get_name(MSG_host_self()));
90 time1 = MSG_get_clock();
91 sender_time = *((double *) (task_la->data));
93 communication_time = time1 - time;
94 XBT_INFO("Task received : %s", task_la->name);
95 xbt_free(task_la->data);
96 MSG_task_destroy(task_la);
97 XBT_INFO("Communic. time %le", communication_time);
98 XBT_INFO("--- la %f ----", communication_time);
100 xbt_die("Unexpected behavior");
105 a = MSG_task_receive(&task_bw,MSG_host_get_name(MSG_host_self()));
107 time1 = MSG_get_clock();
108 sender_time = *((double *) (task_bw->data));
110 communication_time = time1 - time;
111 XBT_INFO("Task received : %s", task_bw->name);
112 xbt_free(task_bw->data);
113 MSG_task_destroy(task_bw);
114 XBT_INFO("Communic. time %le", communication_time);
115 XBT_INFO("--- bw %f ----", task_comm_size_bw / communication_time);
117 xbt_die("Unexpected behavior");
122 } /* end_of_receiver */
126 MSG_error_t test_all(const char *platform_file,
127 const char *application_file)
130 MSG_error_t res = MSG_OK;
134 XBT_INFO("test_all");
136 /* Simulation setting */
137 MSG_create_environment(platform_file);
139 /* Application deployment */
140 MSG_function_register("sender", sender);
141 MSG_function_register("receiver", receiver);
143 MSG_launch_application(application_file);
148 } /* end_of_test_all */
152 int main(int argc, char *argv[])
154 MSG_error_t res = MSG_OK;
157 unsigned int prev_exponent_format =
158 _set_output_format(_TWO_DIGIT_EXPONENT);
161 MSG_global_init(&argc, argv);
165 XBT_CRITICAL("Usage: %s platform_file deployment_file <model>\n",
168 ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n",
173 /* Options for the workstation/model:
175 KCCFLN05 => for maxmin
176 KCCFLN05_proportional => for proportional (Vegas)
177 KCCFLN05_Vegas => for TCP Vegas
178 KCCFLN05_Reno => for TCP Reno
180 //MSG_config("workstation/model", argv[3]);
182 res = test_all(argv[1], argv[2]);
184 XBT_INFO("Total simulation time: %le", MSG_get_clock());
189 _set_output_format(prev_exponent_format);