summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeon Arber <larber@ncsa.uiuc.edu>2005-04-05 21:42:02 (GMT)
committerLeon Arber <larber@ncsa.uiuc.edu>2005-04-05 21:42:02 (GMT)
commitbba7693f56cdf01eca814e64fd289eeb48823a0d (patch)
tree815b99169a3deed737625e7864f2c89ab88aaf40
parenta4760c1ade4affb5a7d517a8a75311ba2186b5e8 (diff)
downloadhdf5-bba7693f56cdf01eca814e64fd289eeb48823a0d.zip
hdf5-bba7693f56cdf01eca814e64fd289eeb48823a0d.tar.gz
hdf5-bba7693f56cdf01eca814e64fd289eeb48823a0d.tar.bz2
[svn-r10555] Purpose:
Feature Description: Added new function, getenv_all (only for parallel builds) Solution: getenv_all is a collective version of getenv. It is used to the return the value of an environment variable in another task and can be used to synchronize all of the environment variables used by all of the tasks. This helps to fix problems that commonly crop up (like with HDF5_PARAPREFIX) when an environment variable does not propogate to other tasks. This commit only includes the function. Future commits will replace the various getenv calls with getenv_all calls. Platforms tested: heping, sol, copper Misc. update:
-rw-r--r--test/h5test.c82
-rw-r--r--test/h5test.h1
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