summaryrefslogtreecommitdiffstats
path: root/src/H5.c
diff options
context:
space:
mode:
authorMohamad Chaarawi <chaarawi@hdfgroup.org>2015-02-20 21:33:48 (GMT)
committerMohamad Chaarawi <chaarawi@hdfgroup.org>2015-02-20 21:33:48 (GMT)
commitfcd77ffe7ea32017bc00aa7652e7abd91d8b0b89 (patch)
tree0a0b5a2ec5c195d4be6c48596dffd2dfac62f273 /src/H5.c
parent734f1682254aa422172247ac21e5c61d634aded2 (diff)
downloadhdf5-fcd77ffe7ea32017bc00aa7652e7abd91d8b0b89.zip
hdf5-fcd77ffe7ea32017bc00aa7652e7abd91d8b0b89.tar.gz
hdf5-fcd77ffe7ea32017bc00aa7652e7abd91d8b0b89.tar.bz2
[svn-r26260] - add an attribute callback to call H5_term_library when MPI_COMM_SELF is destroyed.
- add tests for above. - this is a fix for HDFFV-883. 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 af8b668..52dc566 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 */
@@ -109,6 +111,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.
*/
@@ -132,24 +171,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
@@ -580,6 +601,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