Skip to content

Commit

Permalink
Handle certain empty subfiling environment variables (#4038)
Browse files Browse the repository at this point in the history
  • Loading branch information
glennsong09 authored Mar 20, 2024
1 parent e99b0af commit a286066
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/H5FDsubfiling/H5FDioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ H5FD_ioc_init(void)

/* Check if IOC VFD has been loaded dynamically */
env_var = getenv(HDF5_DRIVER);
if (env_var && !strcmp(env_var, H5FD_IOC_NAME)) {
if (env_var && strlen(env_var) > 0 && !strcmp(env_var, H5FD_IOC_NAME)) {
int mpi_initialized = 0;
int provided = 0;

Expand Down Expand Up @@ -1498,7 +1498,8 @@ H5FD__ioc_del(const char *name, hid_t fapl)
/* TODO: No support for subfile directory prefix currently */
/* TODO: Possibly try loading config file prefix from file before deleting */
snprintf(tmp_filename, PATH_MAX, "%s/" H5FD_SUBFILING_CONFIG_FILENAME_TEMPLATE,
prefix_env ? prefix_env : file_dirname, base_filename, (uint64_t)st.st_ino);
prefix_env && (strlen(prefix_env) > 0) ? prefix_env : file_dirname, base_filename,
(uint64_t)st.st_ino);

if (NULL == (config_file = fopen(tmp_filename, "r"))) {
if (ENOENT == errno) {
Expand Down
13 changes: 8 additions & 5 deletions src/H5FDsubfiling/H5subfiling_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ init_subfiling(const char *base_filename, uint64_t file_id, H5FD_subfiling_param

/* Check if a prefix has been set for the configuration file name */
prefix_env = getenv(H5FD_SUBFILING_CONFIG_FILE_PREFIX);
if (prefix_env) {
if (prefix_env && (strlen(prefix_env) > 0)) {
if (NULL == (new_context->config_file_prefix = strdup(prefix_env)))
H5_SUBFILING_GOTO_ERROR(H5E_VFL, H5E_CANTCOPY, FAIL, "couldn't copy config file prefix string");
}
Expand Down Expand Up @@ -858,7 +858,8 @@ init_subfiling(const char *base_filename, uint64_t file_id, H5FD_subfiling_param
char *env_value = NULL;

/* Check for a subfiling stripe size setting from the environment */
if ((env_value = getenv(H5FD_SUBFILING_STRIPE_SIZE))) {
env_value = getenv(H5FD_SUBFILING_STRIPE_SIZE);
if (env_value && (strlen(env_value) > 0)) {
long long stripe_size = -1;

errno = 0;
Expand Down Expand Up @@ -988,7 +989,8 @@ init_app_topology(int64_t sf_context_id, H5FD_subfiling_params_t *subfiling_conf
case SELECT_IOC_ONE_PER_NODE: {
if (comm_size > 1) {
/* Check for an IOC-per-node value set in the environment */
if ((env_value = getenv(H5FD_SUBFILING_IOC_PER_NODE))) {
env_value = getenv(H5FD_SUBFILING_IOC_PER_NODE);
if (env_value && (strlen(env_value) > 0)) {
errno = 0;
ioc_select_val = strtol(env_value, NULL, 0);
if ((ERANGE == errno)) {
Expand Down Expand Up @@ -1193,7 +1195,7 @@ get_ioc_selection_criteria_from_env(H5FD_subfiling_ioc_select_t *ioc_selection_t

*ioc_sel_info_str = NULL;

if (env_value) {
if (env_value && (strlen(env_value) > 0)) {
/*
* Parse I/O Concentrator selection strategy criteria as
* either a single value or two colon-separated values of
Expand Down Expand Up @@ -1828,7 +1830,8 @@ init_subfiling_context(subfiling_context_t *sf_context, const char *base_filenam
"couldn't allocate space for subfiling filename");

/* Check for a subfile name prefix setting in the environment */
if ((env_value = getenv(H5FD_SUBFILING_SUBFILE_PREFIX))) {
env_value = getenv(H5FD_SUBFILING_SUBFILE_PREFIX);
if (env_value && (strlen(env_value) > 0)) {
if (NULL == (sf_context->subfile_prefix = strdup(env_value)))
H5_SUBFILING_GOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "couldn't copy subfile prefix value");
}
Expand Down
38 changes: 38 additions & 0 deletions testpar/t_subfiling_vfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3237,6 +3237,44 @@ main(int argc, char **argv)
SKIPPED();
#endif

if (MAINPROCESS)
printf("\nRe-running tests with environment variables set to the empty string\n");

HDsetenv("H5FD_SUBFILING_SUBFILE_PREFIX", "", 1);
HDsetenv("H5FD_SUBFILING_IOC_SELECTION_CRITERIA", "", 1);
HDsetenv("H5FD_SUBFILING_IOC_PER_NODE", "", 1);
HDsetenv("H5FD_SUBFILING_STRIPE_SIZE", "", 1);
HDsetenv("H5FD_SUBFILING_CONFIG_FILE_PREFIX", "", 1);

/* Grab values from environment variables if set */
parse_subfiling_env_vars();

/*
* Assume that we use the "one IOC per node" selection
* strategy by default, with a possibly modified
* number of IOCs per node value
*/
num_iocs_g = (ioc_per_node_g > 0) ? (int)ioc_per_node_g * num_nodes_g : num_nodes_g;
if (num_iocs_g > mpi_size)
num_iocs_g = mpi_size;

for (size_t i = 0; i < ARRAY_SIZE(tests); i++) {
if (MPI_SUCCESS == (mpi_code_g = MPI_Barrier(comm_g))) {
(*tests[i])();
}
else {
if (MAINPROCESS)
MESG("MPI_Barrier failed");
nerrors++;
}
}

HDunsetenv("H5FD_SUBFILING_SUBFILE_PREFIX");
HDunsetenv("H5FD_SUBFILING_IOC_SELECTION_CRITERIA");
HDunsetenv("H5FD_SUBFILING_IOC_PER_NODE");
HDunsetenv("H5FD_SUBFILING_STRIPE_SIZE");
HDunsetenv("H5FD_SUBFILING_CONFIG_FILE_PREFIX");

if (nerrors)
goto exit;

Expand Down
40 changes: 40 additions & 0 deletions testpar/t_vfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6250,6 +6250,46 @@ main(int argc, char **argv)

test_vector_io(mpi_rank, mpi_size);

#ifdef H5_HAVE_SUBFILING_VFD

if (mpi_rank == 0)
printf("\n --- TESTING SUBFILING VFD: environment variables set to empty --- \n");

HDsetenv("H5FD_SUBFILING_SUBFILE_PREFIX", "", 1);
HDsetenv("H5FD_SUBFILING_IOC_SELECTION_CRITERIA", "", 1);
HDsetenv("H5FD_SUBFILING_IOC_PER_NODE", "", 1);
HDsetenv("H5FD_SUBFILING_STRIPE_SIZE", "", 1);
HDsetenv("H5FD_SUBFILING_CONFIG_FILE_PREFIX", "", 1);

MPI_Barrier(comm);

if (mpi_rank == 0)
printf("\n --- TESTING MPIO VFD: selection I/O --- \n");

test_selection_io(mpi_rank, mpi_size);

if (mpi_rank == 0)
printf("\n --- TESTING MPIO VFD: vector I/O --- \n");

if (mpi_size < 2) {
if (mpi_rank == 0) {
printf(" Need at least 2 processes to run tests for vector I/O.");
SKIPPED();
}
printf("\n");
goto finish;
}

test_vector_io(mpi_rank, mpi_size);

HDunsetenv("H5FD_SUBFILING_SUBFILE_PREFIX");
HDunsetenv("H5FD_SUBFILING_IOC_SELECTION_CRITERIA");
HDunsetenv("H5FD_SUBFILING_IOC_PER_NODE");
HDunsetenv("H5FD_SUBFILING_STRIPE_SIZE");
HDunsetenv("H5FD_SUBFILING_CONFIG_FILE_PREFIX");

#endif

finish:
/* make sure all processes are finished before final report, cleanup
* and exit.
Expand Down

0 comments on commit a286066

Please sign in to comment.