Skip to content

Commit 22be635

Browse files
committed
Use simpler file existence check in Windows workaround
1 parent 8544100 commit 22be635

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class ADIOS2IOHandlerImpl
153153

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

156+
// MPI Collective
157+
bool checkFile(std::string fullFilePath) const;
158+
156159
void
157160
createPath(Writable *, Parameter<Operation::CREATE_PATH> const &) override;
158161

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -508,32 +508,36 @@ void ADIOS2IOHandlerImpl::checkFile(
508508
std::string name =
509509
fullPath(parameters.name + fileSuffix(/* verbose = */ false));
510510

511+
using FileExists = Parameter<Operation::CHECK_FILE>::FileExists;
512+
*parameters.fileExists = checkFile(name) ? FileExists::Yes : FileExists::No;
513+
}
514+
515+
bool ADIOS2IOHandlerImpl::checkFile(std::string fullFilePath) const
516+
{
511517
if (m_engineType == "bp3")
512518
{
513-
if (!auxiliary::ends_with(name, ".bp"))
519+
if (!auxiliary::ends_with(fullFilePath, ".bp"))
514520
{
515521
/*
516522
* BP3 will add this ending if not specified
517523
*/
518-
name += ".bp";
524+
fullFilePath += ".bp";
519525
}
520526
}
521527
else if (m_engineType == "sst")
522528
{
523529
/*
524530
* SST will add this ending indiscriminately
525531
*/
526-
name += ".sst";
532+
fullFilePath += ".sst";
527533
}
528-
529534
char fileExists = false;
530-
auxiliary::runOnRankZero(m_communicator, [&fileExists, &name]() {
531-
fileExists =
532-
auxiliary::file_exists(name) || auxiliary::directory_exists(name);
535+
auxiliary::runOnRankZero(m_communicator, [&fileExists, &fullFilePath]() {
536+
fileExists = auxiliary::file_exists(fullFilePath) ||
537+
auxiliary::directory_exists(fullFilePath);
533538
});
534539
auxiliary::MPI_Bcast_fromRankZero(m_communicator, &fileExists);
535-
using FileExists = Parameter<Operation::CHECK_FILE>::FileExists;
536-
*parameters.fileExists = fileExists ? FileExists::Yes : FileExists::No;
540+
return fileExists;
537541
}
538542

539543
void ADIOS2IOHandlerImpl::createPath(
@@ -2669,25 +2673,8 @@ namespace detail
26692673
* files. So, we first check for file existence and switch to
26702674
* create mode if it does not exist.
26712675
*/
2672-
{
2673-
try
2674-
{
2675-
adios2::Engine checkExists =
2676-
m_IO.Open(m_file, adios2::Mode::Read);
2677-
if (!checkExists)
2678-
{
2679-
tempMode = adios2::Mode::Write;
2680-
}
2681-
else
2682-
{
2683-
checkExists.Close();
2684-
}
2685-
}
2686-
catch (...)
2687-
{
2688-
tempMode = adios2::Mode::Write;
2689-
}
2690-
}
2676+
tempMode = m_impl->checkFile(m_file) ? adios2::Mode::Append
2677+
: adios2::Mode::Write;
26912678
[[fallthrough]];
26922679
#endif
26932680
case adios2::Mode::Write: {

0 commit comments

Comments
 (0)