[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:
This commit is contained in:
Leon Arber 2005-04-05 16:42:02 -05:00
parent a4760c1ade
commit bba7693f56
2 changed files with 82 additions and 1 deletions

View File

@ -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

View File

@ -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