Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9423d136c9b930076070f1d842533ed695bdb7dc
[simgrid.git] / src / smpi / smpi_global.c
1 /* Copyright (c) 2007-2014. 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 "private.h"
8 #include "smpi_mpi_dt_private.h"
9 #include "mc/mc.h"
10 #include "xbt/replay.h"
11 #include "surf/surf.h"
12 #include "simix/smx_private.h"
13 #include "simgrid/sg_config.h"
14
15 #include <float.h>              /* DBL_MAX */
16 #include <stdint.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi,
21                                 "Logging specific to SMPI (kernel)");
22
23 typedef struct s_smpi_process_data {
24   double simulated;
25   int *argc;
26   char ***argv;
27   smx_rdv_t mailbox;
28   smx_rdv_t mailbox_small;
29   xbt_os_timer_t timer;
30   MPI_Comm comm_self;
31   MPI_Comm comm_intra;
32   MPI_Comm* comm_world;
33   void *data;                   /* user data */
34   int index;
35   char state;
36   int sampling;                 /* inside an SMPI_SAMPLE_ block? */
37   char* instance_id;
38   xbt_bar_t finalization_barrier;
39 } s_smpi_process_data_t;
40
41 static smpi_process_data_t *process_data = NULL;
42 int process_count = 0;
43 int* index_to_process_data = NULL;
44
45
46 MPI_Comm MPI_COMM_WORLD = MPI_COMM_UNINITIALIZED;
47 int MPI_UNIVERSE_SIZE;
48
49 MPI_Errhandler *MPI_ERRORS_RETURN = NULL;
50 MPI_Errhandler *MPI_ERRORS_ARE_FATAL = NULL;
51 MPI_Errhandler *MPI_ERRHANDLER_NULL = NULL;
52
53 #define MAILBOX_NAME_MAXLEN (5 + sizeof(int) * 2 + 1)
54
55 static char *get_mailbox_name(char *str, int index)
56 {
57   snprintf(str, MAILBOX_NAME_MAXLEN, "SMPI-%0*x", (int) (sizeof(int) * 2),
58            index);
59   return str;
60 }
61
62 static char *get_mailbox_name_small(char *str, int index)
63 {
64   snprintf(str, MAILBOX_NAME_MAXLEN, "small%0*x", (int) (sizeof(int) * 2),
65            index);
66   return str;
67 }
68
69 void smpi_process_init(int *argc, char ***argv)
70 {
71   int index=-1;
72   smpi_process_data_t data;
73   smx_process_t proc;
74
75   if (argc && argv) {
76     proc = SIMIX_process_self();
77     //FIXME: dirty cleanup method to avoid using msg cleanup functions on these processes when using MSG+SMPI
78     proc->context->cleanup_func=SIMIX_process_cleanup;
79     char* instance_id = (*argv)[1];
80     int rank = atoi((*argv)[2]);
81     index = smpi_process_index_of_smx_process(proc);
82
83     if(!index_to_process_data){
84         index_to_process_data=(int*)xbt_malloc(SIMIX_process_count()*sizeof(int));
85     }
86     MPI_Comm* temp_comm_world;
87     xbt_bar_t temp_bar;
88     smpi_deployment_register_process(instance_id, rank, index, &temp_comm_world ,&temp_bar);
89     data = smpi_process_remote_data(index);
90     data->comm_world = temp_comm_world;
91     if(temp_bar != NULL) data->finalization_barrier = temp_bar;
92     data->index = index;
93     data->instance_id = instance_id;
94     xbt_free(simcall_process_get_data(proc));
95     simcall_process_set_data(proc, data);
96     if (*argc > 3) {
97       free((*argv)[1]);
98       free((*argv)[2]);
99       memmove(&(*argv)[1], &(*argv)[3], sizeof(char *) * (*argc - 3));
100       (*argv)[(*argc) - 1] = NULL;
101       (*argv)[(*argc) - 2] = NULL;
102     }
103     (*argc)-=2;
104     data->argc = argc;
105     data->argv = argv;
106     // set the process attached to the mailbox
107     simcall_rdv_set_receiver(data->mailbox_small, proc);
108
109     XBT_DEBUG("<%d> New process in the game: %p", index, proc);
110
111     if(smpi_privatize_global_variables){
112       smpi_switch_data_segment(index);
113     }
114
115   }
116   if (smpi_process_data() == NULL)
117     xbt_die("smpi_process_data() returned NULL. You probably gave a NULL parameter to MPI_Init. Although it's required by MPI-2, this is currently not supported by SMPI.");
118 }
119
120 void smpi_process_destroy(void)
121 {
122   int index = smpi_process_index();
123   if(smpi_privatize_global_variables){
124     smpi_switch_data_segment(index);
125   }
126   process_data[index_to_process_data[index]]->state = SMPI_FINALIZED;
127   XBT_DEBUG("<%d> Process left the game", index);
128 }
129
130 /**
131  * @brief Prepares the current process for termination.
132  */
133 void smpi_process_finalize(void)
134 {
135     // This leads to an explosion of the search graph
136     // which cannot be reduced:
137     if(MC_is_active())
138       return;
139
140     int index = smpi_process_index();
141     // wait for all pending asynchronous comms to finish
142     xbt_barrier_wait(process_data[index_to_process_data[index]]->finalization_barrier);
143 }
144
145 /**
146  * @brief Check if a process is finalized
147  */
148 int smpi_process_finalized()
149 {
150   int index = smpi_process_index();
151     if (index != MPI_UNDEFINED)
152       return (process_data[index_to_process_data[index]]->state == SMPI_FINALIZED);
153     else
154       return 0;
155 }
156
157 /**
158  * @brief Check if a process is initialized
159  */
160 int smpi_process_initialized(void)
161 {
162   int index = smpi_process_index();
163   return ( (index != MPI_UNDEFINED)
164           && (process_data[index_to_process_data[index]]->state == SMPI_INITIALIZED));
165 }
166
167 /**
168  * @brief Mark a process as initialized (=MPI_Init called)
169  */
170 void smpi_process_mark_as_initialized(void)
171 {
172   int index = smpi_process_index();
173   if ((index != MPI_UNDEFINED) && (!process_data[index_to_process_data[index]]->state != SMPI_FINALIZED))
174     process_data[index_to_process_data[index]]->state = SMPI_INITIALIZED;
175 }
176
177
178 int smpi_global_size(void)
179 {
180   char *value = getenv("SMPI_GLOBAL_SIZE");
181
182   if (!value) {
183     fprintf(stderr,
184             "Please set env var SMPI_GLOBAL_SIZE to expected number of processes.\n");
185     xbt_abort();
186   }
187   return atoi(value);
188 }
189
190 smpi_process_data_t smpi_process_data(void)
191 {
192   return SIMIX_process_self_get_data(SIMIX_process_self());
193 }
194
195 smpi_process_data_t smpi_process_remote_data(int index)
196 {
197   return process_data[index_to_process_data[index]];
198 }
199
200 void smpi_process_set_user_data(void *data)
201 {
202   smpi_process_data_t process_data = smpi_process_data();
203   process_data->data = data;
204 }
205
206 void *smpi_process_get_user_data()
207 {
208   smpi_process_data_t process_data = smpi_process_data();
209   return process_data->data;
210 }
211
212 int smpi_process_count(void)
213 {
214   return process_count;
215 }
216
217 int smpi_process_index(void)
218 {
219   smpi_process_data_t data = smpi_process_data();
220   //return -1 if not initialized
221   return data ? data->index : MPI_UNDEFINED;
222 }
223
224 MPI_Comm smpi_process_comm_world(void)
225 {
226   smpi_process_data_t data = smpi_process_data();
227   //return MPI_COMM_NULL if not initialized
228   return data ? *data->comm_world : MPI_COMM_NULL;
229 }
230
231 smx_rdv_t smpi_process_mailbox(void)
232 {
233   smpi_process_data_t data = smpi_process_data();
234   return data->mailbox;
235 }
236
237 smx_rdv_t smpi_process_mailbox_small(void)
238 {
239   smpi_process_data_t data = smpi_process_data();
240   return data->mailbox_small;
241 }
242
243 smx_rdv_t smpi_process_remote_mailbox(int index)
244 {
245   smpi_process_data_t data = smpi_process_remote_data(index);
246   return data->mailbox;
247 }
248
249
250 smx_rdv_t smpi_process_remote_mailbox_small(int index)
251 {
252   smpi_process_data_t data = smpi_process_remote_data(index);
253   return data->mailbox_small;
254 }
255
256 xbt_os_timer_t smpi_process_timer(void)
257 {
258   smpi_process_data_t data = smpi_process_data();
259   return data->timer;
260 }
261
262 void smpi_process_simulated_start(void)
263 {
264   smpi_process_data_t data = smpi_process_data();
265   data->simulated = SIMIX_get_clock();
266 }
267
268 double smpi_process_simulated_elapsed(void)
269 {
270   smpi_process_data_t data = smpi_process_data();
271   return SIMIX_get_clock() - data->simulated;
272 }
273
274 MPI_Comm smpi_process_comm_self(void)
275 {
276   smpi_process_data_t data = smpi_process_data();
277   if(data->comm_self==MPI_COMM_NULL){
278     MPI_Group group = smpi_group_new(1);
279     data->comm_self = smpi_comm_new(group, NULL);
280     smpi_group_set_mapping(group, smpi_process_index(), 0);
281   }
282
283   return data->comm_self;
284 }
285
286 MPI_Comm smpi_process_get_comm_intra(void)
287 {
288   smpi_process_data_t data = smpi_process_data();
289   return data->comm_intra;
290 }
291
292 void smpi_process_set_comm_intra(MPI_Comm comm)
293 {
294   smpi_process_data_t data = smpi_process_data();
295   data->comm_intra = comm;
296 }
297
298 void smpi_process_set_sampling(int s)
299 {
300   smpi_process_data_t data = smpi_process_data();
301   data->sampling = s;
302 }
303
304 int smpi_process_get_sampling(void)
305 {
306   smpi_process_data_t data = smpi_process_data();
307   return data->sampling;
308 }
309
310
311 void print_request(const char *message, MPI_Request request)
312 {
313   XBT_VERB
314       ("%s  request %p  [buf = %p, size = %zu, src = %d, dst = %d, tag = %d, flags = %x]",
315        message, request, request->buf, request->size, request->src,
316        request->dst, request->tag, request->flags);
317 }
318
319 void smpi_comm_copy_buffer_callback(smx_action_t comm,
320                                            void *buff, size_t buff_size)
321 {
322   XBT_DEBUG("Copy the data over");
323   if(_xbt_replay_is_active()) return;
324   void* tmpbuff=buff;
325
326   if((smpi_privatize_global_variables)
327       && ((char*)buff >= start_data_exe)
328       && ((char*)buff < start_data_exe + size_data_exe )
329     ){
330        XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !");
331        smpi_switch_data_segment(((smpi_process_data_t)SIMIX_process_get_data(comm->comm.src_proc))->index);
332        tmpbuff = (void*)xbt_malloc(buff_size);
333        memcpy(tmpbuff, buff, buff_size);
334   }
335
336
337   if((smpi_privatize_global_variables)
338       && ((char*)comm->comm.dst_buff >= start_data_exe)
339       && ((char*)comm->comm.dst_buff < start_data_exe + size_data_exe )
340     ){
341        XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment");
342        smpi_switch_data_segment(((smpi_process_data_t)SIMIX_process_get_data(comm->comm.dst_proc))->index);
343   }
344
345
346   memcpy(comm->comm.dst_buff, tmpbuff, buff_size);
347   if (comm->comm.detached) {
348     // if this is a detached send, the source buffer was duplicated by SMPI
349     // sender to make the original buffer available to the application ASAP
350     xbt_free(buff);
351     //It seems that the request is used after the call there this should
352     //be free somewhereelse  but where???
353     //xbt_free(comm->comm.src_data);// inside SMPI the request is keep
354     //inside the user data and should be free
355     comm->comm.src_buff = NULL;
356   }
357
358   if(tmpbuff!=buff)xbt_free(tmpbuff);
359
360 }
361
362 static void smpi_check_options(){
363   //check correctness of MPI parameters
364
365    xbt_assert(sg_cfg_get_int("smpi/async_small_thres") <=
366               sg_cfg_get_int("smpi/send_is_detached_thres"));
367
368    if (sg_cfg_is_default_value("smpi/running_power")) {
369      XBT_INFO("You did not set the power of the host running the simulation.  "
370               "The timings will certainly not be accurate.  "
371               "Use the option \"--cfg=smpi/running_power:<flops>\" to set its value."
372               "Check http://simgrid.org/simgrid/latest/doc/options.html#options_smpi_bench for more information.");
373    }
374 }
375
376 int smpi_enabled(void) {
377   return process_data != NULL;
378 }
379
380 void smpi_global_init(void)
381 {
382   int i;
383   MPI_Group group;
384   char name[MAILBOX_NAME_MAXLEN];
385   int smpirun=0;
386
387
388   if (process_count == 0){
389     process_count = SIMIX_process_count();
390     smpirun=1;
391   }
392   process_data = xbt_new0(smpi_process_data_t, process_count);
393   for (i = 0; i < process_count; i++) {
394     process_data[i] = xbt_new(s_smpi_process_data_t, 1);
395     //process_data[i]->index = i;
396     process_data[i]->argc = NULL;
397     process_data[i]->argv = NULL;
398     process_data[i]->mailbox = simcall_rdv_create(get_mailbox_name(name, i));
399     process_data[i]->mailbox_small =
400         simcall_rdv_create(get_mailbox_name_small(name, i));
401     process_data[i]->timer = xbt_os_timer_new();
402     if (MC_is_active())
403       MC_ignore_heap(process_data[i]->timer, xbt_os_timer_size());
404     process_data[i]->comm_self = MPI_COMM_NULL;
405     process_data[i]->comm_intra = MPI_COMM_NULL;
406     process_data[i]->comm_world = NULL;
407     process_data[i]->state = SMPI_UNINITIALIZED;
408     process_data[i]->sampling = 0;
409     process_data[i]->finalization_barrier = NULL;
410   }
411   //if the process was launched through smpirun script
412   //we generate a global mpi_comm_world
413   //if not, we let MPI_COMM_NULL, and the comm world
414   //will be private to each mpi instance
415   if(smpirun){
416     group = smpi_group_new(process_count);
417     MPI_COMM_WORLD = smpi_comm_new(group, NULL);
418     xbt_bar_t bar=xbt_barrier_init(process_count);
419
420     MPI_UNIVERSE_SIZE = smpi_comm_size(MPI_COMM_WORLD);
421     for (i = 0; i < process_count; i++) {
422       smpi_group_set_mapping(group, i, i);
423       process_data[i]->finalization_barrier = bar;
424     }
425   }
426 }
427
428 void smpi_global_destroy(void)
429 {
430   int count = smpi_process_count();
431   int i;
432
433   smpi_bench_destroy();
434   if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){
435       while (smpi_group_unuse(smpi_comm_group(MPI_COMM_WORLD)) > 0);
436       xbt_free(MPI_COMM_WORLD);
437       xbt_barrier_destroy(process_data[0]->finalization_barrier);
438   }else{
439       smpi_deployment_cleanup_instances();
440   }
441   MPI_COMM_WORLD = MPI_COMM_NULL;
442   for (i = 0; i < count; i++) {
443     if(process_data[i]->comm_self!=MPI_COMM_NULL){
444       smpi_group_unuse(smpi_comm_group(process_data[i]->comm_self));
445       smpi_comm_destroy(process_data[i]->comm_self);
446     }
447     if(process_data[i]->comm_intra!=MPI_COMM_NULL){
448       smpi_group_unuse(smpi_comm_group(process_data[i]->comm_intra));
449       smpi_comm_destroy(process_data[i]->comm_intra);
450     }
451     xbt_os_timer_free(process_data[i]->timer);
452     simcall_rdv_destroy(process_data[i]->mailbox);
453     simcall_rdv_destroy(process_data[i]->mailbox_small);
454     xbt_free(process_data[i]);
455   }
456   xbt_free(process_data);
457   process_data = NULL;
458
459   xbt_free(index_to_process_data);
460   if(smpi_privatize_global_variables)
461     smpi_destroy_global_memory_segments();
462   smpi_free_static();
463 }
464
465 #ifndef WIN32
466 void __attribute__ ((weak)) user_main_()
467 {
468   xbt_die("Should not be in this smpi_simulated_main");
469   return;
470 }
471
472 int __attribute__ ((weak)) smpi_simulated_main_(int argc, char **argv)
473 {
474   smpi_process_init(&argc, &argv);
475   user_main_();
476   return 0;
477 }
478
479 int __attribute__ ((weak)) main(int argc, char **argv)
480 {
481   return smpi_main(smpi_simulated_main_, argc, argv);
482 }
483
484 #endif
485
486 static void smpi_init_logs(){
487
488   /* Connect log categories.  See xbt/log.c */
489   XBT_LOG_CONNECT(smpi);        /* Keep this line as soon as possible in this
490                                    function: xbt_log_appender_file.c depends on it
491                                    DO NOT connect this in XBT or so, or it will be
492                                    useless to xbt_log_appender_file.c */
493 #ifdef HAVE_TRACING
494   XBT_LOG_CONNECT(instr_smpi);
495 #endif
496   XBT_LOG_CONNECT(smpi_base);
497   XBT_LOG_CONNECT(smpi_bench);
498   XBT_LOG_CONNECT(smpi_coll);
499   XBT_LOG_CONNECT(smpi_colls);
500   XBT_LOG_CONNECT(smpi_comm);
501   XBT_LOG_CONNECT(smpi_dvfs);
502   XBT_LOG_CONNECT(smpi_group);
503   XBT_LOG_CONNECT(smpi_kernel);
504   XBT_LOG_CONNECT(smpi_mpi);
505   XBT_LOG_CONNECT(smpi_mpi_dt);
506   XBT_LOG_CONNECT(smpi_pmpi);
507   XBT_LOG_CONNECT(smpi_replay);
508   XBT_LOG_CONNECT(smpi_rma);
509
510 }
511
512
513 static void smpi_init_options(){
514   int gather_id = find_coll_description(mpi_coll_gather_description,
515                                           sg_cfg_get_string("smpi/gather"));
516     mpi_coll_gather_fun = (int (*)(void *, int, MPI_Datatype,
517                                    void *, int, MPI_Datatype, int, MPI_Comm))
518         mpi_coll_gather_description[gather_id].coll;
519
520     int allgather_id = find_coll_description(mpi_coll_allgather_description,
521                                              sg_cfg_get_string("smpi/allgather"));
522     mpi_coll_allgather_fun = (int (*)(void *, int, MPI_Datatype,
523                                       void *, int, MPI_Datatype, MPI_Comm))
524         mpi_coll_allgather_description[allgather_id].coll;
525
526     int allgatherv_id = find_coll_description(mpi_coll_allgatherv_description,
527                                               sg_cfg_get_string("smpi/allgatherv"));
528     mpi_coll_allgatherv_fun = (int (*)(void *, int, MPI_Datatype, void *, int *,
529                                        int *, MPI_Datatype, MPI_Comm))
530         mpi_coll_allgatherv_description[allgatherv_id].coll;
531
532     int allreduce_id = find_coll_description(mpi_coll_allreduce_description,
533                                              sg_cfg_get_string("smpi/allreduce"));
534     mpi_coll_allreduce_fun = (int (*)(void *sbuf, void *rbuf, int rcount,
535                                       MPI_Datatype dtype, MPI_Op op,
536                                       MPI_Comm comm))
537         mpi_coll_allreduce_description[allreduce_id].coll;
538
539     int alltoall_id = find_coll_description(mpi_coll_alltoall_description,
540                                             sg_cfg_get_string("smpi/alltoall"));
541     mpi_coll_alltoall_fun = (int (*)(void *, int, MPI_Datatype,
542                                      void *, int, MPI_Datatype, MPI_Comm))
543         mpi_coll_alltoall_description[alltoall_id].coll;
544
545     int alltoallv_id = find_coll_description(mpi_coll_alltoallv_description,
546                                              sg_cfg_get_string("smpi/alltoallv"));
547     mpi_coll_alltoallv_fun = (int (*)(void *, int *, int *, MPI_Datatype,
548                                       void *, int *, int *, MPI_Datatype,
549                                       MPI_Comm))
550         mpi_coll_alltoallv_description[alltoallv_id].coll;
551
552     int bcast_id = find_coll_description(mpi_coll_bcast_description,
553                                          sg_cfg_get_string("smpi/bcast"));
554     mpi_coll_bcast_fun = (int (*)(void *buf, int count, MPI_Datatype datatype,
555                                   int root, MPI_Comm com))
556         mpi_coll_bcast_description[bcast_id].coll;
557
558     int reduce_id = find_coll_description(mpi_coll_reduce_description,
559                                           sg_cfg_get_string("smpi/reduce"));
560     mpi_coll_reduce_fun = (int (*)(void *buf, void *rbuf, int count,
561                                    MPI_Datatype datatype, MPI_Op op,
562                                    int root, MPI_Comm comm))
563         mpi_coll_reduce_description[reduce_id].coll;
564
565     int reduce_scatter_id =
566         find_coll_description(mpi_coll_reduce_scatter_description,
567                               sg_cfg_get_string("smpi/reduce_scatter"));
568     mpi_coll_reduce_scatter_fun = (int (*)(void *sbuf, void *rbuf, int *rcounts,
569                                            MPI_Datatype dtype, MPI_Op op,
570                                            MPI_Comm comm))
571         mpi_coll_reduce_scatter_description[reduce_scatter_id].coll;
572
573     int scatter_id = find_coll_description(mpi_coll_scatter_description,
574                                            sg_cfg_get_string("smpi/scatter"));
575     mpi_coll_scatter_fun = (int (*)(void *sendbuf, int sendcount,
576                                     MPI_Datatype sendtype, void *recvbuf,
577                                     int recvcount, MPI_Datatype recvtype,
578                                     int root, MPI_Comm comm))
579         mpi_coll_scatter_description[scatter_id].coll;
580
581     int barrier_id = find_coll_description(mpi_coll_barrier_description,
582                                            sg_cfg_get_string("smpi/barrier"));
583     mpi_coll_barrier_fun = (int (*)(MPI_Comm comm))
584         mpi_coll_barrier_description[barrier_id].coll;
585
586     smpi_cpu_threshold = sg_cfg_get_double("smpi/cpu_threshold");
587     smpi_running_power = sg_cfg_get_double("smpi/running_power");
588     smpi_privatize_global_variables = sg_cfg_get_boolean("smpi/privatize_global_variables");
589     if (smpi_cpu_threshold < 0)
590       smpi_cpu_threshold = DBL_MAX;
591
592 }
593
594 int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[])
595 {
596   srand(SMPI_RAND_SEED);
597
598   if (getenv("SMPI_PRETEND_CC") != NULL) {
599     /* Hack to ensure that smpicc can pretend to be a simple
600      * compiler. Particularly handy to pass it to the configuration tools */
601     return 0;
602   }
603
604   smpi_init_logs();
605
606 #ifdef HAVE_TRACING
607   TRACE_global_init(&argc, argv);
608
609   TRACE_add_start_function(TRACE_smpi_alloc);
610   TRACE_add_end_function(TRACE_smpi_release);
611 #endif
612
613   SIMIX_global_init(&argc, argv);
614
615   smpi_init_options();
616
617   // parse the platform file: get the host list
618   SIMIX_create_environment(argv[1]);
619   SIMIX_comm_set_copy_data_callback(&smpi_comm_copy_buffer_callback);
620   SIMIX_function_register_default(realmain);
621   SIMIX_launch_application(argv[2]);
622
623   smpi_global_init();
624
625   smpi_check_options();
626
627   if(smpi_privatize_global_variables)
628     smpi_initialize_global_memory_segments();
629
630   /* Clean IO before the run */
631   fflush(stdout);
632   fflush(stderr);
633
634   if (MC_is_active())
635     MC_do_the_modelcheck_for_real();
636   else
637     SIMIX_run();
638
639   if (sg_cfg_get_boolean("smpi/display_timing"))
640     XBT_INFO("Simulation time: %g seconds.", SIMIX_get_clock());
641
642   smpi_global_destroy();
643
644 #ifdef HAVE_TRACING
645   TRACE_end();
646 #endif
647
648   return 0;
649 }
650
651 // This function can be called from extern file, to initialize logs, options, and processes of smpi
652 // without the need of smpirun
653 void SMPI_init(){
654   smpi_init_logs();
655   smpi_init_options();
656   smpi_global_init();
657   smpi_check_options();
658 #ifdef HAVE_TRACING
659   if (TRACE_is_enabled() && TRACE_is_configured()) {
660     TRACE_smpi_alloc();
661   }
662 #endif
663   if(smpi_privatize_global_variables)
664     smpi_initialize_global_memory_segments();
665 }
666
667 void SMPI_finalize(){
668   smpi_global_destroy();
669 }