From 22be6355d500a6da80211f7be8baa1d0951f819a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Thu, 21 Jul 2022 10:20:29 +0200 Subject: [PATCH] Use simpler file existence check in Windows workaround --- include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp | 3 ++ src/IO/ADIOS/ADIOS2IOHandler.cpp | 43 +++++++------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp index a5652db778..707fa8c77d 100644 --- a/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp @@ -153,6 +153,9 @@ class ADIOS2IOHandlerImpl void checkFile(Writable *, Parameter &) override; + // MPI Collective + bool checkFile(std::string fullFilePath) const; + void createPath(Writable *, Parameter const &) override; diff --git a/src/IO/ADIOS/ADIOS2IOHandler.cpp b/src/IO/ADIOS/ADIOS2IOHandler.cpp index ef7845d435..edb6fb8279 100644 --- a/src/IO/ADIOS/ADIOS2IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS2IOHandler.cpp @@ -508,14 +508,20 @@ void ADIOS2IOHandlerImpl::checkFile( std::string name = fullPath(parameters.name + fileSuffix(/* verbose = */ false)); + using FileExists = Parameter::FileExists; + *parameters.fileExists = checkFile(name) ? FileExists::Yes : FileExists::No; +} + +bool ADIOS2IOHandlerImpl::checkFile(std::string fullFilePath) const +{ if (m_engineType == "bp3") { - if (!auxiliary::ends_with(name, ".bp")) + if (!auxiliary::ends_with(fullFilePath, ".bp")) { /* * BP3 will add this ending if not specified */ - name += ".bp"; + fullFilePath += ".bp"; } } else if (m_engineType == "sst") @@ -523,17 +529,15 @@ void ADIOS2IOHandlerImpl::checkFile( /* * SST will add this ending indiscriminately */ - name += ".sst"; + fullFilePath += ".sst"; } - char fileExists = false; - auxiliary::runOnRankZero(m_communicator, [&fileExists, &name]() { - fileExists = - auxiliary::file_exists(name) || auxiliary::directory_exists(name); + auxiliary::runOnRankZero(m_communicator, [&fileExists, &fullFilePath]() { + fileExists = auxiliary::file_exists(fullFilePath) || + auxiliary::directory_exists(fullFilePath); }); auxiliary::MPI_Bcast_fromRankZero(m_communicator, &fileExists); - using FileExists = Parameter::FileExists; - *parameters.fileExists = fileExists ? FileExists::Yes : FileExists::No; + return fileExists; } void ADIOS2IOHandlerImpl::createPath( @@ -2669,25 +2673,8 @@ namespace detail * files. So, we first check for file existence and switch to * create mode if it does not exist. */ - { - try - { - adios2::Engine checkExists = - m_IO.Open(m_file, adios2::Mode::Read); - if (!checkExists) - { - tempMode = adios2::Mode::Write; - } - else - { - checkExists.Close(); - } - } - catch (...) - { - tempMode = adios2::Mode::Write; - } - } + tempMode = m_impl->checkFile(m_file) ? adios2::Mode::Append + : adios2::Mode::Write; [[fallthrough]]; #endif case adios2::Mode::Write: {