Skip to content

Commit acd54b4

Browse files
Fix double write from unique_ptr in ADIOS2 (#1743)
* Add failing test * Fix the bug * Use a less weird API
1 parent 65fa0e9 commit acd54b4

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/IO/ADIOS/ADIOS2File.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,16 @@ void ADIOS2File::finalize()
225225
{
226226
return;
227227
}
228+
if (!m_uniquePtrPuts.empty())
229+
{
230+
throw error::Internal(
231+
"[ADIOS2 backend] Orphaned unique-ptr put operations found "
232+
"when closing file.");
233+
}
228234
// if write accessing, ensure that the engine is opened
229-
// and that all datasets are written
230-
// (attributes and unique_ptr datasets are written upon closing a step
231-
// or a file which users might never do)
232-
bool needToWrite = !m_uniquePtrPuts.empty();
233-
if ((needToWrite || !m_engine) && writeOnly(m_mode))
235+
if (!m_engine && writeOnly(m_mode))
234236
{
235237
getEngine();
236-
for (auto &entry : m_uniquePtrPuts)
237-
{
238-
entry.run(*this);
239-
}
240238
}
241239
if (m_engine)
242240
{
@@ -1027,12 +1025,16 @@ void ADIOS2File::flush_impl(
10271025
initializedDefaults = true;
10281026
}
10291027

1028+
std::vector<BufferedUniquePtrPut> drainedUniquePtrPuts;
10301029
if (writeLatePuts)
10311030
{
10321031
for (auto &entry : m_uniquePtrPuts)
10331032
{
10341033
entry.run(*this);
10351034
}
1035+
// Move the operations out of the queue so that no one has ideas to run
1036+
// them for a second time
1037+
drainedUniquePtrPuts.swap(m_uniquePtrPuts);
10361038
}
10371039

10381040
if (readOnly(m_mode))
@@ -1047,10 +1049,7 @@ void ADIOS2File::flush_impl(
10471049
m_updateSpans.clear();
10481050
m_buffer.clear();
10491051
m_alreadyEnqueued.clear();
1050-
if (writeLatePuts)
1051-
{
1052-
m_uniquePtrPuts.clear();
1053-
}
1052+
drainedUniquePtrPuts.clear();
10541053

10551054
break;
10561055

test/ParallelIOTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ void joined_dim(std::string const &ext)
19371937

19381938
{
19391939
Series s(
1940-
"../samples/joinedDimParallel." + ext,
1940+
"../samples/joinedDimParallel_%T." + ext,
19411941
Access::CREATE,
19421942
MPI_COMM_WORLD);
19431943
std::vector<UniquePtrWithLambda<type>> writeFrom(patches_per_rank);
@@ -2001,7 +2001,7 @@ void joined_dim(std::string const &ext)
20012001

20022002
{
20032003
Series s(
2004-
"../samples/joinedDimParallel." + ext,
2004+
"../samples/joinedDimParallel_%T." + ext,
20052005
Access::READ_ONLY,
20062006
MPI_COMM_WORLD);
20072007
auto it = s.iterations[100];

0 commit comments

Comments
 (0)