summaryrefslogtreecommitdiffstats
path: root/src/H5.c
diff options
context:
space:
mode:
authorMohamad Chaarawi <chaarawi@hdfgroup.org>2015-02-25 14:12:05 (GMT)
committerMohamad Chaarawi <chaarawi@hdfgroup.org>2015-02-25 14:12:05 (GMT)
commit864a9d5552c3e74cb1c30756a9a216c039a26c27 (patch)
tree97b85ea9f6b95fdcf61e692db2a4f212156f0f46 /src/H5.c
parent85a644221848b047a46bdcff5f3371d690a2f55a (diff)
downloadhdf5-864a9d5552c3e74cb1c30756a9a216c039a26c27.zip
hdf5-864a9d5552c3e74cb1c30756a9a216c039a26c27.tar.gz
hdf5-864a9d5552c3e74cb1c30756a9a216c039a26c27.tar.bz2
[svn-r26298] merge 26279 from trunk.
HDFFV-883: attach callback to terminate HDF5 library when MPI_COMM_SELF is destroyed on MPI_Finalize. tested h5committest.
Diffstat (limited to 'src/H5.c')
-rw-r--r--src/H5.c80
1 files changed, 61 insertions, 19 deletions
diff --git a/src/H5.c b/src/H5.c
index 84dc990..c8f7775 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -52,7 +52,9 @@
/* Local Prototypes */
/********************/
static void H5_debug_mask(const char*);
-
+#ifdef H5_HAVE_PARALLEL
+static int H5_mpi_delete_cb(MPI_Comm comm, int keyval, void *attr_val, int *flag);
+#endif /*H5_HAVE_PARALLEL*/
/*********************/
/* Package Variables */
@@ -105,6 +107,43 @@ H5_init_library(void)
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(FAIL)
+
+#ifdef H5_HAVE_PARALLEL
+ {
+ int mpi_initialized;
+ int mpi_code;
+
+ MPI_Initialized(&mpi_initialized);
+
+#ifdef H5_HAVE_MPE
+ /* Initialize MPE instrumentation library. */
+ if (!H5_MPEinit_g)
+ {
+ int mpe_code;
+ if (mpi_initialized){
+ mpe_code = MPE_Init_log();
+ HDassert(mpe_code >=0);
+ H5_MPEinit_g = TRUE;
+ }
+ }
+#endif /*H5_HAVE_MPE*/
+
+ /* add an attribute on MPI_COMM_SELF to call H5_term_library
+ when it is destroyed, i.e. on MPI_Finalize */
+ if (mpi_initialized) {
+ int key_val;
+
+ if(MPI_SUCCESS != (mpi_code = MPI_Comm_create_keyval(MPI_NULL_COPY_FN,
+ (MPI_Comm_delete_attr_function *)H5_mpi_delete_cb,
+ &key_val, NULL)))
+ HMPI_GOTO_ERROR(FAIL, "MPI_Comm_create_keyval failed", mpi_code)
+
+ if(MPI_SUCCESS != (mpi_code = MPI_Comm_set_attr(MPI_COMM_SELF, key_val, NULL)))
+ HMPI_GOTO_ERROR(FAIL, "MPI_Comm_set_attr failed", mpi_code)
+ }
+ }
+#endif /*H5_HAVE_PARALLEL*/
+
/*
* Make sure the package information is updated.
*/
@@ -128,24 +167,6 @@ H5_init_library(void)
H5_debug_g.pkg[H5_PKG_V].name = "v";
H5_debug_g.pkg[H5_PKG_Z].name = "z";
-#ifdef H5_HAVE_MPE
- /* Initialize MPE instrumentation library. May need to move this
- * up earlier if any of the above initialization involves using
- * the instrumentation code.
- */
- if (!H5_MPEinit_g)
- {
- int mpe_code;
- int mpi_initialized;
- MPI_Initialized(&mpi_initialized);
- if (mpi_initialized){
- mpe_code = MPE_Init_log();
- HDassert(mpe_code >=0);
- H5_MPEinit_g = TRUE;
- }
- }
-#endif
-
/*
* Install atexit() library cleanup routines unless the H5dont_atexit()
* has been called. Once we add something to the atexit() list it stays
@@ -578,6 +599,27 @@ H5_debug_mask(const char *s)
}
} /* end H5_debug_mask() */
+#ifdef H5_HAVE_PARALLEL
+
+/*-------------------------------------------------------------------------
+ * Function: H5_mpi_delete_cb
+ *
+ * Purpose: Callback attribute on MPI_COMM_SELF to terminate the HDF5
+ * library when the communicator is destroyed, i.e. on MPI_Finalize.
+ *
+ * Return: MPI_SUCCESS
+ *
+ * Programmer: Mohamad Chaarawi, February 2015
+ *
+ *-------------------------------------------------------------------------
+ */
+static int H5_mpi_delete_cb(MPI_Comm UNUSED comm, int UNUSED keyval, void UNUSED *attr_val, int UNUSED *flag)
+{
+ H5_term_library();
+ return MPI_SUCCESS;
+}
+#endif /*H5_HAVE_PARALLEL*/
+
/*-------------------------------------------------------------------------
* Function: H5get_libversion