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);
30 double task_comm_size_lat = 10e0;
31 double task_comm_size_bw = 10e8;
33 /** Emitter function */
34 int sender(int argc, char *argv[])
38 m_task_t task_la = NULL;
39 m_task_t task_bw = NULL;
40 char sprintf_buffer_la[64];
41 char sprintf_buffer_bw[64];
45 /*host = xbt_new0(m_host_t,1); */
47 INFO1("host = %s", argv[1]);
49 host = MSG_get_host_by_name(argv[1]);
52 INFO1("Unknown host %s. Stopping Now! ", argv[1]);
57 time = MSG_get_clock();
58 sprintf(sprintf_buffer_la, "latency task");
60 MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL);
61 task_la->data = xbt_new(double, 1);
62 *(double *) task_la->data = time;
63 INFO1("task_la->data = %le", *((double *) task_la->data));
64 MSG_task_put(task_la, host, PORT_22);
67 time = MSG_get_clock();
68 sprintf(sprintf_buffer_bw, "bandwidth task");
70 MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL);
71 task_bw->data = xbt_new(double, 1);
72 *(double *) task_bw->data = time;
73 INFO1("task_bw->data = %le", *((double *) task_bw->data));
74 MSG_task_put(task_bw, host, PORT_22);
79 /** Receiver function */
80 int receiver(int argc, char *argv[])
82 double time, time1, sender_time;
83 m_task_t task_la = NULL;
84 m_task_t task_bw = NULL;
86 double communication_time = 0;
90 time = MSG_get_clock();
93 a = MSG_task_get(&task_la, PORT_22);
95 time1 = MSG_get_clock();
96 sender_time = *((double *) (task_la->data));
98 communication_time = time1 - time;
99 INFO1("Task received : %s", task_la->name);
100 MSG_task_destroy(task_la);
101 INFO1("Communic. time %le", communication_time);
102 INFO1("--- la %f ----", communication_time);
104 xbt_assert0(0, "Unexpected behavior");
109 a = MSG_task_get(&task_bw, PORT_22);
111 time1 = MSG_get_clock();
112 sender_time = *((double *) (task_bw->data));
114 communication_time = time1 - time;
115 INFO1("Task received : %s", task_bw->name);
116 MSG_task_destroy(task_bw);
117 INFO1("Communic. time %le", communication_time);
118 INFO1("--- bw %f ----", task_comm_size_bw / communication_time);
120 xbt_assert0(0, "Unexpected behavior");
125 } /* end_of_receiver */
129 MSG_error_t test_all(const char *platform_file,
130 const char *application_file)
133 MSG_error_t res = MSG_OK;
139 /* Simulation setting */
140 MSG_set_channel_number(MAX_CHANNEL);
141 MSG_create_environment(platform_file);
143 /* Application deployment */
144 MSG_function_register("sender", sender);
145 MSG_function_register("receiver", receiver);
147 MSG_launch_application(application_file);
152 } /* end_of_test_all */
156 int main(int argc, char *argv[])
158 MSG_error_t res = MSG_OK;
161 unsigned int prev_exponent_format =
162 _set_output_format(_TWO_DIGIT_EXPONENT);
165 MSG_global_init(&argc, argv);
169 CRITICAL1("Usage: %s platform_file deployment_file <model>\n",
172 ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n",
177 /* Options for the workstation/model:
179 KCCFLN05 => for maxmin
180 KCCFLN05_proportional => for proportional (Vegas)
181 KCCFLN05_Vegas => for TCP Vegas
182 KCCFLN05_Reno => for TCP Reno
184 //MSG_config("workstation/model", argv[3]);
186 res = test_all(argv[1], argv[2]);
188 INFO1("Total simulation time: %le", MSG_get_clock());
193 _set_output_format(prev_exponent_format);