3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * 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 "surf/surf_parse.h" /* to override surf_parse */
10 #include "surf/surfxml.h" /* to hijack surf_parse_lex */
12 /* Create a log channel to have nice outputs. */
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
16 static int surf_parse_bypass(void)
18 /* <platform_description> */
19 STag_platform_description();
22 /* <cpu name="Cpu A" power="100.00" availability_file="trace_A.txt"/> */
24 A_cpu_power= "100.00";
25 A_cpu_availability = "1.0";
26 A_cpu_availability_file = "trace_A.txt";
27 A_cpu_state = A_cpu_state_ON;
28 A_cpu_state_file = NULL;
29 A_cpu_interference_send = "1.0";
30 A_cpu_interference_recv = "1.0";
31 A_cpu_interference_send_recv = "1.0";
32 A_cpu_max_outgoing_rate = "-1.0";
37 /* <cpu name="Cpu B" power="100.00" availability_file="trace_B.txt"/> */
39 A_cpu_power= "100.00";
40 A_cpu_availability = "1.0";
41 A_cpu_availability_file = "trace_B.txt";
42 A_cpu_state = A_cpu_state_ON;
43 A_cpu_state_file = NULL;
44 A_cpu_interference_send = "1.0";
45 A_cpu_interference_recv = "1.0";
46 A_cpu_interference_send_recv = "1.0";
47 A_cpu_max_outgoing_rate = "-1.0";
52 /* <network_link name="LinkA" bandwidth="10.0" latency="0.2"/> */
53 A_network_link_name = "LinkA";
54 A_network_link_bandwidth = "10.0";
55 A_network_link_bandwidth_file = NULL;
56 A_network_link_latency = "0.2";
57 A_network_link_latency_file = NULL;
58 A_network_link_state = A_network_link_state_ON;
59 A_network_link_state_file = NULL;
60 A_network_link_sharing_policy = A_network_link_sharing_policy_SHARED;
64 /* <route src="Cpu A" dst="Cpu B"><route_element name="LinkA"/></route> */
65 A_route_src = "Cpu A";
66 A_route_dst = "Cpu B";
67 A_route_impact_on_src = "0.0";
68 A_route_impact_on_dst = "0.0";
69 A_route_impact_on_src_with_other_recv = "0.0";
70 A_route_impact_on_dst_with_other_send = "0.0";
74 A_route_element_name = "LinkA";
80 /* <route src="Cpu B" dst="Cpu A"><route_element name="LinkA"/></route> */
81 A_route_src = "Cpu B";
82 A_route_dst = "Cpu A";
83 A_route_impact_on_src = "0.0";
84 A_route_impact_on_dst = "0.0";
85 A_route_impact_on_src_with_other_recv = "0.0";
86 A_route_impact_on_dst_with_other_send = "0.0";
90 A_route_element_name = "LinkA";
96 /* <process host="Cpu A" function="master"> */
97 A_process_host = "Cpu A";
98 A_process_function = "master";
99 A_process_start_time = "-1.0";
100 A_process_kill_time = "-1.0";
103 /* <argument value="20"/> */
104 A_argument_value = "20";
108 /* <argument value="50000"/> */
109 A_argument_value = "50000";
113 /* <argument value="10"/> */
114 A_argument_value = "10";
118 /* <argument value="Cpu B"/> */
119 A_argument_value = "Cpu B";
126 /* <process host="Cpu B" function="slave"/> */
127 A_process_host = "Cpu B";
128 A_process_function = "slave";
129 A_process_start_time = "-1.0";
130 A_process_kill_time = "-1.0";
134 /* </platform_description> */
135 ETag_platform_description();
140 int master(int argc, char *argv[]);
141 int slave(int argc, char *argv[]);
149 /* This function is just used so that users can check that each process
150 * has received the arguments it was supposed to receive.
152 static void print_args(int argc, char** argv)
157 for(i=0; i<argc; i++)
158 fprintf(stderr,"%s ",argv[i]);
159 fprintf(stderr,">\n");
162 /** Emitter function */
163 int master(int argc, char *argv[])
165 int slaves_count = 0;
166 m_host_t *slaves = NULL;
167 m_task_t *todo = NULL;
168 int number_of_tasks = 0;
169 double task_comp_size = 0;
170 double task_comm_size = 0;
175 print_args(argc,argv);
177 xbt_assert1(sscanf(argv[1],"%d", &number_of_tasks),
178 "Invalid argument %s\n",argv[1]);
179 xbt_assert1(sscanf(argv[2],"%lg", &task_comp_size),
180 "Invalid argument %s\n",argv[2]);
181 xbt_assert1(sscanf(argv[3],"%lg", &task_comm_size),
182 "Invalid argument %s\n",argv[3]);
184 { /* Task creation */
185 char sprintf_buffer[64];
187 todo = calloc(number_of_tasks, sizeof(m_task_t));
189 for (i = 0; i < number_of_tasks; i++) {
190 sprintf(sprintf_buffer, "Task_%d", i);
191 todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
195 { /* Process organisation */
196 slaves_count = argc - 4;
197 slaves = calloc(slaves_count, sizeof(m_host_t));
199 for (i = 4; i < argc; i++) {
200 slaves[i-4] = MSG_get_host_by_name(argv[i]);
201 if(slaves[i-4]==NULL) {
202 INFO1("Unknown host %s. Stopping Now! ", argv[i]);
208 INFO1("Got %d slave(s) :", slaves_count);
209 for (i = 0; i < slaves_count; i++)
210 INFO1("\t %s", slaves[i]->name);
212 INFO1("Got %d task to process :", number_of_tasks);
214 for (i = 0; i < number_of_tasks; i++)
215 INFO1("\t\"%s\"", todo[i]->name);
217 for (i = 0; i < number_of_tasks; i++) {
218 INFO2("Sending \"%s\" to \"%s\"",
220 slaves[i % slaves_count]->name);
221 if(MSG_host_self()==slaves[i % slaves_count]) {
222 INFO0("Hey ! It's me ! :)");
224 MSG_task_put(todo[i], slaves[i % slaves_count],
226 INFO0("Send completed");
229 INFO0("All tasks have been dispatched. Bye!");
233 } /* end_of_master */
235 /** Receiver function */
236 int slave(int argc, char *argv[])
238 print_args(argc,argv);
241 m_task_t task = NULL;
243 a = MSG_task_get(&(task), PORT_22);
245 INFO1("Received \"%s\" ", task->name);
246 INFO1("Processing \"%s\" ", task->name);
247 MSG_task_execute(task);
248 INFO1("\"%s\" done ", task->name);
249 MSG_task_destroy(task);
251 INFO0("Hey ?! What's up ? ");
252 xbt_assert0(0,"Unexpected behaviour");
255 INFO0("I'm done. See you!");
263 /* MSG_config("surf_workstation_model","KCCFLN05"); */
264 { /* Simulation setting */
265 MSG_set_channel_number(MAX_CHANNEL);
266 MSG_paje_output("msg_test.trace");
267 surf_parse = surf_parse_bypass;
268 MSG_create_environment(NULL);
270 { /* Application deployment */
271 MSG_function_register("master", master);
272 MSG_function_register("slave", slave);
273 MSG_launch_application(NULL);
277 INFO1("Simulation time %g",MSG_get_clock());
278 } /* end_of_test_all */
282 int main(int argc, char *argv[])
284 MSG_global_init(&argc,argv);