summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohamad Chaarawi <chaarawi@hdfgroup.org>2015-06-08 20:52:48 (GMT)
committerMohamad Chaarawi <chaarawi@hdfgroup.org>2015-06-08 20:52:48 (GMT)
commit929e8ce1281a2a4953f6f3925a8595227fcb8f7f (patch)
tree5a6e2ad3622dadf6de58ce81397328e527fbd1c7
parent02e9a43900cb8d2879b9bb2af9c3a9aba98c8949 (diff)
downloadhdf5-929e8ce1281a2a4953f6f3925a8595227fcb8f7f.zip
hdf5-929e8ce1281a2a4953f6f3925a8595227fcb8f7f.tar.gz
hdf5-929e8ce1281a2a4953f6f3925a8595227fcb8f7f.tar.bz2
[svn-r27162] fix for HDFFV-9412:
- Check for mpi is_initialized and is_finalized before making MPI calls in init/terminate of HDF5. - Add a test to make sure we can make serial HDF5 calls from rank 0 after MPI_Finalize is called. tested with h5committest
-rw-r--r--src/H5.c26
-rw-r--r--testpar/CMakeLists.txt1
-rw-r--r--testpar/Makefile.am5
-rw-r--r--testpar/Makefile.in24
-rw-r--r--testpar/t_init_term.c76
5 files changed, 112 insertions, 20 deletions
diff --git a/src/H5.c b/src/H5.c
index ad5ff5f..37476b0 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -115,26 +115,27 @@ H5_init_library(void)
#ifdef H5_HAVE_PARALLEL
{
int mpi_initialized;
+ int mpi_finalized;
int mpi_code;
MPI_Initialized(&mpi_initialized);
+ MPI_Finalized(&mpi_finalized);
#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;
- }
+ if (!H5_MPEinit_g) {
+ int mpe_code;
+ if (mpi_initialized && !mpi_finalized) {
+ 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) {
+ if (mpi_initialized && !mpi_finalized) {
int key_val;
if(MPI_SUCCESS != (mpi_code = MPI_Comm_create_keyval(MPI_NULL_COPY_FN,
@@ -334,11 +335,14 @@ H5_term_library(void)
* down if any of the below code involves using the instrumentation code.
*/
if(H5_MPEinit_g) {
- int mpe_code;
int mpi_initialized;
+ int mpi_finalized;
+ int mpe_code;
MPI_Initialized(&mpi_initialized);
- if(mpi_initialized) {
+ MPI_Finalized(&mpi_finalized);
+
+ if (mpi_initialized && !mpi_finalized) {
mpe_code = MPE_Finish_log("h5log");
HDassert(mpe_code >=0);
} /* end if */
diff --git a/testpar/CMakeLists.txt b/testpar/CMakeLists.txt
index 70e0246..b02c8e2 100644
--- a/testpar/CMakeLists.txt
+++ b/testpar/CMakeLists.txt
@@ -48,6 +48,7 @@ set (H5P_TESTS
t_pflush2
t_pshutdown
t_prestart
+ t_init_term
t_shapesame
)
diff --git a/testpar/Makefile.am b/testpar/Makefile.am
index 1eae439..4fe0ba8 100644
--- a/testpar/Makefile.am
+++ b/testpar/Makefile.am
@@ -25,7 +25,7 @@ AM_CPPFLAGS+=-I$(top_srcdir)/src -I$(top_srcdir)/test
# Test programs. These are our main targets.
#
-TEST_PROG_PARA=t_mpi testphdf5 t_cache t_pflush1 t_pflush2 t_pshutdown t_prestart t_shapesame
+TEST_PROG_PARA=t_mpi testphdf5 t_cache t_pflush1 t_pflush2 t_pshutdown t_prestart t_init_term t_shapesame
check_PROGRAMS = $(TEST_PROG_PARA)
@@ -40,7 +40,8 @@ LDADD = $(LIBH5TEST) $(LIBHDF5)
# MPItest.h5 is from t_mpi
# Para*.h5 are from testphdf
# shutdown.h5 is from t_pshutdown
+# after_mpi_fin.h5 is from t_init_term
# go is used for debugging. See testphdf5.c.
-CHECK_CLEANFILES+=MPItest.h5 Para*.h5 CacheTestDummy.h5 shutdown.h5 go
+CHECK_CLEANFILES+=MPItest.h5 Para*.h5 CacheTestDummy.h5 shutdown.h5 after_mpi_fin.h5 go
include $(top_srcdir)/config/conclude.am
diff --git a/testpar/Makefile.in b/testpar/Makefile.in
index 7787a65..dc339cd 100644
--- a/testpar/Makefile.in
+++ b/testpar/Makefile.in
@@ -113,7 +113,7 @@ CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__EXEEXT_1 = t_mpi$(EXEEXT) testphdf5$(EXEEXT) t_cache$(EXEEXT) \
t_pflush1$(EXEEXT) t_pflush2$(EXEEXT) t_pshutdown$(EXEEXT) \
- t_prestart$(EXEEXT) t_shapesame$(EXEEXT)
+ t_prestart$(EXEEXT) t_init_term$(EXEEXT) t_shapesame$(EXEEXT)
t_cache_SOURCES = t_cache.c
t_cache_OBJECTS = t_cache.$(OBJEXT)
t_cache_LDADD = $(LDADD)
@@ -122,6 +122,10 @@ AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
+t_init_term_SOURCES = t_init_term.c
+t_init_term_OBJECTS = t_init_term.$(OBJEXT)
+t_init_term_LDADD = $(LDADD)
+t_init_term_DEPENDENCIES = $(LIBH5TEST) $(LIBHDF5)
t_mpi_SOURCES = t_mpi.c
t_mpi_OBJECTS = t_mpi.$(OBJEXT)
t_mpi_LDADD = $(LDADD)
@@ -188,10 +192,10 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
-SOURCES = t_cache.c t_mpi.c t_pflush1.c t_pflush2.c t_prestart.c \
- t_pshutdown.c t_shapesame.c $(testphdf5_SOURCES)
-DIST_SOURCES = t_cache.c t_mpi.c t_pflush1.c t_pflush2.c t_prestart.c \
- t_pshutdown.c t_shapesame.c $(testphdf5_SOURCES)
+SOURCES = t_cache.c t_init_term.c t_mpi.c t_pflush1.c t_pflush2.c \
+ t_prestart.c t_pshutdown.c t_shapesame.c $(testphdf5_SOURCES)
+DIST_SOURCES = t_cache.c t_init_term.c t_mpi.c t_pflush1.c t_pflush2.c \
+ t_prestart.c t_pshutdown.c t_shapesame.c $(testphdf5_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@@ -687,13 +691,14 @@ TRACE = perl $(top_srcdir)/bin/trace
# MPItest.h5 is from t_mpi
# Para*.h5 are from testphdf
# shutdown.h5 is from t_pshutdown
+# after_mpi_fin.h5 is from t_init_term
# go is used for debugging. See testphdf5.c.
CHECK_CLEANFILES = *.chkexe *.chklog *.clog *.clog2 MPItest.h5 \
- Para*.h5 CacheTestDummy.h5 shutdown.h5 go
+ Para*.h5 CacheTestDummy.h5 shutdown.h5 after_mpi_fin.h5 go
# Test programs. These are our main targets.
#
-TEST_PROG_PARA = t_mpi testphdf5 t_cache t_pflush1 t_pflush2 t_pshutdown t_prestart t_shapesame
+TEST_PROG_PARA = t_mpi testphdf5 t_cache t_pflush1 t_pflush2 t_pshutdown t_prestart t_init_term t_shapesame
testphdf5_SOURCES = testphdf5.c t_dset.c t_file.c t_file_image.c t_mdset.c \
t_ph5basic.c t_coll_chunk.c t_span_tree.c t_chunk_alloc.c t_filter_read.c \
t_prop.c
@@ -770,6 +775,10 @@ t_cache$(EXEEXT): $(t_cache_OBJECTS) $(t_cache_DEPENDENCIES) $(EXTRA_t_cache_DEP
@rm -f t_cache$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(t_cache_OBJECTS) $(t_cache_LDADD) $(LIBS)
+t_init_term$(EXEEXT): $(t_init_term_OBJECTS) $(t_init_term_DEPENDENCIES) $(EXTRA_t_init_term_DEPENDENCIES)
+ @rm -f t_init_term$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(t_init_term_OBJECTS) $(t_init_term_LDADD) $(LIBS)
+
t_mpi$(EXEEXT): $(t_mpi_OBJECTS) $(t_mpi_DEPENDENCIES) $(EXTRA_t_mpi_DEPENDENCIES)
@rm -f t_mpi$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(t_mpi_OBJECTS) $(t_mpi_LDADD) $(LIBS)
@@ -811,6 +820,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_file.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_file_image.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_filter_read.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_init_term.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_mdset.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_mpi.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t_pflush1.Po@am__quote@
diff --git a/testpar/t_init_term.c b/testpar/t_init_term.c
new file mode 100644
index 0000000..824f773
--- /dev/null
+++ b/testpar/t_init_term.c
@@ -0,0 +1,76 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Programmer: Mohamad Chaarawi
+ * June 2015
+ *
+ * Purpose: This test checks for the correct initialization and
+ * termination of the HDF5 library with MPI init and finalize.
+ */
+
+#include "testphdf5.h"
+
+int nerrors = 0; /* errors count */
+
+const char *FILENAME[] = {
+ "after_mpi_fin",
+ NULL
+};
+
+int
+main (int argc, char **argv)
+{
+ int mpi_size, mpi_rank;
+ MPI_Comm comm = MPI_COMM_WORLD;
+
+ /* Initialize and finalize MPI */
+ MPI_Init(&argc, &argv);
+ MPI_Comm_size(comm, &mpi_size);
+ MPI_Comm_rank(comm, &mpi_rank);
+
+ if(MAINPROCESS)
+ TESTING("Usage of Serial HDF5 after MPI_Finalize() is called");
+
+ MPI_Finalize();
+
+ nerrors += GetTestNumErrs();
+
+ /* test if we can initialize the library with MPI being finalized
+ and create a file serially */
+ H5open();
+
+ if(mpi_rank == 0) {
+ char filename[1024];
+ hid_t file_id;
+
+ h5_fixname(FILENAME[0], H5P_DEFAULT, filename, sizeof filename);
+ file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ VRFY((file_id >= 0), "H5Fcreate succeeded");
+ H5Fclose(file_id);
+ file_id = -1;
+ }
+
+ H5close();
+
+ if(MAINPROCESS) {
+ if(0 == nerrors)
+ PASSED()
+ else
+ H5_FAILED()
+ }
+
+ return (nerrors!=0);
+}