Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bypassing the XML parser. Need to fix include directories to make it work.
[simgrid.git] / examples / msg / msg_test_surfxml_bypassed.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved.        */
4
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. */
7
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 */
11
12 /* Create a log channel to have nice outputs. */
13 #include "xbt/log.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
15
16 static int surf_parse_bypass(void)
17 {
18 /* <platform_description> */
19   STag_platform_description();
20
21
22 /*   <cpu name="Cpu A" power="100.00" availability_file="trace_A.txt"/> */
23   A_cpu_name = "Cpu A";
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";
33
34   STag_cpu_fun();
35   ETag_cpu_fun();
36
37 /*   <cpu name="Cpu B" power="100.00" availability_file="trace_B.txt"/> */
38   A_cpu_name = "Cpu B";
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";
48
49   STag_cpu_fun();
50   ETag_cpu_fun();
51
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;
61   STag_network_link();
62   ETag_network_link();
63
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";
71
72   STag_route();
73
74   A_route_element_name = "LinkA";
75   STag_route_element();
76   ETag_route_element();
77
78   ETag_route();
79
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";
87
88   STag_route();
89
90   A_route_element_name = "LinkA";
91   STag_route_element();
92   ETag_route_element();
93
94   ETag_route();
95
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";
101   STag_process();
102
103 /*      <argument value="20"/> */
104   A_argument_value = "20";
105   STag_argument();
106   ETag_argument();
107
108 /*      <argument value="50000"/> */
109   A_argument_value = "50000";
110   STag_argument();
111   ETag_argument();
112
113 /*      <argument value="10"/> */
114   A_argument_value = "10";
115   STag_argument();
116   ETag_argument();
117
118 /*      <argument value="Cpu B"/> */
119   A_argument_value = "Cpu B";
120   STag_argument();
121   ETag_argument();
122
123 /*   </process> */
124   ETag_process();
125
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";
131   STag_process();
132   ETag_process();
133
134 /* </platform_description> */
135   ETag_platform_description();
136
137   return 0;
138 }
139
140 int master(int argc, char *argv[]);
141 int slave(int argc, char *argv[]);
142 void test_all(const char *platform_file, const char *application_file);
143
144 typedef enum {
145   PORT_22 = 0,
146   MAX_CHANNEL
147 } channel_t;
148
149 /* This function is just used so that users can check that each process
150  *  has received the arguments it was supposed to receive.
151  */
152 static void print_args(int argc, char** argv)
153 {
154   int i ; 
155
156   fprintf(stderr,"<");
157   for(i=0; i<argc; i++) 
158     fprintf(stderr,"%s ",argv[i]);
159   fprintf(stderr,">\n");
160 }
161
162 /** Emitter function  */
163 int master(int argc, char *argv[])
164 {
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;
171
172
173   int i;
174
175   print_args(argc,argv);
176
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]);
183
184   {                  /*  Task creation */
185     char sprintf_buffer[64];
186
187     todo = calloc(number_of_tasks, sizeof(m_task_t));
188
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);
192     }
193   }
194
195   {                  /* Process organisation */
196     slaves_count = argc - 4;
197     slaves = calloc(slaves_count, sizeof(m_host_t));
198     
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]);
203         abort();
204       }
205     }
206   }
207
208   INFO1("Got %d slave(s) :", slaves_count);
209   for (i = 0; i < slaves_count; i++)
210     INFO1("\t %s", slaves[i]->name);
211
212   INFO1("Got %d task to process :", number_of_tasks);
213
214   for (i = 0; i < number_of_tasks; i++)
215     INFO1("\t\"%s\"", todo[i]->name);
216
217   for (i = 0; i < number_of_tasks; i++) {
218     INFO2("Sending \"%s\" to \"%s\"",
219                   todo[i]->name,
220                   slaves[i % slaves_count]->name);
221     if(MSG_host_self()==slaves[i % slaves_count]) {
222       INFO0("Hey ! It's me ! :)");
223     }
224     MSG_task_put(todo[i], slaves[i % slaves_count],
225                  PORT_22);
226     INFO0("Send completed");
227   }
228   
229   INFO0("All tasks have been dispatched. Bye!");
230   free(slaves);
231   free(todo);
232   return 0;
233 } /* end_of_master */
234
235 /** Receiver function  */
236 int slave(int argc, char *argv[])
237 {
238   print_args(argc,argv);
239
240   while(1) {
241     m_task_t task = NULL;
242     int a;
243     a = MSG_task_get(&(task), PORT_22);
244     if (a == MSG_OK) {
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);
250     } else {
251       INFO0("Hey ?! What's up ? ");
252       xbt_assert0(0,"Unexpected behaviour");
253     }
254   }
255   INFO0("I'm done. See you!");
256   return 0;
257 } /* end_of_slave */
258
259 /** Test function */
260 void test_all(void)
261 {
262
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);
269   }
270   {                            /*   Application deployment */
271     MSG_function_register("master", master);
272     MSG_function_register("slave", slave);
273     MSG_function_register("forwarder", forwarder);
274     MSG_launch_application(NULL);
275   }
276   MSG_main();
277   
278   INFO1("Simulation time %g",MSG_get_clock());
279 } /* end_of_test_all */
280
281
282 /** Main function */
283 int main(int argc, char *argv[])
284 {
285   MSG_global_init(&argc,argv);
286   test_all();
287   MSG_clean();
288   return (0);
289 } /* end_of_main */
290