diff --git a/orte/runtime/orte_finalize.c b/orte/runtime/orte_finalize.c index 85bd613c3d..b9a39ff98e 100644 --- a/orte/runtime/orte_finalize.c +++ b/orte/runtime/orte_finalize.c @@ -32,6 +32,7 @@ #include "orte/runtime/orte_globals.h" #include "orte/runtime/runtime.h" #include "orte/runtime/orte_locks.h" +#include "orte/util/name_fns.h" #include "orte/util/show_help.h" /** @@ -44,7 +45,13 @@ */ int orte_finalize(void) { - if (!orte_initialized) { + --orte_initialized; + if (0 != orte_initialized) { + /* check for mismatched calls */ + if (0 > orte_initialized) { + opal_output(0, "%s MISMATCHED CALLS TO ORTE FINALIZE", + ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); + } return ORTE_SUCCESS; } @@ -99,6 +106,5 @@ int orte_finalize(void) /* finalize the opal utilities */ opal_finalize(); - orte_initialized = false; return ORTE_SUCCESS; } diff --git a/orte/runtime/orte_init.c b/orte/runtime/orte_init.c index 732cc46ac9..2f84245dc7 100644 --- a/orte/runtime/orte_init.c +++ b/orte/runtime/orte_init.c @@ -50,7 +50,7 @@ /* * Whether we have completed orte_init or we are in orte_finalize */ -bool orte_initialized = false; +int orte_initialized = 0; bool orte_finalizing = false; bool orte_debug_flag = false; int orte_debug_verbosity; @@ -96,9 +96,12 @@ int orte_init(int* pargc, char*** pargv, orte_proc_type_t flags) int ret; char *error = NULL; - if (orte_initialized) { + if (0 < orte_initialized) { + /* track number of times we have been called */ + orte_initialized++; return ORTE_SUCCESS; } + orte_initialized++; /* initialize the opal layer */ if (ORTE_SUCCESS != (ret = opal_init(pargc, pargv))) { @@ -196,7 +199,6 @@ int orte_init(int* pargc, char*** pargv, orte_proc_type_t flags) } /* All done */ - orte_initialized = true; return ORTE_SUCCESS; error: diff --git a/orte/runtime/runtime.h b/orte/runtime/runtime.h index 60578d71d0..50047c7a2c 100644 --- a/orte/runtime/runtime.h +++ b/orte/runtime/runtime.h @@ -41,7 +41,7 @@ ORTE_DECLSPEC extern const char orte_version_string[]; /** * Whether ORTE is initialized or we are in orte_finalize */ -ORTE_DECLSPEC extern bool orte_initialized; +ORTE_DECLSPEC extern int orte_initialized; ORTE_DECLSPEC extern bool orte_finalizing; ORTE_DECLSPEC extern int orte_debug_output; ORTE_DECLSPEC extern bool orte_debug_flag;