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-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 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) 2015 Research Organization for Information Science
13 * and Technology (RIST). All rights reserved.
14 * Copyright (c) 2015-2018 Cisco Systems, Inc. All rights reserved
15 * Copyright (c) 2015 Intel, Inc. All rights reserved
16 * $COPYRIGHT$
17 *
18 * Additional copyrights may follow
19 *
20 * $HEADER$
21 */
22
23 #include "ompi_config.h"
24
25 #include "ompi/mpi/c/bindings.h"
26 #include "ompi/runtime/params.h"
27 #include "ompi/communicator/communicator.h"
28 #include "ompi/errhandler/errhandler.h"
29 #include "ompi/mca/hook/base/base.h"
30
31 #if OMPI_BUILD_MPI_PROFILING
32 #if OPAL_HAVE_WEAK_SYMBOLS
33 #pragma weak MPI_Initialized = PMPI_Initialized
34 #endif
35 #define MPI_Initialized PMPI_Initialized
36 #endif
37
38 static const char FUNC_NAME[] = "MPI_Initialized";
39
40
41 int MPI_Initialized(int *flag)
42 {
43 OPAL_CR_NOOP_PROGRESS();
44
45 ompi_hook_base_mpi_initialized_top(flag);
46
47 int32_t state = ompi_mpi_state;
48
49 if (MPI_PARAM_CHECK) {
50 if (NULL == flag) {
51
52 /* If we have an error, the action that we take depends on
53 whether we're currently (after MPI_Init and before
54 MPI_Finalize) or not */
55
56 if (state >= OMPI_MPI_STATE_INIT_COMPLETED &&
57 state < OMPI_MPI_STATE_FINALIZE_PAST_COMM_SELF_DESTRUCT) {
58 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
59 FUNC_NAME);
60 } else {
61 /* We have no MPI object here so call ompi_errhandle_invoke
62 * directly */
63 return ompi_errhandler_invoke(NULL, NULL, -1,
64 ompi_errcode_get_mpi_code(MPI_ERR_ARG),
65 FUNC_NAME);
66 }
67 }
68 }
69
70 *flag = (state >= OMPI_MPI_STATE_INIT_COMPLETED);
71
72 ompi_hook_base_mpi_initialized_bottom(flag);
73
74 return MPI_SUCCESS;
75 }