From 788ee8d2ba01a84fd85ba40255fceaf82739ce8f Mon Sep 17 00:00:00 2001 From: Kevin Huck Date: Mon, 10 Aug 2020 15:40:35 -0700 Subject: [PATCH] Add MPI_Finalize wrapper When configuring APEX with MPI support, wrap the MPI_Finalize function so that we can use MPI functions during OTF2 event unification instead of the filesystem. --- src/apex/apex.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/apex/apex.cpp b/src/apex/apex.cpp index 0fee121f..11509aa6 100644 --- a/src/apex/apex.cpp +++ b/src/apex/apex.cpp @@ -78,6 +78,10 @@ thread_instance::get_id(), __func__, __LINE__); fflush(stdout); #define FUNCTION_EXIT #endif +#if defined(APEX_HAVE_MPI) +#include "mpi.h" +#endif + APEX_NATIVE_TLS bool _registered = false; APEX_NATIVE_TLS bool _exited = false; static bool _initialized = false; @@ -2051,6 +2055,18 @@ extern "C" { return hardware_concurrency(); } +/* When running with MPI and OTF (or other event unification at the end of + * execution) we need to finalize APEX before MPI_Finalize() is called, so + * that we can use MPI for the wrap-up. We can override the weak MPI + * implementation of Finalize, and do what we need to. */ +#if defined(APEX_HAVE_MPI) + int MPI_Finalize(void) { + apex::finalize(); + int retval = PMPI_Finalize(); + apex::cleanup(); + return retval; + } +#endif } // extern "C"