Skip to content

Commit

Permalink
Use simpler file existence check in Windows workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jul 29, 2022
1 parent 8544100 commit 22be635
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
3 changes: 3 additions & 0 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class ADIOS2IOHandlerImpl

void checkFile(Writable *, Parameter<Operation::CHECK_FILE> &) override;

// MPI Collective
bool checkFile(std::string fullFilePath) const;

void
createPath(Writable *, Parameter<Operation::CREATE_PATH> const &) override;

Expand Down
43 changes: 15 additions & 28 deletions src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,32 +508,36 @@ void ADIOS2IOHandlerImpl::checkFile(
std::string name =
fullPath(parameters.name + fileSuffix(/* verbose = */ false));

using FileExists = Parameter<Operation::CHECK_FILE>::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")
{
/*
* 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<Operation::CHECK_FILE>::FileExists;
*parameters.fileExists = fileExists ? FileExists::Yes : FileExists::No;
return fileExists;
}

void ADIOS2IOHandlerImpl::createPath(
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 22be635

Please sign in to comment.