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. */
9 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
10 #include "surf/surfxml_parse.h" /* to override surf_parse */
11 #include "surf/surfxml.h" /* to hijack surf_parse_lex */
13 /* Create a log channel to have nice outputs. */
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
16 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
18 static int surf_parse_bypass(void)
21 /* allocating memory to the buffer, I think 2MB should be enough */
22 surfxml_buffer = xbt_new0(char, 2048);
24 /* <platform_description> */
25 strcpy(A_surfxml_platform_description_version, "1");
26 STag_surfxml_platform_description();
29 /* <cpu name="Cpu A" power="100000000.00" availability_file="trace_A.txt"/> */
30 strcpy(A_surfxml_cpu_name,"Cpu A");
31 strcpy(A_surfxml_cpu_power, "100000000.00");
32 strcpy(A_surfxml_cpu_availability, "1.0");
33 strcpy(A_surfxml_cpu_availability_file, "");
34 A_surfxml_cpu_state = A_surfxml_cpu_state_ON;
35 //bypassing the parser file
36 AX_surfxml_cpu_state_file = 0;
37 strcpy(A_surfxml_cpu_interference_send, "1.0");
38 strcpy(A_surfxml_cpu_interference_recv, "1.0");
39 strcpy(A_surfxml_cpu_interference_send_recv, "1.0");
40 strcpy(A_surfxml_cpu_max_outgoing_rate, "-1.0");
45 /* <cpu name="Cpu B" power="100000000.00" availability_file="trace_B.txt"/> */
46 strcpy(A_surfxml_cpu_name, "Cpu B");
47 strcpy(A_surfxml_cpu_power, "100000000.00");
48 strcpy(A_surfxml_cpu_availability, "1.0");
49 strcpy(A_surfxml_cpu_availability_file, "");
50 A_surfxml_cpu_state = A_surfxml_cpu_state_ON;
51 //bypassing the parser file
52 AX_surfxml_cpu_state_file = 0;
53 strcpy(A_surfxml_cpu_interference_send, "1.0");
54 strcpy(A_surfxml_cpu_interference_recv, "1.0");
55 strcpy(A_surfxml_cpu_interference_send_recv, "1.0");
56 strcpy(A_surfxml_cpu_max_outgoing_rate, "-1.0");
61 /* <network_link name="LinkA" bandwidth="10000000.0" latency="0.2"/> */
62 strcpy(A_surfxml_network_link_name, "LinkA");
63 strcpy(A_surfxml_network_link_bandwidth, "10000000.0");
64 AX_surfxml_network_link_bandwidth_file = 0;
65 strcpy(A_surfxml_network_link_latency, "0.2");
66 AX_surfxml_network_link_latency_file = 0;
67 A_surfxml_network_link_state = A_surfxml_network_link_state_ON;
68 AX_surfxml_network_link_state_file = 0;
69 A_surfxml_network_link_sharing_policy = A_surfxml_network_link_sharing_policy_SHARED;
70 STag_surfxml_network_link();
71 ETag_surfxml_network_link();
73 /* <route src="Cpu A" dst="Cpu B"><route_element name="LinkA"/></route> */
74 strcpy(A_surfxml_route_src, "Cpu A");
75 strcpy(A_surfxml_route_dst, "Cpu B");
76 strcpy(A_surfxml_route_impact_on_src, "0.0");
77 strcpy(A_surfxml_route_impact_on_dst, "0.0");
78 strcpy(A_surfxml_route_impact_on_src_with_other_recv, "0.0");
79 strcpy(A_surfxml_route_impact_on_dst_with_other_send, "0.0");
83 strcpy(A_surfxml_route_element_name, "LinkA");
84 STag_surfxml_route_element();
85 ETag_surfxml_route_element();
89 /* <route src="Cpu B" dst="Cpu A"><route_element name="LinkA"/></route> */
90 strcpy(A_surfxml_route_src, "Cpu B");
91 strcpy(A_surfxml_route_dst, "Cpu A");
92 strcpy(A_surfxml_route_impact_on_src, "0.0");
93 strcpy(A_surfxml_route_impact_on_dst, "0.0");
94 strcpy(A_surfxml_route_impact_on_src_with_other_recv, "0.0");
95 strcpy(A_surfxml_route_impact_on_dst_with_other_send, "0.0");
99 strcpy(A_surfxml_route_element_name, "LinkA");
100 STag_surfxml_route_element();
101 ETag_surfxml_route_element();
103 ETag_surfxml_route();
105 /* <process host="Cpu A" function="master"> */
106 strcpy(A_surfxml_process_host, "Cpu A");
107 strcpy(A_surfxml_process_function, "master");
108 strcpy(A_surfxml_process_start_time, "-1.0");
109 strcpy(A_surfxml_process_kill_time, "-1.0");
110 STag_surfxml_process();
112 /* <argument value="20"/> */
113 strcpy(A_surfxml_argument_value, "20");
114 STag_surfxml_argument();
115 ETag_surfxml_argument();
117 /* <argument value="5000000"/> */
118 strcpy(A_surfxml_argument_value, "5000000");
119 STag_surfxml_argument();
120 ETag_surfxml_argument();
122 /* <argument value="100000"/> */
123 strcpy(A_surfxml_argument_value, "100000");
124 STag_surfxml_argument();
125 ETag_surfxml_argument();
127 /* <argument value="Cpu B"/> */
128 strcpy(A_surfxml_argument_value, "Cpu B");
129 STag_surfxml_argument();
130 ETag_surfxml_argument();
133 ETag_surfxml_process();
135 /* <process host="Cpu B" function="slave"/> */
136 strcpy(A_surfxml_process_host, "Cpu B");
137 strcpy(A_surfxml_process_function, "slave");
138 strcpy(A_surfxml_process_start_time, "-1.0");
139 strcpy(A_surfxml_process_kill_time, "-1.0");
140 STag_surfxml_process();
141 ETag_surfxml_process();
143 /* </platform_description> */
144 ETag_surfxml_platform_description();
149 int master(int argc, char *argv[]);
150 int slave(int argc, char *argv[]);
151 MSG_error_t test_all(void);
158 /** Emitter function */
159 int master(int argc, char *argv[])
161 int slaves_count = 0;
162 m_host_t *slaves = NULL;
163 m_task_t *todo = NULL;
164 int number_of_tasks = 0;
165 double task_comp_size = 0;
166 double task_comm_size = 0;
171 xbt_assert1(sscanf(argv[1],"%d", &number_of_tasks),
172 "Invalid argument %s\n",argv[1]);
173 xbt_assert1(sscanf(argv[2],"%lg", &task_comp_size),
174 "Invalid argument %s\n",argv[2]);
175 xbt_assert1(sscanf(argv[3],"%lg", &task_comm_size),
176 "Invalid argument %s\n",argv[3]);
178 { /* Task creation */
179 char sprintf_buffer[64];
181 todo = calloc(number_of_tasks, sizeof(m_task_t));
183 for (i = 0; i < number_of_tasks; i++) {
184 sprintf(sprintf_buffer, "Task_%d", i);
185 todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
189 { /* Process organisation */
190 slaves_count = argc - 4;
191 slaves = calloc(slaves_count, sizeof(m_host_t));
193 for (i = 4; i < argc; i++) {
194 slaves[i-4] = MSG_get_host_by_name(argv[i]);
195 if(slaves[i-4]==NULL) {
196 INFO1("Unknown host %s. Stopping Now! ", argv[i]);
202 INFO1("Got %d slave(s) :", slaves_count);
203 for (i = 0; i < slaves_count; i++)
204 INFO1("\t %s", slaves[i]->name);
206 INFO1("Got %d task to process :", number_of_tasks);
208 for (i = 0; i < number_of_tasks; i++)
209 INFO1("\t\"%s\"", todo[i]->name);
211 for (i = 0; i < number_of_tasks; i++) {
212 INFO2("Sending \"%s\" to \"%s\"",
214 slaves[i % slaves_count]->name);
215 if(MSG_host_self()==slaves[i % slaves_count]) {
216 INFO0("Hey ! It's me ! :)");
218 MSG_task_put(todo[i], slaves[i % slaves_count],
220 INFO0("Send completed");
223 INFO0("All tasks have been dispatched. Let's tell everybody the computation is over.");
224 for (i = 0; i < slaves_count; i++)
225 MSG_task_put(MSG_task_create("finalize", 0, 0, FINALIZE),
228 INFO0("Goodbye now!");
232 } /* end_of_master */
234 /** Receiver function */
235 int slave(int argc, char *argv[])
238 m_task_t task = NULL;
240 a = MSG_task_get(&(task), PORT_22);
242 INFO1("Received \"%s\" ", MSG_task_get_name(task));
243 if(MSG_task_get_data(task)==FINALIZE) {
244 MSG_task_destroy(task);
247 INFO1("Processing \"%s\" ", MSG_task_get_name(task));
248 MSG_task_execute(task);
249 INFO1("\"%s\" done ", MSG_task_get_name(task));
250 MSG_task_destroy(task);
252 INFO0("Hey ?! What's up ? ");
253 xbt_assert0(0,"Unexpected behavior");
256 INFO0("I'm done. See you!");
261 MSG_error_t test_all(void)
263 MSG_error_t res = MSG_OK;
265 { /* Simulation setting */
266 MSG_set_channel_number(MAX_CHANNEL);
267 MSG_paje_output("msg_test.trace");
268 surf_parse = surf_parse_bypass;
269 MSG_create_environment(NULL);
271 { /* Application deployment */
272 MSG_function_register("master", master);
273 MSG_function_register("slave", slave);
274 MSG_launch_application(NULL);
278 INFO1("Simulation time %g",MSG_get_clock());
280 } /* end_of_test_all */
283 int main(int argc, char *argv[])
285 MSG_error_t res = MSG_OK;
287 MSG_global_init(&argc,argv);
291 if(res==MSG_OK) return 0;