Skip to content

Commit

Permalink
Clean up I/O back-end allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ckhroulev committed Aug 19, 2020
1 parent e94f4c7 commit 8e3b020
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/util/io/File.cc
@@ -1,4 +1,4 @@
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 PISM Authors
// Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 PISM Authors
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -111,36 +111,50 @@ static IO_Backend choose_backend(MPI_Comm com, const std::string &filename) {
}

static io::NCFile::Ptr create_backend(MPI_Comm com, IO_Backend backend, int iosysid) {
// disable a compiler warning
(void) iosysid;

int size = 1;
MPI_Comm_size(com, &size);

if (backend == PISM_NETCDF3) {
switch (backend) {
case PISM_NETCDF3:
return io::NCFile::Ptr(new io::NC3File(com));
}

case PISM_NETCDF4_PARALLEL:
#if (Pism_USE_PARALLEL_NETCDF4==1)
if (backend == PISM_NETCDF4_PARALLEL) {
return io::NCFile::Ptr(new io::NC4_Par(com));
}
#else
break;
#endif

case PISM_PNETCDF:
#if (Pism_USE_PNETCDF==1)
if (backend == PISM_PNETCDF) {
return io::NCFile::Ptr(new io::PNCFile(com));
}
#else
break;
#endif

case PISM_PIO_PNETCDF:
case PISM_PIO_NETCDF4P:
case PISM_PIO_NETCDF4C:
case PISM_PIO_NETCDF:
#if (Pism_USE_PIO==1)
if (backend == PISM_PIO_PNETCDF or
backend == PISM_PIO_NETCDF4P or
backend == PISM_PIO_NETCDF4C or
backend == PISM_PIO_NETCDF) {
if (iosysid == -1) {
throw RuntimeError::formatted(PISM_ERROR_LOCATION,
"To use ParallelIO you have to pass iosysid to File");
{
if (iosysid == -1) {
throw RuntimeError::formatted(PISM_ERROR_LOCATION,
"To use ParallelIO you have to pass iosysid to File");
}
return io::NCFile::Ptr(new io::ParallelIO(com, iosysid, backend));
}
return io::NCFile::Ptr(new io::ParallelIO(com, iosysid, backend));
}
#else
(void) iosysid; // silence a compiler warning
break;
#endif

case PISM_GUESS:
break;
} // end of switch (backend)

throw RuntimeError::formatted(PISM_ERROR_LOCATION,
"unknown or unsupported I/O backend: %d", backend);
}
Expand Down

0 comments on commit 8e3b020

Please sign in to comment.