Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove usage of xbt_assert[0-9].
[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 "msg/mailbox.h"        /* we play funny tricks with mailboxes and rdv points */
11 #include "simix/simix.h"        /* semaphores for the barrier */
12 #include "xbt.h"                /* calloc, printf */
13 #include "instr/instr_private.h"
14
15 #include "msg/private.h" /* You don't want to know why, trust us */
16 #include "simix/private.h"
17
18 void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory);
19
20 XBT_LOG_NEW_DEFAULT_CATEGORY(actions,
21                              "Messages specific for this msg example");
22 int communicator_size = 0;
23
24 static void action_Isend(const char *const *action);
25
26 typedef struct  {
27   int last_Irecv_sender_id;
28   int bcast_counter;
29   int reduce_counter;
30   int allReduce_counter;
31   xbt_dynar_t isends; /* of msg_comm_t */
32   /* Used to implement irecv+wait */
33   xbt_dynar_t irecvs; /* of msg_comm_t */
34   xbt_dynar_t tasks; /* of m_task_t */
35 } s_process_globals_t, *process_globals_t;
36
37 /* Helper function */
38 static double parse_double(const char *string)
39 {
40   double value;
41   char *endptr;
42
43   value = strtod(string, &endptr);
44   if (*endptr != '\0')
45     THROWF(unknown_error, 0, "%s is not a double", string);
46   return value;
47 }
48
49 static int get_rank (const char *process_name)
50 {
51   return atoi(&(process_name[1]));
52
53
54 static void asynchronous_cleanup(void) {
55   process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
56
57   /* Destroy any isend which correspond to completed communications */
58   int found;
59   msg_comm_t comm;
60   while ((found = MSG_comm_testany(globals->isends)) != -1) {
61     xbt_dynar_remove_at(globals->isends,found,&comm);
62     MSG_comm_destroy(comm);
63   }
64 }
65
66 /* My actions */
67 static void action_send(const char *const *action)
68 {
69   char *name = NULL;
70   char to[250];
71   const char *size_str = action[3];
72   double size=parse_double(size_str);
73   double clock = MSG_get_clock(); /* this "call" is free thanks to inlining */
74
75   sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()),action[2]);
76
77   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
78     name = xbt_str_join_array(action, " ");
79
80 #ifdef HAVE_TRACING
81   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
82   int dst_traced = get_rank(action[2]);
83   TRACE_smpi_ptp_in(rank, rank, dst_traced, "send");
84   TRACE_smpi_send(rank, rank, dst_traced);
85 #endif
86
87   XBT_DEBUG("Entering Send: %s (size: %lg)", name, size);
88    if (size<65536) {
89      action_Isend(action);
90    } else {
91      MSG_task_send(MSG_task_create(name, 0, size, NULL), to);
92    }
93    
94    XBT_VERB("%s %f", name, MSG_get_clock() - clock);
95
96   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
97     free(name);
98
99 #ifdef HAVE_TRACING
100   TRACE_smpi_ptp_out(rank, rank, dst_traced, "send");
101 #endif
102
103   asynchronous_cleanup();
104 }
105
106 static int task_recv_matching(void*ignored,void*recv_task) {
107   XBT_DEBUG("Trying to recv_match with %p", recv_task);
108   return recv_task != NULL;
109 }
110
111 static void action_Isend(const char *const *action)
112 {
113   char to[250];
114   const char *size = action[3];
115   double clock = MSG_get_clock();
116   process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
117
118
119   sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()),action[2]);
120   m_task_t task = MSG_task_create(to,0,parse_double(size),NULL);
121
122   smx_rdv_t rdv = MSG_mailbox_get_by_alias(to);
123
124   if(SIMIX_comm_has_recv_match(rdv, task_recv_matching, NULL)) {
125     XBT_DEBUG("Switching back to MSG_task_send: %s", to);
126     MSG_task_send(task, to);
127   } else {
128
129     msg_comm_t comm = MSG_task_isend_with_matching(task, to, /*matching madness*/NULL,task);
130     xbt_dynar_push(globals->isends,&comm);
131
132     if (task->simdata->message_size < 65536) {
133       /* Close your eyes, it burns ! */
134       comm->s_comm->comm.dst_proc = SIMIX_process_get_by_name(action[2]);
135       comm->s_comm->comm.dst_buff = NULL;
136       comm->s_comm->comm.dst_buff_size = NULL;
137       comm->s_comm->comm.dst_data = NULL;
138       comm->s_comm->state = SIMIX_READY;
139       comm->s_comm->comm.refcount++;
140       SIMIX_comm_start(comm->s_comm);
141     }
142
143     XBT_DEBUG("Isend on %s", MSG_process_get_name(MSG_process_self()));
144     XBT_VERB("%s %f", xbt_str_join_array(action, " "), MSG_get_clock() - clock);
145   }
146
147   asynchronous_cleanup();
148 }
149
150 static int task_sent_matching(void*ignored,void*sent_task) {
151   m_task_t t = (m_task_t)sent_task;
152   if (t!=NULL && MSG_task_get_data_size(t)<65536)
153     return 1; /* that's supposed to be already arrived */
154   return 0; /* rendez-vous mode: it's not there yet */
155 }
156
157 static void action_recv(const char *const *action)
158 {
159   char *name = NULL;
160   char mailbox_name[250];
161   m_task_t task = NULL;
162   double clock = MSG_get_clock();
163
164   sprintf(mailbox_name, "%s_%s", action[2],
165           MSG_process_get_name(MSG_process_self()));
166
167   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
168     name = xbt_str_join_array(action, " ");
169
170   /* The next chunk is to deal with the fact that for short messages,
171    * if the send occurs before the receive, the message is already sent and
172    * buffered on receiver side when the recv() occurs.
173    *
174    * So the next chunk detects this fact and cancel the simix communication instead.
175    */
176
177   /* make sure the rdv is created on need by asking to MSG instead of simix directly */
178   smx_rdv_t rdv = MSG_mailbox_get_by_alias(mailbox_name);
179   smx_action_t act = SIMIX_comm_get_send_match(rdv, task_sent_matching, NULL);
180   if (act!=NULL){
181     /* FIXME account for the memcopy time if needed */
182     task = act->comm.src_data;
183
184     if (task->simdata->message_size < 65536) {
185       act->comm.refcount--; /* See action_send for more pain */
186       if(act->state == SIMIX_DONE)
187         SIMIX_comm_finish(act);
188       else
189         SIMIX_req_comm_wait(act, -1.0);
190       return;
191     }
192   }
193
194 #ifdef HAVE_TRACING
195   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
196   int src_traced = get_rank(action[2]);
197   TRACE_smpi_ptp_in(rank, src_traced, rank, "recv");
198 #endif
199
200   XBT_DEBUG("Receiving: %s", name);
201   /* Mimic a call to MSG_task_receive(&task, mailbox_name); */
202   SIMIX_req_comm_recv(rdv, &task, NULL, NULL, &task, -1.0);
203
204   //  MSG_task_receive(&task, MSG_process_get_name(MSG_process_self()));
205   XBT_VERB("%s %f", name, MSG_get_clock() - clock);
206   MSG_task_destroy(task);
207
208   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
209     free(name);
210 #ifdef HAVE_TRACING
211   TRACE_smpi_ptp_out(rank, src_traced, rank, "recv");
212   TRACE_smpi_recv(rank, src_traced, rank);
213 #endif
214
215   asynchronous_cleanup();
216 }
217
218 static void action_Irecv(const char *const *action)
219 {
220   char mailbox[250];
221   double clock = MSG_get_clock();
222   process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
223
224   XBT_DEBUG("Irecv on %s", MSG_process_get_name(MSG_process_self()));
225 #ifdef HAVE_TRACING
226   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
227   int src_traced = get_rank(action[2]);
228   globals->last_Irecv_sender_id = src_traced;
229   MSG_process_set_data(MSG_process_self(), (void *) globals);
230
231   TRACE_smpi_ptp_in(rank, src_traced, rank, "Irecv");
232 #endif
233
234   sprintf(mailbox, "%s_%s", action[2],
235           MSG_process_get_name(MSG_process_self()));
236   m_task_t t=NULL;
237   xbt_dynar_push(globals->tasks,&t);
238   msg_comm_t c =
239       MSG_task_irecv(
240           xbt_dynar_get_ptr(globals->tasks, xbt_dynar_length(globals->tasks)-1),
241           mailbox);
242   xbt_dynar_push(globals->irecvs,&c);
243
244   XBT_VERB("%s %f", xbt_str_join_array(action, " "), MSG_get_clock() - clock);
245
246 #ifdef HAVE_TRACING
247   TRACE_smpi_ptp_out(rank, src_traced, rank, "Irecv");
248 #endif
249
250   asynchronous_cleanup();
251 }
252
253
254 static void action_wait(const char *const *action)
255 {
256   char *name = NULL;
257   m_task_t task = NULL;
258   msg_comm_t comm;
259   double clock = MSG_get_clock();
260   process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
261
262   xbt_assert(xbt_dynar_length(globals->irecvs),
263       "action wait not preceded by any irecv: %s", xbt_str_join_array(action," "));
264
265   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
266     name = xbt_str_join_array(action, " ");
267 #ifdef HAVE_TRACING
268   process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self());
269   int src_traced = counters->last_Irecv_sender_id;
270   int rank = get_rank(MSG_process_get_name(MSG_process_self()));
271   TRACE_smpi_ptp_in(rank, src_traced, rank, "wait");
272 #endif
273
274   XBT_DEBUG("Entering %s", name);
275   comm = xbt_dynar_pop_as(globals->irecvs,msg_comm_t);
276   MSG_comm_wait(comm,-1);
277   task = xbt_dynar_pop_as(globals->tasks,m_task_t);
278   MSG_comm_destroy(comm);
279   MSG_task_destroy(task);
280
281   XBT_VERB("%s %f", name, MSG_get_clock() - clock);
282   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
283     free(name);
284 #ifdef HAVE_TRACING
285   TRACE_smpi_ptp_out(rank, src_traced, rank, "wait");
286   TRACE_smpi_recv(rank, src_traced, rank);
287 #endif
288
289 }
290
291 /* FIXME: that's a poor man's implementation: we should take the message exchanges into account */
292 static void action_barrier(const char *const *action)
293 {
294   char *name = NULL;
295   static smx_mutex_t mutex = NULL;
296   static smx_cond_t cond = NULL;
297   static int processes_arrived_sofar=0;
298
299   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
300     name = xbt_str_join_array(action, " ");
301
302   if (mutex == NULL) {       // first arriving on the barrier
303     mutex = SIMIX_req_mutex_init();
304     cond = SIMIX_req_cond_init();
305     processes_arrived_sofar=0;
306   }
307   XBT_DEBUG("Entering barrier: %s (%d already there)", name,processes_arrived_sofar);
308
309   SIMIX_req_mutex_lock(mutex);
310   if (++processes_arrived_sofar == communicator_size) {
311     SIMIX_req_cond_broadcast(cond);
312     SIMIX_req_mutex_unlock(mutex);
313   } else {
314     SIMIX_req_cond_wait(cond,mutex);
315     SIMIX_req_mutex_unlock(mutex);
316   }
317
318   XBT_DEBUG("Exiting barrier: %s", name);
319
320   processes_arrived_sofar--;
321   if (!processes_arrived_sofar) {
322     SIMIX_req_cond_destroy(cond);
323     SIMIX_req_mutex_destroy(mutex);
324     mutex=NULL;
325   }
326
327   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
328     free(name);
329
330 }
331
332 static void action_reduce(const char *const *action)
333 {
334         int i;
335         char *reduce_identifier;
336         char mailbox[80];
337         double comm_size = parse_double(action[2]);
338         double comp_size = parse_double(action[3]);
339         m_task_t comp_task = NULL;
340         const char *process_name;
341         double clock = MSG_get_clock();
342
343         process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self());
344
345         xbt_assert(communicator_size, "Size of Communicator is not defined, "
346                         "can't use collective operations");
347
348         process_name = MSG_process_get_name(MSG_process_self());
349
350         reduce_identifier = bprintf("reduce_%d", counters->reduce_counter++);
351
352         if (!strcmp(process_name, "p0")) {
353                 XBT_DEBUG("%s: %s is the Root", reduce_identifier, process_name);
354
355                 msg_comm_t *comms = xbt_new0(msg_comm_t,communicator_size-1);
356             m_task_t *tasks = xbt_new0(m_task_t,communicator_size-1);
357             for (i = 1; i < communicator_size; i++) {
358               sprintf(mailbox, "%s_p%d_p0", reduce_identifier, i);
359               comms[i-1] = MSG_task_irecv(&(tasks[i-1]),mailbox);
360             }
361             MSG_comm_waitall(comms,communicator_size-1,-1);
362             for (i = 1; i < communicator_size; i++) {
363                 MSG_comm_destroy(comms[i-1]);
364                 MSG_task_destroy(tasks[i-1]);
365             }
366             free(tasks);
367
368             comp_task = MSG_task_create("reduce_comp", comp_size, 0, NULL);
369             XBT_DEBUG("%s: computing 'reduce_comp'", reduce_identifier);
370             MSG_task_execute(comp_task);
371             MSG_task_destroy(comp_task);
372             XBT_DEBUG("%s: computed", reduce_identifier);
373
374         } else {
375                 XBT_DEBUG("%s: %s sends", reduce_identifier, process_name);
376                 sprintf(mailbox, "%s_%s_p0", reduce_identifier, process_name);
377             XBT_DEBUG("put on %s", mailbox);
378             MSG_task_send(MSG_task_create(reduce_identifier, 0, comm_size, NULL),
379                           mailbox);
380         }
381
382         XBT_VERB("%s %f", xbt_str_join_array(action, " "), MSG_get_clock() - clock);
383         free(reduce_identifier);
384 }
385
386 static void action_bcast(const char *const *action)
387 {
388         int i;
389         char *bcast_identifier;
390         char mailbox[80];
391         double comm_size = parse_double(action[2]);
392         m_task_t task = NULL;
393         const char *process_name;
394         double clock = MSG_get_clock();
395
396         process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self());
397
398         xbt_assert(communicator_size, "Size of Communicator is not defined, "
399                         "can't use collective operations");
400
401         process_name = MSG_process_get_name(MSG_process_self());
402
403         bcast_identifier = bprintf("bcast_%d", counters->bcast_counter++);
404
405         if (!strcmp(process_name, "p0")) {
406                 XBT_DEBUG("%s: %s is the Root", bcast_identifier, process_name);
407
408             msg_comm_t *comms = xbt_new0(msg_comm_t,communicator_size-1);
409
410             for (i = 1; i < communicator_size; i++) {
411               sprintf(mailbox, "%s_p0_p%d", bcast_identifier, i);
412               comms[i-1] =
413                   MSG_task_isend(MSG_task_create(mailbox,0,comm_size,NULL),
414                       mailbox);
415             }
416             MSG_comm_waitall(comms,communicator_size-1,-1);
417                 for (i = 1; i < communicator_size; i++)
418                MSG_comm_destroy(comms[i-1]);
419             free(comms);
420
421             XBT_DEBUG("%s: all messages sent by %s have been received",
422                    bcast_identifier, process_name);
423
424         } else {
425             sprintf(mailbox, "%s_p0_%s", bcast_identifier, process_name);
426             MSG_task_receive(&task, mailbox);
427             MSG_task_destroy(task);
428             XBT_DEBUG("%s: %s has received", bcast_identifier, process_name);
429         }
430
431         XBT_VERB("%s %f", xbt_str_join_array(action, " "), MSG_get_clock() - clock);
432         free(bcast_identifier);
433 }
434
435
436 static void action_sleep(const char *const *action)
437 {
438   char *name = NULL;
439   const char *duration = action[2];
440   double clock = MSG_get_clock();
441
442   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
443     name = xbt_str_join_array(action, " ");
444
445   XBT_DEBUG("Entering %s", name);
446   MSG_process_sleep(parse_double(duration));
447   XBT_VERB("%s %f ", name, MSG_get_clock() - clock);
448
449   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
450     free(name);
451 }
452
453 static void action_allReduce(const char *const *action) {
454   int i;
455   char *allreduce_identifier;
456   char mailbox[80];
457   double comm_size = parse_double(action[2]);
458   double comp_size = parse_double(action[3]);
459   m_task_t task = NULL, comp_task = NULL;
460   const char *process_name;
461   double clock = MSG_get_clock();
462
463   process_globals_t counters = (process_globals_t) MSG_process_get_data(MSG_process_self());
464
465   xbt_assert(communicator_size, "Size of Communicator is not defined, "
466               "can't use collective operations");
467
468   process_name = MSG_process_get_name(MSG_process_self());
469
470   allreduce_identifier = bprintf("allReduce_%d", counters->allReduce_counter++);
471
472   if (!strcmp(process_name, "p0")) {
473     XBT_DEBUG("%s: %s is the Root", allreduce_identifier, process_name);
474
475     msg_comm_t *comms = xbt_new0(msg_comm_t,communicator_size-1);
476     m_task_t *tasks = xbt_new0(m_task_t,communicator_size-1);
477     for (i = 1; i < communicator_size; i++) {
478       sprintf(mailbox, "%s_p%d_p0", allreduce_identifier, i);
479       comms[i-1] = MSG_task_irecv(&(tasks[i-1]),mailbox);
480     }
481     MSG_comm_waitall(comms,communicator_size-1,-1);
482     for (i = 1; i < communicator_size; i++) {
483       MSG_comm_destroy(comms[i-1]);
484       MSG_task_destroy(tasks[i-1]);
485     }
486     free(tasks);
487
488     comp_task = MSG_task_create("allReduce_comp", comp_size, 0, NULL);
489     XBT_DEBUG("%s: computing 'reduce_comp'", allreduce_identifier);
490     MSG_task_execute(comp_task);
491     MSG_task_destroy(comp_task);
492     XBT_DEBUG("%s: computed", allreduce_identifier);
493
494     for (i = 1; i < communicator_size; i++) {
495       sprintf(mailbox, "%s_p0_p%d", allreduce_identifier, i);
496       comms[i-1] =
497           MSG_task_isend(MSG_task_create(mailbox,0,comm_size,NULL),
498               mailbox);
499     }
500     MSG_comm_waitall(comms,communicator_size-1,-1);
501     for (i = 1; i < communicator_size; i++)
502        MSG_comm_destroy(comms[i-1]);
503     free(comms);
504
505     XBT_DEBUG("%s: all messages sent by %s have been received",
506            allreduce_identifier, process_name);
507
508   } else {
509     XBT_DEBUG("%s: %s sends", allreduce_identifier, process_name);
510     sprintf(mailbox, "%s_%s_p0", allreduce_identifier, process_name);
511     XBT_DEBUG("put on %s", mailbox);
512     MSG_task_send(MSG_task_create(allreduce_identifier, 0, comm_size, NULL),
513                   mailbox);
514
515     sprintf(mailbox, "%s_p0_%s", allreduce_identifier, process_name);
516     MSG_task_receive(&task, mailbox);
517     MSG_task_destroy(task);
518     XBT_DEBUG("%s: %s has received", allreduce_identifier, process_name);
519   }
520
521   XBT_VERB("%s %f", xbt_str_join_array(action, " "), MSG_get_clock() - clock);
522   free(allreduce_identifier);
523 }
524
525 static void action_comm_size(const char *const *action)
526 {
527   char *name = NULL;
528   const char *size = action[2];
529   double clock = MSG_get_clock();
530
531   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
532     name = xbt_str_join_array(action, " ");
533   communicator_size = parse_double(size);
534   XBT_VERB("%s %f", name, MSG_get_clock() - clock);
535   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
536     free(name);
537 }
538
539 static void action_compute(const char *const *action)
540 {
541   char *name = NULL;
542   const char *amout = action[2];
543   m_task_t task = MSG_task_create(name, parse_double(amout), 0, NULL);
544   double clock = MSG_get_clock();
545
546   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
547     name = xbt_str_join_array(action, " ");
548   XBT_DEBUG("Entering %s", name);
549   MSG_task_execute(task);
550   MSG_task_destroy(task);
551   XBT_VERB("%s %f", name, MSG_get_clock() - clock);
552   if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
553     free(name);
554 }
555
556 static void action_init(const char *const *action)
557
558 #ifdef HAVE_TRACING
559   TRACE_smpi_init(get_rank(MSG_process_get_name(MSG_process_self())));
560 #endif
561   XBT_DEBUG("Initialize the counters");
562   process_globals_t globals = (process_globals_t) calloc(1, sizeof(s_process_globals_t));
563   globals->isends = xbt_dynar_new(sizeof(msg_comm_t),NULL);
564   globals->irecvs = xbt_dynar_new(sizeof(msg_comm_t),NULL);
565   globals->tasks  = xbt_dynar_new(sizeof(m_task_t),NULL);
566   MSG_process_set_data(MSG_process_self(),globals);
567
568 }
569
570 static void action_finalize(const char *const *action)
571 {
572 #ifdef HAVE_TRACING
573   TRACE_smpi_finalize(get_rank(MSG_process_get_name(MSG_process_self())));
574 #endif
575   process_globals_t globals = (process_globals_t) MSG_process_get_data(MSG_process_self());
576   if (globals){
577     xbt_dynar_free_container(&(globals->isends));
578     xbt_dynar_free_container(&(globals->irecvs));
579     xbt_dynar_free_container(&(globals->tasks));
580     free(globals);
581   }
582 }
583
584 /** Main function */
585 int main(int argc, char *argv[])
586 {
587   MSG_error_t res = MSG_OK;
588
589   smx_factory_initializer_to_use = SIMIX_ctx_raw_factory_init;
590
591   /* Check the given arguments */
592   MSG_global_init(&argc, argv);
593   if (argc < 3) {
594     printf("Usage: %s platform_file deployment_file [action_files]\n",
595            argv[0]);
596     printf
597         ("example: %s msg_platform.xml msg_deployment.xml actions # if all actions are in the same file\n",
598          argv[0]);
599     printf
600         ("example: %s msg_platform.xml msg_deployment.xml # if actions are in separate files, specified in deployment\n",
601          argv[0]);
602     exit(1);
603   }
604
605   /*  Simulation setting */
606   MSG_create_environment(argv[1]);
607
608   /* No need to register functions as in classical MSG programs: the actions get started anyway */
609   MSG_launch_application(argv[2]);
610
611   /*   Action registration */
612   MSG_action_register("init",     action_init);
613   MSG_action_register("finalize", action_finalize);
614   MSG_action_register("comm_size",action_comm_size);
615   MSG_action_register("send",     action_send);
616   MSG_action_register("Isend",    action_Isend);
617   MSG_action_register("recv",     action_recv);
618   MSG_action_register("Irecv",    action_Irecv);
619   MSG_action_register("wait",     action_wait);
620   MSG_action_register("barrier",  action_barrier);
621   MSG_action_register("bcast",    action_bcast);
622   MSG_action_register("reduce",   action_reduce);
623   MSG_action_register("allReduce",action_allReduce);
624   MSG_action_register("sleep",    action_sleep);
625   MSG_action_register("compute",  action_compute);
626
627
628   /* Actually do the simulation using MSG_action_trace_run */
629   res = MSG_action_trace_run(argv[3]);  // it's ok to pass a NULL argument here
630
631   XBT_INFO("Simulation time %g", MSG_get_clock());
632   MSG_clean();
633
634   if (res == MSG_OK)
635     return 0;
636   else
637     return 1;
638 }                               /* end_of_main */