Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8306dc20e1d3633d94464d51b798afe3506de06f
[simgrid.git] / examples / msg / actions / actions.c
1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
10 #include "simix/simix.h"        /* semaphores for the barrier */
11 #include "xbt.h"                /* calloc, printf */
12 #include "simgrid_config.h"     /* getline */
13 #include "instr/instr_private.h"
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(actions,
16                              "Messages specific for this msg example");
17 int communicator_size = 0;
18
19 typedef struct coll_ctr_t {
20   int last_Irecv_sender_id;
21   int bcast_counter;
22   int reduce_counter;
23   int allReduce_counter;
24 } *coll_ctr;
25
26 /* Helper function */
27 static double parse_double(const char *string)
28 {
29   double value;
30   char *endptr;
31
32   value = strtod(string, &endptr);
33   if (*endptr != '\0')
34     THROW1(unknown_error, 0, "%s is not a double", string);
35   return value;
36 }
37
38 static int get_rank (const char *process_name)
39 {
40   return atoi(&(process_name[1]));
41
42
43 /* My actions */
44 static int spawned_send(int argc, char *argv[])
45 {
46   DEBUG3("%s: Sending %s on %s", MSG_process_get_name(MSG_process_self()),
47          argv[1], argv[0]);
48   MSG_task_send(MSG_task_create(argv[0], 0, parse_double(argv[1]), NULL),
49                 argv[0]);
50   return 0;
51 }
52
53 static void action_send(xbt_dynar_t action)
54 {
55   char *name = NULL;
56   char to[250];
57   char *size = xbt_dynar_get_as(action, 3, char *);
58   double clock = MSG_get_clock();
59
60   sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()),
61           xbt_dynar_get_as(action, 2, char *));
62   //  char *to =  xbt_dynar_get_as(action, 2, char *);
63
64   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
65     name = xbt_str_join(action, " ");
66
67 #ifdef HAVE_TRACING
68   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
69   int dst_traced = get_rank(xbt_dynar_get_as(action, 2, char *));
70   TRACE_smpi_ptp_in(rank, rank, dst_traced, "send");
71   TRACE_smpi_send(rank, rank, dst_traced);
72 #endif
73
74   DEBUG2("Entering Send: %s (size: %lg)", name, parse_double(size));
75    if (parse_double(size)<65536) {
76      char spawn_name[80];
77      char **myargv;
78      m_process_t comm_helper;
79      DEBUG1("Isend on %s: spawn process ",
80             MSG_process_get_name(MSG_process_self()));
81      myargv = (char **) calloc(3, sizeof(char *));
82      myargv[0] = xbt_strdup(to);
83      myargv[1] = xbt_strdup(size);
84      myargv[2] = NULL;
85      
86      sprintf(spawn_name, "%s_wait", to);
87      comm_helper =
88        MSG_process_create_with_arguments(spawn_name, spawned_send,
89                                          NULL, MSG_host_self(), 2, myargv);
90    }
91    else {
92      MSG_task_send(MSG_task_create(name, 0, parse_double(size), NULL), to);
93    }
94    
95    VERB2("%s %f", name, MSG_get_clock() - clock);
96
97   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
98     free(name);
99
100 #ifdef HAVE_TRACING
101   TRACE_smpi_ptp_out(rank, rank, dst_traced, "send");
102 #endif  
103 }
104
105 static void Isend(xbt_dynar_t action)
106 {
107   char spawn_name[80];
108   char to[250];
109   //  char *to = xbt_dynar_get_as(action, 2, char *);
110   char *size = xbt_dynar_get_as(action, 3, char *);
111   char **myargv;
112   m_process_t comm_helper;
113   double clock = MSG_get_clock();
114   DEBUG1("Isend on %s: spawn process ",
115          MSG_process_get_name(MSG_process_self()));
116
117   sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()),
118           xbt_dynar_get_as(action, 2, char *));
119   myargv = (char **) calloc(3, sizeof(char *));
120
121   myargv[0] = xbt_strdup(to);
122   myargv[1] = xbt_strdup(size);
123   myargv[2] = NULL;
124
125   //    sprintf(spawn_name,"%s_wait",MSG_process_get_name(MSG_process_self()));
126   sprintf(spawn_name, "%s_wait", to);
127   comm_helper =
128       MSG_process_create_with_arguments(spawn_name, spawned_send,
129                                         NULL, MSG_host_self(), 2, myargv);
130   VERB2("%s %f", xbt_str_join(action, " "), MSG_get_clock() - clock);
131 }
132
133
134 static void action_recv(xbt_dynar_t action)
135 {
136   char *name = NULL;
137   char mailbox_name[250];
138   m_task_t task = NULL;
139   double clock = MSG_get_clock();
140   //FIXME: argument of action ignored so far; semantic not clear
141   //char *from=xbt_dynar_get_as(action,2,char*);
142   sprintf(mailbox_name, "%s_%s", xbt_dynar_get_as(action, 2, char *),
143           MSG_process_get_name(MSG_process_self()));
144
145   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
146     name = xbt_str_join(action, " ");
147
148 #ifdef HAVE_TRACING
149   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
150   int src_traced = get_rank(xbt_dynar_get_as(action, 2, char *));
151   TRACE_smpi_ptp_in(rank, src_traced, rank, "recv");
152 #endif
153
154   DEBUG1("Receiving: %s", name);
155   MSG_task_receive(&task, mailbox_name);
156   //  MSG_task_receive(&task, MSG_process_get_name(MSG_process_self()));
157   VERB2("%s %f", name, MSG_get_clock() - clock);
158   MSG_task_destroy(task);
159
160   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
161     free(name);
162 #ifdef HAVE_TRACING
163   TRACE_smpi_ptp_out(rank, src_traced, rank, "recv");
164   TRACE_smpi_recv(rank, src_traced, rank);
165 #endif
166
167 }
168
169 static int spawned_recv(int argc, char *argv[])
170 {
171   m_task_t task = NULL;
172   DEBUG1("Receiving on %s", argv[0]);
173   MSG_task_receive(&task, argv[0]);
174   DEBUG1("Received %s", MSG_task_get_name(task));
175   DEBUG1("waiter on %s", MSG_process_get_name(MSG_process_self()));
176   MSG_task_send(MSG_task_create("waiter", 0, 0, NULL),
177                 MSG_process_get_name(MSG_process_self()));
178
179   MSG_task_destroy(task);
180   return 0;
181 }
182
183
184 static void Irecv(xbt_dynar_t action)
185 {
186   char *name;
187   m_process_t comm_helper;
188   char mailbox_name[250];
189   char **myargv;
190   double clock = MSG_get_clock();
191
192   DEBUG1("Irecv on %s: spawn process ",
193          MSG_process_get_name(MSG_process_self()));
194 #ifdef HAVE_TRACING
195   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
196   int src_traced = get_rank(xbt_dynar_get_as(action, 2, char *));
197   coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self());
198   if (!counters) {
199       DEBUG0("Initialize the counters");
200       counters = (coll_ctr) calloc(1, sizeof(struct coll_ctr_t));
201     }
202   counters->last_Irecv_sender_id = src_traced;
203   MSG_process_set_data(MSG_process_self(), (void *) counters);
204
205   TRACE_smpi_ptp_in(rank, src_traced, rank, "Irecv");
206 #endif
207
208   sprintf(mailbox_name, "%s_%s", xbt_dynar_get_as(action, 2, char *),
209           MSG_process_get_name(MSG_process_self()));
210   name = bprintf("%s_wait", MSG_process_get_name(MSG_process_self()));
211   myargv = (char **) calloc(2, sizeof(char *));
212
213   myargv[0] = xbt_strdup(mailbox_name);
214   myargv[1] = NULL;
215   comm_helper = MSG_process_create_with_arguments(name, spawned_recv,
216                                                   NULL, MSG_host_self(),
217                                                   1, myargv);
218
219   VERB2("%s %f", xbt_str_join(action, " "), MSG_get_clock() - clock);
220
221   free(name);
222 #ifdef HAVE_TRACING
223   TRACE_smpi_ptp_out(rank, src_traced, rank, "Irecv");
224 #endif
225
226 }
227
228
229 static void action_wait(xbt_dynar_t action)
230 {
231   char *name = NULL;
232   char task_name[80];
233   m_task_t task = NULL;
234   double clock = MSG_get_clock();
235
236   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
237     name = xbt_str_join(action, " ");
238 #ifdef HAVE_TRACING
239   coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self());
240   int src_traced = counters->last_Irecv_sender_id;
241   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
242   TRACE_smpi_ptp_in(rank, src_traced, rank, "wait");
243 #endif
244
245   DEBUG1("Entering %s", name);
246   sprintf(task_name, "%s_wait", MSG_process_get_name(MSG_process_self()));
247   DEBUG1("wait: %s", task_name);
248   MSG_task_receive(&task, task_name);
249   MSG_task_destroy(task);
250   VERB2("%s %f", name, MSG_get_clock() - clock);
251   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
252     free(name);
253 #ifdef HAVE_TRACING
254   TRACE_smpi_ptp_out(rank, src_traced, rank, "wait");
255   TRACE_smpi_recv(rank, src_traced, rank);
256 #endif
257
258 }
259
260 /* FIXME: that's a poor man's implementation: we should take the message exchanges into account */
261 static void barrier(xbt_dynar_t action)
262 {
263   char *name = NULL;
264   static smx_mutex_t mutex = NULL;
265   static smx_cond_t cond = NULL;
266   static int processes_arrived_sofar=0;
267
268   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
269     name = xbt_str_join(action, " ");
270
271   if (mutex == NULL) {       // first arriving on the barrier
272     mutex = SIMIX_req_mutex_init();
273     cond = SIMIX_req_cond_init();
274     processes_arrived_sofar=0;
275   }
276   DEBUG2("Entering barrier: %s (%d already there)", name,processes_arrived_sofar);
277
278   SIMIX_req_mutex_lock(mutex);
279   if (++processes_arrived_sofar == communicator_size) {
280     SIMIX_req_cond_broadcast(cond);
281     SIMIX_req_mutex_unlock(mutex);
282   } else {
283     SIMIX_req_cond_wait(cond,mutex);
284     SIMIX_req_mutex_unlock(mutex);
285   }
286
287   DEBUG1("Exiting barrier: %s", name);
288
289   processes_arrived_sofar--;
290   if (!processes_arrived_sofar) {
291     SIMIX_req_cond_destroy(cond);
292     SIMIX_req_mutex_destroy(mutex);
293     mutex=NULL;
294   }
295
296   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
297     free(name);
298
299 }
300
301 static void reduce(xbt_dynar_t action)
302 {
303   int i;
304   char *name;
305   char task_name[80];
306   char spawn_name[80];
307   char **myargv;
308   char *comm_size = xbt_dynar_get_as(action, 2, char *);
309   char *comp_size = xbt_dynar_get_as(action, 3, char *);
310   m_process_t comm_helper = NULL;
311   m_task_t task = NULL, comp_task = NULL;
312   const char *process_name;
313   double clock = MSG_get_clock();
314
315   coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self());
316
317   xbt_assert0(communicator_size, "Size of Communicator is not defined"
318               ", can't use collective operations");
319
320   process_name = MSG_process_get_name(MSG_process_self());
321
322   if (!counters) {
323     DEBUG0("Initialize the counters");
324     counters = (coll_ctr) calloc(1, sizeof(struct coll_ctr_t));
325   }
326
327   name = bprintf("reduce_%d", counters->reduce_counter++);
328
329   if (!strcmp(process_name, "p0")) {
330     DEBUG2("%s: %s is the Root", name, process_name);
331     for (i = 1; i < communicator_size; i++) {
332       sprintf(spawn_name, "%s_p%d_%s", name, i,
333               MSG_process_get_name(MSG_process_self()));
334       sprintf(task_name, "%s_wait", spawn_name);
335       myargv = (char **) calloc(2, sizeof(char *));
336
337       myargv[0] = xbt_strdup(spawn_name);
338       myargv[1] = NULL;
339
340       comm_helper =
341           MSG_process_create_with_arguments(task_name, spawned_recv,
342                                             NULL, MSG_host_self(),
343                                             1, myargv);
344     }
345
346     for (i = 1; i < communicator_size; i++) {
347       sprintf(task_name, "%s_p%d_p0_wait", name, i);
348       MSG_task_receive(&task, task_name);
349       MSG_task_destroy(task);
350       task = NULL;
351     }
352
353     comp_task =
354         MSG_task_create("reduce_comp", parse_double(comp_size), 0, NULL);
355     DEBUG1("%s: computing 'reduce_comp'", name);
356     MSG_task_execute(comp_task);
357     MSG_task_destroy(comp_task);
358     DEBUG1("%s: computed", name);
359   } else {
360     DEBUG2("%s: %s sends", name, process_name);
361     sprintf(task_name, "%s_%s_p0", name, process_name);
362     DEBUG1("put on %s", task_name);
363     MSG_task_send(MSG_task_create(name, 0, parse_double(comm_size), NULL),
364                   task_name);
365   }
366
367   MSG_process_set_data(MSG_process_self(), (void *) counters);
368   VERB2("%s %f", xbt_str_join(action, " "), MSG_get_clock() - clock);
369   free(name);
370 }
371
372 static void bcast(xbt_dynar_t action)
373 {
374   int i;
375   char *name;
376   const char *process_name;
377   char task_name[80];
378   char spawn_name[80];
379   char **myargv;
380   m_process_t comm_helper = NULL;
381   m_task_t task = NULL;
382   char *size = xbt_dynar_get_as(action, 2, char *);
383   coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self());
384   double clock = MSG_get_clock();
385
386   xbt_assert0(communicator_size, "Size of Communicator is not defined"
387               ", can't use collective operations");
388
389
390   process_name = MSG_process_get_name(MSG_process_self());
391   if (!counters) {
392     DEBUG0("Initialize the counters");
393     counters = (coll_ctr) calloc(1, sizeof(struct coll_ctr_t));
394   }
395
396   name = bprintf("bcast_%d", counters->bcast_counter++);
397   if (!strcmp(process_name, "p0")) {
398     DEBUG2("%s: %s is the Root", name, process_name);
399
400     for (i = 1; i < communicator_size; i++) {
401       myargv = (char **) calloc(3, sizeof(char *));
402       myargv[0] = xbt_strdup(name);
403       myargv[1] = xbt_strdup(size);
404       myargv[2] = NULL;
405
406       sprintf(spawn_name, "%s_%d", myargv[0], i);
407       comm_helper =
408           MSG_process_create_with_arguments(spawn_name, spawned_send,
409                                             NULL, MSG_host_self(), 2,
410                                             myargv);
411     }
412
413     for (i = 1; i < communicator_size; i++) {
414       sprintf(task_name, "p%d_wait", i);
415       DEBUG1("get on %s", task_name);
416       MSG_task_receive(&task, task_name);
417       MSG_task_destroy(task);
418       task = NULL;
419     }
420     DEBUG2("%s: all messages sent by %s have been received",
421            name, process_name);
422   } else {
423     DEBUG2("%s: %s receives", name, process_name);
424     MSG_task_receive(&task, name);
425     MSG_task_destroy(task);
426     DEBUG2("%s: %s has received", name, process_name);
427     sprintf(task_name, "%s_wait", process_name);
428     DEBUG1("put on %s", task_name);
429     MSG_task_send(MSG_task_create("waiter", 0, 0, NULL), task_name);
430   }
431
432   MSG_process_set_data(MSG_process_self(), (void *) counters);
433   VERB2("%s %f", xbt_str_join(action, " "), MSG_get_clock() - clock);
434   free(name);
435 }
436
437
438 static void action_sleep(xbt_dynar_t action)
439 {
440   char *name = NULL;
441   char *duration = xbt_dynar_get_as(action, 2, char *);
442   double clock = MSG_get_clock();
443
444   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
445     name = xbt_str_join(action, " ");
446
447   DEBUG1("Entering %s", name);
448   MSG_process_sleep(parse_double(duration));
449   VERB2("%s %f ", name, MSG_get_clock() - clock);
450
451   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
452     free(name);
453 }
454
455 static void allReduce(xbt_dynar_t action)
456 {
457   int i;
458   char *name;
459   char task_name[80];
460   char spawn_name[80];
461   char **myargv;
462   char *comm_size = xbt_dynar_get_as(action, 2, char *);
463   char *comp_size = xbt_dynar_get_as(action, 3, char *);
464   m_process_t comm_helper = NULL;
465   m_task_t task = NULL, comp_task = NULL;
466   const char *process_name;
467   double clock = MSG_get_clock();
468
469   coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self());
470
471   xbt_assert0(communicator_size, "Size of Communicator is not defined"
472               ", can't use collective operations");
473
474   process_name = MSG_process_get_name(MSG_process_self());
475
476   if (!counters) {
477     DEBUG0("Initialize the counters");
478     counters = (coll_ctr) calloc(1, sizeof(struct coll_ctr_t));
479   }
480
481   name = bprintf("allReduce_%d", counters->allReduce_counter++);
482
483   if (!strcmp(process_name, "p0")) {
484     DEBUG2("%s: %s is the Root", name, process_name);
485     for (i = 1; i < communicator_size; i++) {
486       sprintf(spawn_name, "%s_p%d_%s", name, i,
487               MSG_process_get_name(MSG_process_self()));
488       sprintf(task_name, "%s_wait", spawn_name);
489       myargv = (char **) calloc(2, sizeof(char *));
490
491       myargv[0] = xbt_strdup(spawn_name);
492       myargv[1] = NULL;
493
494       comm_helper =
495           MSG_process_create_with_arguments(task_name, spawned_recv,
496                                             NULL, MSG_host_self(),
497                                             1, myargv);
498     }
499
500     for (i = 1; i < communicator_size; i++) {
501       sprintf(task_name, "%s_p%d_p0_wait", name, i);
502       MSG_task_receive(&task, task_name);
503       MSG_task_destroy(task);
504       task = NULL;
505     }
506
507     comp_task =
508         MSG_task_create("allReduce_comp", parse_double(comp_size), 0,
509                         NULL);
510     DEBUG1("%s: computing 'reduce_comp'", name);
511     MSG_task_execute(comp_task);
512     MSG_task_destroy(comp_task);
513     DEBUG1("%s: computed", name);
514
515     for (i = 1; i < communicator_size; i++) {
516       myargv = (char **) calloc(3, sizeof(char *));
517       myargv[0] = xbt_strdup(name);
518       myargv[1] = xbt_strdup(comm_size);
519       myargv[2] = NULL;
520
521       sprintf(spawn_name, "%s_%d", myargv[0], i);
522       comm_helper =
523           MSG_process_create_with_arguments(spawn_name, spawned_send,
524                                             NULL, MSG_host_self(), 2,
525                                             myargv);
526     }
527
528     for (i = 1; i < communicator_size; i++) {
529       sprintf(task_name, "p%d_wait", i);
530       DEBUG1("get on %s", task_name);
531       MSG_task_receive(&task, task_name);
532       MSG_task_destroy(task);
533       task = NULL;
534     }
535     DEBUG2("%s: all messages sent by %s have been received",
536            name, process_name);
537
538   } else {
539     DEBUG2("%s: %s sends", name, process_name);
540     sprintf(task_name, "%s_%s_p0", name, process_name);
541     DEBUG1("put on %s", task_name);
542     MSG_task_send(MSG_task_create(name, 0, parse_double(comm_size), NULL),
543                   task_name);
544
545     MSG_task_receive(&task, name);
546     MSG_task_destroy(task);
547     DEBUG2("%s: %s has received", name, process_name);
548     sprintf(task_name, "%s_wait", process_name);
549     DEBUG1("put on %s", task_name);
550     MSG_task_send(MSG_task_create("waiter", 0, 0, NULL), task_name);
551
552   }
553
554   MSG_process_set_data(MSG_process_self(), (void *) counters);
555   VERB2("%s %f", xbt_str_join(action, " "), MSG_get_clock() - clock);
556   free(name);
557 }
558
559 static void comm_size(xbt_dynar_t action)
560 {
561   char *name = NULL;
562   char *size = xbt_dynar_get_as(action, 2, char *);
563   double clock = MSG_get_clock();
564
565   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
566     name = xbt_str_join(action, " ");
567   communicator_size = parse_double(size);
568   VERB2("%s %f", name, MSG_get_clock() - clock);
569   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
570     free(name);
571 }
572
573 static void compute(xbt_dynar_t action)
574 {
575   char *name = NULL;
576   char *amout = xbt_dynar_get_as(action, 2, char *);
577   m_task_t task = MSG_task_create(name, parse_double(amout), 0, NULL);
578   double clock = MSG_get_clock();
579
580   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
581     name = xbt_str_join(action, " ");
582   DEBUG1("Entering %s", name);
583   MSG_task_execute(task);
584   MSG_task_destroy(task);
585   VERB2("%s %f", name, MSG_get_clock() - clock);
586   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
587     free(name);
588 }
589
590 static void init(xbt_dynar_t action)
591
592 #ifdef HAVE_TRACING
593   TRACE_smpi_init(get_rank(MSG_process_get_name(MSG_process_self())));
594 #endif
595 }
596
597 static void finalize(xbt_dynar_t action)
598 {
599 #ifdef HAVE_TRACING
600   TRACE_smpi_finalize(get_rank(MSG_process_get_name(MSG_process_self())));
601 #endif
602   coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self());
603   if (counters)
604           free(counters);
605 }
606
607 /** Main function */
608 int main(int argc, char *argv[])
609 {
610   MSG_error_t res = MSG_OK;
611
612   /* Check the given arguments */
613   MSG_global_init(&argc, argv);
614   if (argc < 3) {
615     printf("Usage: %s platform_file deployment_file [action_files]\n",
616            argv[0]);
617     printf
618         ("example: %s msg_platform.xml msg_deployment.xml actions # if all actions are in the same file\n",
619          argv[0]);
620     printf
621         ("example: %s msg_platform.xml msg_deployment.xml # if actions are in separate files, specified in deployment\n",
622          argv[0]);
623     exit(1);
624   }
625
626   /*  Simulation setting */
627   MSG_create_environment(argv[1]);
628
629   /* No need to register functions as in classical MSG programs: the actions get started anyway */
630   MSG_launch_application(argv[2]);
631
632   /*   Action registration */
633   MSG_action_register("init", init);
634   MSG_action_register("finalize", finalize);
635   MSG_action_register("comm_size", comm_size);
636   MSG_action_register("send", action_send);
637   MSG_action_register("Isend", Isend);
638   MSG_action_register("recv", action_recv);
639   MSG_action_register("Irecv", Irecv);
640   MSG_action_register("wait", action_wait);
641   MSG_action_register("barrier", barrier);
642   MSG_action_register("bcast", bcast);
643   MSG_action_register("reduce", reduce);
644   MSG_action_register("allReduce", allReduce);
645   MSG_action_register("sleep", action_sleep);
646   MSG_action_register("compute", compute);
647
648
649   /* Actually do the simulation using MSG_action_trace_run */
650   res = MSG_action_trace_run(argv[3]);  // it's ok to pass a NULL argument here
651
652   INFO1("Simulation time %g", MSG_get_clock());
653   MSG_clean();
654
655   if (res == MSG_OK)
656     return 0;
657   else
658     return 1;
659 }                               /* end_of_main */