Skip to content

Commit 181c215

Browse files
authored
Merge pull request #650 from E3SM-Project/dqwu/override_adios_with_pnetcdf
Introduce a workaround in SCORPIO that allows overriding the default ADIOS output type with PnetCDF for file creation, based on filename matching via regular expressions. In E3SM, ADIOS is typically preferred only for restart files. Until PIO_TYPENAME_RESTART is implemented, this provides a temporary way to use PnetCDF for history file creation.
2 parents 69246b4 + 09007b4 commit 181c215

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,21 @@ else()
268268
message(STATUS "PIO_REARR_ANY rearranger : Setting the local decomposition map length range for SUBSET rearanger (PIO_REARR_ANY_SUBSET_RANGE) to " ${PIO_REARR_ANY_SUBSET_RANGE} " (default)")
269269
endif()
270270

271+
if(WITH_ADIOS2)
272+
if(DEFINED SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX)
273+
if(WITH_PNETCDF)
274+
message(STATUS "Overriding ADIOS type with PnetCDF for creating files matching regex: ${SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX}")
275+
else()
276+
message(WARNING "Requested override of ADIOS with PnetCDF for file creation, but PnetCDF is not enabled. Override will be ignored.")
277+
endif()
278+
else()
279+
# Use a regex pattern that matches nothing: \b\B (word boundary followed by non-boundary)
280+
# This effectively disables overriding ADIOS type with PnetCDF for file creation by default.
281+
set(SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX "\\b\\B")
282+
message(STATUS "Disabling override of ADIOS type with PnetCDF for file creation (default)")
283+
endif()
284+
endif()
285+
271286
#==============================================================================
272287
# DETECT SYSTEM/COMPILERS (and set compiler specific options)
273288
#==============================================================================

src/clib/pio_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
/** Range of length of the local decomposition map for SUBSET rearanger. */
6565
#define PIO_REARR_ANY_SUBSET_RANGE "@PIO_REARR_ANY_SUBSET_RANGE@"
6666

67+
/** Set the regex to override ADIOS type with PnetCDF for file creation. */
68+
#define SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX "@SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX@"
69+
6770
/** Set to 1 if the library is configured to use the PnetCDF library,
6871
* 0 otherwise */
6972
#define PIO_USE_PNETCDF @PIO_USE_PNETCDF@

src/clib/pioc_support.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdlib.h>
1717
#include <libgen.h>
1818
#include <string>
19+
#include <regex>
1920
#include "spio_io_summary.h"
2021
#include "spio_file_mvcache.h"
2122
#include "spio_hash.h"
@@ -3181,6 +3182,36 @@ int spio_createfile_int(int iosysid, int *ncidp, const int *iotype, const char *
31813182
return check_mpi(ios, file, mpierr, __FILE__, __LINE__);
31823183
}
31833184

3185+
if ((file->iotype == PIO_IOTYPE_ADIOS) || (file->iotype == PIO_IOTYPE_ADIOSC))
3186+
{
3187+
#ifdef SPIO_NO_CXX_REGEX
3188+
if (ios->io_rank == 0)
3189+
{
3190+
printf("PIO: WARNING: C++11 regex support is not available; skipping override of ADIOS with PnetCDF for creating file %s\n", filename);
3191+
}
3192+
#else /* SPIO_NO_CXX_REGEX */
3193+
std::regex rgx(SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX);
3194+
if (std::regex_match(filename, rgx))
3195+
{
3196+
#ifdef _PNETCDF
3197+
if (ios->io_rank == 0)
3198+
{
3199+
printf("PIO: WARNING: Creating file %s with PnetCDF instead of ADIOS (matched regex: %s)\n",
3200+
filename, SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX);
3201+
}
3202+
3203+
file->iotype = PIO_IOTYPE_PNETCDF;
3204+
#else
3205+
if (ios->io_rank == 0)
3206+
{
3207+
printf("PIO: WARNING: PnetCDF is not available; skipping override of ADIOS with PnetCDF for creating file %s (matched regex: %s)\n",
3208+
filename, SPIO_OVERRIDE_ADIOS_WITH_PNETCDF_FNAME_REGEX);
3209+
}
3210+
#endif
3211+
}
3212+
#endif /* SPIO_NO_CXX_REGEX */
3213+
}
3214+
31843215
if ((file->iotype == PIO_IOTYPE_ADIOS) || (file->iotype == PIO_IOTYPE_ADIOSC))
31853216
{
31863217
LOG((2, "Calling adios_open mode = %d", file->mode));

0 commit comments

Comments
 (0)