2 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h" /* calloc */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
17 int sender(int argc, char *argv[]);
18 int receiver(int argc, char *argv[]);
20 MSG_error_t test_all(const char *platform_file, const char *application_file);
28 double task_comm_size_lat = 10e0;
29 double task_comm_size_bw = 10e8;
31 /** Emitter function */
32 int sender(int argc,char *argv[] )
36 m_task_t task_la=NULL;
37 m_task_t task_bw=NULL;
38 char sprintf_buffer_la[64];
39 char sprintf_buffer_bw[64];
43 /*host = xbt_new0(m_host_t,1);*/
45 INFO1("host = %s", argv[1]);
47 host = MSG_get_host_by_name(argv[1]);
50 INFO1("Unknown host %s. Stopping Now! ", argv[1]);
55 time= MSG_get_clock();
56 sprintf(sprintf_buffer_la, "latency task");
57 task_la = MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL);
58 task_la->data = xbt_new(double, 1);
59 *(double *)task_la->data = time;
60 INFO1("task_la->data = %le", *((double *)task_la->data));
61 MSG_task_put(task_la, host,PORT_22);
65 sprintf(sprintf_buffer_bw, "bandwidth task");
66 task_bw = MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL);
67 task_bw->data = xbt_new(double, 1);
68 *(double *)task_bw->data = time;
69 INFO1("task_bw->data = %le", *((double *)task_bw->data) );
70 MSG_task_put(task_bw, host,PORT_22);
75 /** Receiver function */
76 int receiver(int argc, char *argv[])
78 double time, time1, sender_time;
79 m_task_t task_la = NULL;
80 m_task_t task_bw = NULL;
82 double communication_time=0;
86 time = MSG_get_clock();
89 a = MSG_task_get(&task_la,PORT_22);
91 time1=MSG_get_clock();
92 sender_time= *((double*)(task_la->data));
94 communication_time=time1-time;
95 INFO1("Task received : %s", task_la->name);
96 MSG_task_destroy(task_la);
97 INFO1("Communic. time %le",communication_time);
98 INFO1("--- la %f ----",communication_time);
100 xbt_assert0(0,"Unexpected behavior");
105 a=MSG_task_get(&task_bw,PORT_22);
107 time1=MSG_get_clock();
108 sender_time= *((double*)(task_bw->data));
110 communication_time=time1-time;
111 INFO1("Task received : %s", task_bw->name);
112 MSG_task_destroy(task_bw);
113 INFO1("Communic. time %le",communication_time);
114 INFO1("--- bw %f ----",task_comm_size_bw/communication_time);
116 xbt_assert0(0,"Unexpected behavior");
121 }/* end_of_receiver */
125 MSG_error_t test_all(const char *platform_file,
126 const char *application_file)
129 MSG_error_t res = MSG_OK;
135 /* Simulation setting */
136 MSG_set_channel_number(MAX_CHANNEL);
137 MSG_paje_output("msg_test.trace");
138 MSG_create_environment(platform_file);
140 /* Application deployment */
141 MSG_function_register("sender", sender);
142 MSG_function_register("receiver", receiver);
144 MSG_launch_application(application_file);
149 } /* end_of_test_all */
153 int main(int argc, char *argv[])
155 MSG_error_t res = MSG_OK;
158 unsigned int prev_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT);
161 MSG_global_init(&argc,argv);
165 CRITICAL1 ("Usage: %s platform_file deployment_file <model>\n",argv[0]);
166 CRITICAL1 ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n",argv[0]);
170 /* Options for the workstation_model:
172 KCCFLN05 => for maxmin
173 KCCFLN05_proportional => for proportional (Vegas)
174 KCCFLN05_Vegas => for TCP Vegas
175 KCCFLN05_Reno => for TCP Reno
177 //MSG_config("workstation_model", argv[3]);
179 res = test_all(argv[1],argv[2]);
181 INFO1("Total simulation time: %le", MSG_get_clock());
186 _set_output_format(prev_exponent_format);
189 if(res==MSG_OK) return 0;