Skip to content

Commit b4548d3

Browse files
committed
Fix dirty handling filebased
1 parent bcb55ef commit b4548d3

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

src/Iteration.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,28 @@ void Iteration::flush(internal::FlushParams const &flushParams)
401401
* meshesPath and particlesPath are stored there */
402402
Series s = retrieveSeries();
403403

404-
if (!meshes.empty() || s.containsAttribute("meshesPath"))
405-
{
406-
if (!s.containsAttribute("meshesPath") &&
407-
flushParams.flushLevel != FlushLevel::CreateOrOpenFiles)
404+
auto set_and_get_mp_path =
405+
[&](char const *attrName,
406+
char const *defaultVal,
407+
Series &(Series::*set)(std::string const &)) -> std::string {
408+
if (s.containsAttribute(attrName))
409+
{
410+
return s.getAttribute(attrName).get<std::string>();
411+
}
412+
else
408413
{
409-
s.setMeshesPath("meshes/");
414+
(s.*set)(defaultVal);
415+
return defaultVal;
410416
}
417+
};
418+
419+
if (!meshes.empty() || s.containsAttribute("meshesPath"))
420+
{
421+
auto meshesPath = set_and_get_mp_path(
422+
"meshesPath", "meshes/", &Series::setMeshesPath);
411423
if (meshes.dirtyRecursive())
412424
{
413-
meshes.flush(s.meshesPath(), flushParams);
425+
meshes.flush(meshesPath, flushParams);
414426
for (auto &m : meshes)
415427
{
416428
m.second.flush(m.first, flushParams);
@@ -424,14 +436,11 @@ void Iteration::flush(internal::FlushParams const &flushParams)
424436

425437
if (!particles.empty() || s.containsAttribute("particlesPath"))
426438
{
427-
if (!s.containsAttribute("particlesPath") &&
428-
flushParams.flushLevel != FlushLevel::CreateOrOpenFiles)
429-
{
430-
s.setParticlesPath("particles/");
431-
}
439+
auto particlesPath = set_and_get_mp_path(
440+
"particlesPath", "particles/", &Series::setParticlesPath);
432441
if (particles.dirtyRecursive())
433442
{
434-
particles.flush(s.particlesPath(), flushParams);
443+
particles.flush(particlesPath, flushParams);
435444
for (auto &species : particles)
436445
{
437446
species.second.flush(species.first, flushParams);

src/Series.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,12 @@ void Series::flushFileBased(
14931493
case Access::APPEND_RANDOM_ACCESS:
14941494
case Access::APPEND_LINEAR: {
14951495
bool allDirty = dirty();
1496+
// In flush level SkeletonOnly, we might need to set some attributes
1497+
// (especially: particlesPath, meshesPath), but cannot flush them yet
1498+
// (as writing attributes is only permissible at higher flush levels).
1499+
// This flag records if the Series became dirty during this flush. If
1500+
// yes, we set the Series back to dirty at the end of flushing.
1501+
bool hasBecomeDirty = false;
14961502
for (auto it = begin; it != end; ++it)
14971503
{
14981504
// Phase 1
@@ -1545,9 +1551,27 @@ void Series::flushFileBased(
15451551
* TODO: Ideally, we would skip this in SkeletonOnly flush mode, but
15461552
* for some reason, this leads to hanging parallel tests..?
15471553
*/
1554+
if (flushParams.flushLevel == FlushLevel::SkeletonOnly)
1555+
{
1556+
if (allDirty && !dirty())
1557+
{
1558+
throw error::Internal(
1559+
"Flush mode SkeletonOnly must not unset dirty flags.");
1560+
}
1561+
hasBecomeDirty |=
1562+
flushParams.flushLevel == FlushLevel::SkeletonOnly &&
1563+
!allDirty && dirty();
1564+
}
15481565
setDirty(allDirty);
15491566
}
1550-
determineUnsetDirty(flushParams.flushLevel);
1567+
if (!hasBecomeDirty)
1568+
{
1569+
determineUnsetDirty(flushParams.flushLevel);
1570+
}
1571+
else
1572+
{
1573+
setDirty(true);
1574+
}
15511575
// Phase 3
15521576
if (flushIOHandler)
15531577
{

0 commit comments

Comments
 (0)