summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohamad Chaarawi <chaarawi@hdfgroup.org>2015-06-10 17:57:32 (GMT)
committerMohamad Chaarawi <chaarawi@hdfgroup.org>2015-06-10 17:57:32 (GMT)
commitb9f2a18b5ae9adf23cac4c0336291373a25f0721 (patch)
tree0f630ce5a01721c8ac88fef5282a6f48a71c9ce8
parent0f4e97907cf40af09eece68546e45cf3f3e473b2 (diff)
downloadhdf5-b9f2a18b5ae9adf23cac4c0336291373a25f0721.zip
hdf5-b9f2a18b5ae9adf23cac4c0336291373a25f0721.tar.gz
hdf5-b9f2a18b5ae9adf23cac4c0336291373a25f0721.tar.bz2
[svn-r27185] fix more instances where both mpi is_initialized and is_finalized need to be checked before making any MPI calls.
tested with h5committest.
-rw-r--r--src/H5Eint.c12
-rw-r--r--test/h5test.c158
-rw-r--r--tools/lib/h5tools.c14
3 files changed, 96 insertions, 88 deletions
diff --git a/src/H5Eint.c b/src/H5Eint.c
index 2092566..07d1e46 100644
--- a/src/H5Eint.c
+++ b/src/H5Eint.c
@@ -272,10 +272,12 @@ H5E_walk1_cb(int n, H5E_error1_t *err_desc, void *client_data)
/* try show the process or thread id in multiple processes cases*/
#ifdef H5_HAVE_PARALLEL
{
- int mpi_rank, mpi_initialized;
+ int mpi_rank, mpi_initialized, mpi_finalized;
MPI_Initialized(&mpi_initialized);
- if(mpi_initialized) {
+ MPI_Finalized(&mpi_finalized);
+
+ if(mpi_initialized && !mpi_finalized) {
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
fprintf(stream, "MPI-process %d", mpi_rank);
} /* end if */
@@ -402,10 +404,12 @@ H5E_walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data)
/* try show the process or thread id in multiple processes cases*/
#ifdef H5_HAVE_PARALLEL
{
- int mpi_rank, mpi_initialized;
+ int mpi_rank, mpi_initialized, mpi_finalized;
MPI_Initialized(&mpi_initialized);
- if(mpi_initialized) {
+ MPI_Finalized(&mpi_finalized);
+
+ if(mpi_initialized && !mpi_finalized) {
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
fprintf(stream, "MPI-process %d", mpi_rank);
} /* end if */
diff --git a/test/h5test.c b/test/h5test.c
index d73c120..fefacda 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -700,21 +700,24 @@ h5_show_hostname(void)
{
char hostname[80];
#ifdef H5_HAVE_WIN32_API
- WSADATA wsaData;
- int err;
+ WSADATA wsaData;
+ int err;
#endif
/* try show the process or thread id in multiple processes cases*/
#ifdef H5_HAVE_PARALLEL
{
- int mpi_rank, mpi_initialized;
-
- MPI_Initialized(&mpi_initialized);
- if (mpi_initialized){
- MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
- printf("MPI-process %d.", mpi_rank);
- }else
- printf("thread 0.");
+ int mpi_rank, mpi_initialized, mpi_finalized;
+
+ MPI_Initialized(&mpi_initialized);
+ MPI_Finalized(&mpi_finalized);
+
+ if(mpi_initialized && !mpi_finalized) {
+ MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
+ printf("MPI-process %d.", mpi_rank);
+ }
+ else
+ printf("thread 0.");
}
#elif defined(H5_HAVE_THREADSAFE)
printf("thread %lu.", HDpthread_self_ulong());
@@ -723,31 +726,31 @@ h5_show_hostname(void)
#endif
#ifdef H5_HAVE_WIN32_API
- err = WSAStartup( MAKEWORD(2,2), &wsaData );
- if ( err != 0 ) {
- /* could not find a usable WinSock DLL */
- return;
- }
-
-/* Confirm that the WinSock DLL supports 2.2.*/
-/* Note that if the DLL supports versions greater */
-/* than 2.2 in addition to 2.2, it will still return */
-/* 2.2 in wVersion since that is the version we */
-/* requested. */
-
- if ( LOBYTE( wsaData.wVersion ) != 2 ||
- HIBYTE( wsaData.wVersion ) != 2 ) {
- /* could not find a usable WinSock DLL */
- WSACleanup( );
- return;
- }
+ err = WSAStartup( MAKEWORD(2,2), &wsaData );
+ if ( err != 0 ) {
+ /* could not find a usable WinSock DLL */
+ return;
+ }
+
+ /* Confirm that the WinSock DLL supports 2.2.*/
+ /* Note that if the DLL supports versions greater */
+ /* than 2.2 in addition to 2.2, it will still return */
+ /* 2.2 in wVersion since that is the version we */
+ /* requested. */
+
+ if ( LOBYTE( wsaData.wVersion ) != 2 ||
+ HIBYTE( wsaData.wVersion ) != 2 ) {
+ /* could not find a usable WinSock DLL */
+ WSACleanup( );
+ return;
+ }
#endif
#ifdef H5_HAVE_GETHOSTNAME
if (gethostname(hostname, (size_t)80) < 0)
- printf(" gethostname failed\n");
+ printf(" gethostname failed\n");
else
- printf(" hostname=%s\n", hostname);
+ printf(" hostname=%s\n", hostname);
#else
printf(" gethostname not supported\n");
#endif
@@ -1099,61 +1102,62 @@ int h5_szip_can_encode(void )
char *
getenv_all(MPI_Comm comm, int root, const char* name)
{
- int mpi_size, mpi_rank, mpi_initialized;
+ int mpi_size, mpi_rank, mpi_initialized, mpi_finalized;
int len;
static char* env = NULL;
assert(name);
MPI_Initialized(&mpi_initialized);
- if(!mpi_initialized) {
- /* use original getenv */
- if(env)
- HDfree(env);
- env = HDgetenv(name);
- } /* end if */
- else {
- MPI_Comm_rank(comm, &mpi_rank);
- MPI_Comm_size(comm, &mpi_size);
- assert(root < mpi_size);
-
- /* The root task does the getenv call
- * and sends the result to the other tasks */
- if(mpi_rank == root) {
- env = HDgetenv(name);
- if(env) {
- len = (int)HDstrlen(env);
- MPI_Bcast(&len, 1, MPI_INT, root, comm);
- MPI_Bcast(env, len, MPI_CHAR, root, comm);
- }
- else {
- /* len -1 indicates that the variable was not in the environment */
- len = -1;
- MPI_Bcast(&len, 1, MPI_INT, root, comm);
- }
- }
- else {
- MPI_Bcast(&len, 1, MPI_INT, root, comm);
- if(len >= 0) {
- if(env == NULL)
- env = (char*) HDmalloc((size_t)len+1);
- else if(HDstrlen(env) < (size_t)len)
- env = (char*) HDrealloc(env, (size_t)len+1);
-
- MPI_Bcast(env, len, MPI_CHAR, root, comm);
- env[len] = '\0';
- }
- else {
- if(env)
- HDfree(env);
- env = NULL;
- }
- }
- }
-
+ MPI_Finalized(&mpi_finalized);
+
+ if(mpi_initialized && !mpi_finalized) {
+ MPI_Comm_rank(comm, &mpi_rank);
+ MPI_Comm_size(comm, &mpi_size);
+ assert(root < mpi_size);
+
+ /* The root task does the getenv call
+ * and sends the result to the other tasks */
+ if(mpi_rank == root) {
+ env = HDgetenv(name);
+ if(env) {
+ len = (int)HDstrlen(env);
+ MPI_Bcast(&len, 1, MPI_INT, root, comm);
+ MPI_Bcast(env, len, MPI_CHAR, root, comm);
+ }
+ else {
+ /* len -1 indicates that the variable was not in the environment */
+ len = -1;
+ MPI_Bcast(&len, 1, MPI_INT, root, comm);
+ }
+ }
+ else {
+ MPI_Bcast(&len, 1, MPI_INT, root, comm);
+ if(len >= 0) {
+ if(env == NULL)
+ env = (char*) HDmalloc((size_t)len+1);
+ else if(HDstrlen(env) < (size_t)len)
+ env = (char*) HDrealloc(env, (size_t)len+1);
+
+ MPI_Bcast(env, len, MPI_CHAR, root, comm);
+ env[len] = '\0';
+ }
+ else {
+ if(env)
+ HDfree(env);
+ env = NULL;
+ }
+ }
#ifndef NDEBUG
- MPI_Barrier(comm);
+ MPI_Barrier(comm);
#endif
+ }
+ else {
+ /* use original getenv */
+ if(env)
+ HDfree(env);
+ env = HDgetenv(name);
+ } /* end if */
return env;
}
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 10d150f..c820aff 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -54,9 +54,6 @@ unsigned long long packed_data_mask; /* mask in which packed bits to display */
/* module-scoped variables */
static int h5tools_init_g; /* if h5tools lib has been initialized */
-#ifdef H5_HAVE_PARALLEL
-static int h5tools_mpi_init_g; /* if MPI_Init() has been called */
-#endif /* H5_HAVE_PARALLEL */
/* Names of VFDs */
static const char *drivernames[]={
@@ -516,11 +513,14 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum)
}
#ifdef H5_HAVE_PARALLEL
else if(!HDstrcmp(driver, drivernames[MPIO_IDX])) {
+ int mpi_initialized, mpi_finalized;
+
/* MPI-I/O Driver */
- /* check if MPI has been initialized. */
- if(!h5tools_mpi_init_g)
- MPI_Initialized(&h5tools_mpi_init_g);
- if(h5tools_mpi_init_g) {
+ /* check if MPI is available. */
+ MPI_Initialized(&mpi_initialized);
+ MPI_Finalized(&mpi_finalized);
+
+ if(mpi_initialized && !mpi_finalized) {
if(H5Pset_fapl_mpio(new_fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
goto error;
if(drivernum)