1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2018 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2007-2018 Cisco Systems, Inc. All rights reserved
13 * Copyright (c) 2007-2008 Sun Microsystems, Inc. All rights reserved.
14 * Copyright (c) 2015 Research Organization for Information Science
15 * and Technology (RIST). All rights reserved.
16 * $COPYRIGHT$
17 *
18 * Additional copyrights may follow
19 *
20 * $HEADER$
21 */
22
23 #include "ompi_config.h"
24
25 #include <stdlib.h>
26
27 #include "opal/util/show_help.h"
28 #include "ompi/runtime/ompi_spc.h"
29 #include "ompi/mpi/c/bindings.h"
30 #include "ompi/communicator/communicator.h"
31 #include "ompi/errhandler/errhandler.h"
32 #include "ompi/constants.h"
33
34 #if OMPI_BUILD_MPI_PROFILING
35 #if OPAL_HAVE_WEAK_SYMBOLS
36 #pragma weak MPI_Init = PMPI_Init
37 #endif
38 #define MPI_Init PMPI_Init
39 #endif
40
41 static const char FUNC_NAME[] = "MPI_Init";
42
43
44 int MPI_Init(int *argc, char ***argv)
45 {
46 int err;
47 int provided;
48 char *env;
49 int required = MPI_THREAD_SINGLE;
50
51 /* check for environment overrides for required thread level. If
52 there is, check to see that it is a valid/supported thread level.
53 If not, default to MPI_THREAD_MULTIPLE. */
54
55 if (NULL != (env = getenv("OMPI_MPI_THREAD_LEVEL"))) {
56 required = atoi(env);
57 if (required < MPI_THREAD_SINGLE || required > MPI_THREAD_MULTIPLE) {
58 required = MPI_THREAD_MULTIPLE;
59 }
60 }
61
62 /* Call the back-end initialization function (we need to put as
63 little in this function as possible so that if it's profiled, we
64 don't lose anything) */
65
66 if (NULL != argc && NULL != argv) {
67 err = ompi_mpi_init(*argc, *argv, required, &provided, false);
68 } else {
69 err = ompi_mpi_init(0, NULL, required, &provided, false);
70 }
71
72 /* Since we don't have a communicator to invoke an errorhandler on
73 here, don't use the fancy-schmancy ERRHANDLER macros; they're
74 really designed for real communicator objects. Just use the
75 back-end function directly. */
76
77 if (MPI_SUCCESS != err) {
78 return ompi_errhandler_invoke(NULL, NULL,
79 OMPI_ERRHANDLER_TYPE_COMM,
80 err <
81 0 ? ompi_errcode_get_mpi_code(err) :
82 err, FUNC_NAME);
83 }
84
85 OPAL_CR_INIT_LIBRARY();
86
87 SPC_INIT();
88
89 return MPI_SUCCESS;
90 }