diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index efdbfa2840..24522b6480 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -316,6 +316,15 @@ if(PKG_ADIOS) # script that defines the MPI::MPI_C target enable_language(C) find_package(ADIOS2 REQUIRED) + if(BUILD_MPI) + if(NOT ADIOS2_HAVE_MPI) + message(FATAL_ERROR "ADIOS2 must be built with MPI support when LAMMPS has MPI enabled") + endif() + else() + if(ADIOS2_HAVE_MPI) + message(FATAL_ERROR "ADIOS2 must be built without MPI support when LAMMPS has MPI disabled") + endif() + endif() target_link_libraries(lammps PRIVATE adios2::adios2) endif() diff --git a/src/ADIOS/dump_atom_adios.cpp b/src/ADIOS/dump_atom_adios.cpp index a31f3f4f25..deee23ba41 100644 --- a/src/ADIOS/dump_atom_adios.cpp +++ b/src/ADIOS/dump_atom_adios.cpp @@ -62,7 +62,11 @@ DumpAtomADIOS::DumpAtomADIOS(LAMMPS *lmp, int narg, char **arg) : DumpAtom(lmp, internal = new DumpAtomADIOSInternal(); try { +#if defined(MPI_STUBS) + internal->ad = new adios2::ADIOS("adios2_config.xml", adios2::DebugON); +#else internal->ad = new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON); +#endif } catch (std::ios_base::failure &e) { error->all(FLERR, "ADIOS initialization failed with error: {}", e.what()); } @@ -84,11 +88,19 @@ void DumpAtomADIOS::openfile() if (multifile) { // if one file per timestep, replace '*' with current timestep auto filecurrent = utils::star_subst(filename, update->ntimestep, padflag); +#if defined(MPI_STUBS) + internal->fh = internal->io.Open(filecurrent, adios2::Mode::Write); +#else internal->fh = internal->io.Open(filecurrent, adios2::Mode::Write, world); +#endif if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filecurrent); } else { if (!singlefile_opened) { +#if defined(MPI_STUBS) + internal->fh = internal->io.Open(filename, adios2::Mode::Write); +#else internal->fh = internal->io.Open(filename, adios2::Mode::Write, world); +#endif if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filename); singlefile_opened = 1; } diff --git a/src/ADIOS/dump_custom_adios.cpp b/src/ADIOS/dump_custom_adios.cpp index 194141c15a..be827f507d 100644 --- a/src/ADIOS/dump_custom_adios.cpp +++ b/src/ADIOS/dump_custom_adios.cpp @@ -70,7 +70,11 @@ DumpCustomADIOS::DumpCustomADIOS(LAMMPS *lmp, int narg, char **arg) : DumpCustom internal = new DumpCustomADIOSInternal(); try { +#if defined(MPI_STUBS) + internal->ad = new adios2::ADIOS("adios2_config.xml", adios2::DebugON); +#else internal->ad = new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON); +#endif } catch (std::ios_base::failure &e) { error->all(FLERR, "ADIOS initialization failed with error: {}", e.what()); } @@ -96,11 +100,19 @@ void DumpCustomADIOS::openfile() if (multifile) { // if one file per timestep, replace '*' with current timestep auto filecurrent = utils::star_subst(filename, update->ntimestep, padflag); +#if defined(MPI_STUBS) + internal->fh = internal->io.Open(filecurrent, adios2::Mode::Write); +#else internal->fh = internal->io.Open(filecurrent, adios2::Mode::Write, world); +#endif if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filecurrent); } else { if (!singlefile_opened) { +#if defined(MPI_STUBS) + internal->fh = internal->io.Open(filename, adios2::Mode::Write); +#else internal->fh = internal->io.Open(filename, adios2::Mode::Write, world); +#endif if (!internal->fh) error->one(FLERR, "Cannot open dump file {}", filename); singlefile_opened = 1; } diff --git a/src/ADIOS/reader_adios.cpp b/src/ADIOS/reader_adios.cpp index dd389be702..655df98d26 100644 --- a/src/ADIOS/reader_adios.cpp +++ b/src/ADIOS/reader_adios.cpp @@ -82,7 +82,11 @@ ReaderADIOS::ReaderADIOS(LAMMPS *lmp) : Reader(lmp) internal = new ReadADIOSInternal(); try { +#if defined(MPI_STUBS) + internal->ad = new adios2::ADIOS("adios2_config.xml", adios2::DebugON); +#else internal->ad = new adios2::ADIOS("adios2_config.xml", world, adios2::DebugON); +#endif } catch (std::ios_base::failure &e) { error->one(FLERR, "ADIOS initialization failed with error: {}", e.what()); } @@ -134,7 +138,11 @@ void ReaderADIOS::open_file(const std::string &file) if (internal->fh) internal->fh.Close(); try { +#if defined(MPI_STUBS) + internal->fh = internal->io.Open(file, adios2::Mode::Read); +#else internal->fh = internal->io.Open(file, adios2::Mode::Read, world); +#endif } catch (std::ios_base::failure &e) { error->one(FLERR, "Error opening file {}: {}", file, e.what()); }