From a286066123f64028ee7d93959bbd38b8be0b518b Mon Sep 17 00:00:00 2001 From: Glenn Song <43005495+glennsong09@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:52:27 -0500 Subject: [PATCH] Handle certain empty subfiling environment variables (#4038) --- src/H5FDsubfiling/H5FDioc.c | 5 ++-- src/H5FDsubfiling/H5subfiling_common.c | 13 +++++---- testpar/t_subfiling_vfd.c | 38 ++++++++++++++++++++++++ testpar/t_vfd.c | 40 ++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/src/H5FDsubfiling/H5FDioc.c b/src/H5FDsubfiling/H5FDioc.c index b019add4009..fc581775867 100644 --- a/src/H5FDsubfiling/H5FDioc.c +++ b/src/H5FDsubfiling/H5FDioc.c @@ -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; @@ -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) { diff --git a/src/H5FDsubfiling/H5subfiling_common.c b/src/H5FDsubfiling/H5subfiling_common.c index 47d0624ef16..84e07215d53 100644 --- a/src/H5FDsubfiling/H5subfiling_common.c +++ b/src/H5FDsubfiling/H5subfiling_common.c @@ -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"); } @@ -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; @@ -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)) { @@ -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 @@ -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"); } diff --git a/testpar/t_subfiling_vfd.c b/testpar/t_subfiling_vfd.c index 2ebb0e41961..b0628033222 100644 --- a/testpar/t_subfiling_vfd.c +++ b/testpar/t_subfiling_vfd.c @@ -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; diff --git a/testpar/t_vfd.c b/testpar/t_vfd.c index cce5cf775e8..9faf1dbe7e8 100644 --- a/testpar/t_vfd.c +++ b/testpar/t_vfd.c @@ -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.