summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2006-04-07 15:00:47 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2006-04-07 15:00:47 (GMT)
commitd4a986445c1371eafe67d798de3fd1311cbc3479 (patch)
treefef2d3aea6ec3aa532447ce788b1a3dd44444481 /test
parente6310e08692c631e95a9d827a0f7ec0ddf12d82a (diff)
downloadhdf5-d4a986445c1371eafe67d798de3fd1311cbc3479.zip
hdf5-d4a986445c1371eafe67d798de3fd1311cbc3479.tar.gz
hdf5-d4a986445c1371eafe67d798de3fd1311cbc3479.tar.bz2
[svn-r12209] Purpose:
Bug fix. Description: getenv_all would fail if one calls it without calling MPI_initialized first. This may happen if one uses PHDF5 library to build a serial nature code and does not make any MPI calls. Solution: Added code to detect if MPI has been initialized. If not, use the original getenv. Platforms tested: heping (serial) and mir (parallel).
Diffstat (limited to 'test')
-rw-r--r--test/h5test.c81
1 files changed, 49 insertions, 32 deletions
diff --git a/test/h5test.c b/test/h5test.c
index 15daf3f..555485b 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -901,58 +901,75 @@ int h5_szip_can_encode(void )
* 4/4/05
*
* Modifications:
+ * Use original getenv if MPI is not initialized. This happens
+ * one uses the PHDF5 library to build a serial nature code.
+ * Albert 2006/04/07
*
*-------------------------------------------------------------------------
*/
char* getenv_all(MPI_Comm comm, int root, const char* name)
{
- int nID;
- int len = -1;
+ int mpi_size, mpi_rank, mpi_initialized;
+ int len;
static char* env = NULL;
MPI_Status Status;
assert(name);
- MPI_Comm_rank(comm, &nID);
-
- /* The root task does the getenv call
- * and sends the result to the other tasks */
- if(nID == root)
- {
- env = HDgetenv(name);
+ MPI_Initialized(&mpi_initialized);
+ if (!mpi_initialized){
+ /* use original getenv */
if(env)
- {
- len = HDstrlen(env);
- MPI_Bcast(&len, 1, MPI_INT, root, comm);
- MPI_Bcast(env, len, MPI_CHAR, root, comm);
- }
- /* len -1 indicates that the variable was not in the environment */
- else
- 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(len+1);
- else if(strlen(env) < len)
- env = (char*) HDrealloc(env, len+1);
+ HDfree(env);
+ env = HDgetenv(name);
+ }else{
+ MPI_Comm_rank(comm, &mpi_rank);
+ MPI_Comm_size(comm, &mpi_size);
+ assert(root < mpi_size);
- MPI_Bcast(env, len, MPI_CHAR, root, comm);
- env[len] = '\0';
+ /* 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 = 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
{
- if(env)
- HDfree(env);
- env = NULL;
+ MPI_Bcast(&len, 1, MPI_INT, root, comm);
+ if(len >= 0)
+ {
+ if(env == NULL)
+ env = (char*) HDmalloc(len+1);
+ else if(strlen(env) < len)
+ env = (char*) HDrealloc(env, 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);
+#endif
return env;
}