diff options
-rw-r--r-- | test/h5test.c | 82 | ||||
-rw-r--r-- | test/h5test.h | 1 |
2 files changed, 82 insertions, 1 deletions
diff --git a/test/h5test.c b/test/h5test.c index 94a5599..8044bed 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -302,6 +302,8 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) static int explained = 0; prefix = (paraprefix ? paraprefix : getenv("HDF5_PARAPREFIX")); +/* prefix = (paraprefix ? paraprefix : getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX")); */ + if (!prefix && !explained) { /* print hint by process 0 once. */ @@ -329,7 +331,7 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) * For serial: * First use the environment variable, then try the constant */ - prefix = HDgetenv("HDF5_PREFIX"); + prefix = getenv("HDF5_PREFIX"); #ifdef HDF5_PREFIX if (!prefix) @@ -847,3 +849,81 @@ int h5_szip_can_encode(void ) return(-1); } #endif /* H5_HAVE_FILTER_SZIP */ + +/*------------------------------------------------------------------------- + * Function: getenv_all + * + * Purpose: Used to get the environment that the root MPI task has. + * name specifies which environment variable to look for + * val is the string to which the value of that environment + * variable will be copied. + * + * Return: No failure. + * If an env variable doesn't exist, it is set to NULL. + * This function will allocate space for the variable, and it + * is up to the calling function to free that memory. + * + * Programmer: Leon Arber + * 4/4/05 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +#ifdef H5_HAVE_PARALLEL +char* getenv_all(MPI_Comm comm, int root, const char* name) +{ + int nID; + int len = -1; + 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); + 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); + + HDmemset(env, 0, len); + MPI_Bcast(env, len, MPI_CHAR, root, comm); + env[len+1] = '\0'; + } + else + { + if(env) + HDfree(env); + env = NULL; + } + } + + MPI_Barrier(comm); + + return env; +} + +#endif + diff --git a/test/h5test.h b/test/h5test.h index 00d3367..a0e5ea1 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -148,6 +148,7 @@ H5TEST_DLL int h5_szip_can_encode(void); #ifdef H5_HAVE_PARALLEL H5TEST_DLL int h5_set_info_object(void); H5TEST_DLL void h5_dump_info_object(MPI_Info info); +H5TEST_DLL char* getenv_all(MPI_Comm comm, int root, const char* name); #endif #ifdef __cplusplus |