Logo AND Algorithmique Numérique Distribuée

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