Skip to content

Commit e7bc391

Browse files
committed
Avoid flushing for scalar components
1 parent a1ec892 commit e7bc391

File tree

10 files changed

+96
-21
lines changed

10 files changed

+96
-21
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ set(CORE_SOURCE
469469
src/benchmark/mpi/OneDimensionalBlockSlicer.cpp
470470
src/helper/list_series.cpp)
471471
set(IO_SOURCE
472+
src/IO/AbstractIOHandlerImpl.cpp
472473
src/IO/AbstractIOHandlerHelper.cpp
473474
src/IO/DummyIOHandler.cpp
474475
src/IO/IOTask.cpp

docs/source/dev/design.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Therefore, enabling users to handle hierarchical, self-describing file formats w
2323

2424
.. literalinclude:: IOTask.hpp
2525
:language: cpp
26-
:lines: 44-60
26+
:lines: 44-62
2727

2828
Every task is designed to be a fully self-contained description of one such atomic operation. By describing a required minimal step of work (without any side-effect), these operations are the foundation of the unified handling mechanism across suitable file formats.
2929
The actual low-level exchange of data is implemented in ``IOHandlers``, one per file format (possibly two if handlingi MPI-parallel work is possible and requires different behaviour).

include/openPMD/IO/AbstractIOHandlerImpl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ class AbstractIOHandlerImpl
190190
deref_dynamic_cast<Parameter<O::AVAILABLE_CHUNKS> >(
191191
i.parameter.get()));
192192
break;
193+
case O::KEEP_SYNCHRONOUS:
194+
keepSynchronous(
195+
i.writable,
196+
deref_dynamic_cast<Parameter<O::KEEP_SYNCHRONOUS> >(
197+
i.parameter.get()));
198+
break;
193199
}
194200
}
195201
catch (...)
@@ -523,6 +529,9 @@ class AbstractIOHandlerImpl
523529
virtual void
524530
listAttributes(Writable *, Parameter<Operation::LIST_ATTS> &) = 0;
525531

532+
void
533+
keepSynchronous(Writable *, Parameter<Operation::KEEP_SYNCHRONOUS> param);
534+
526535
AbstractIOHandler *m_handler;
527536
}; // AbstractIOHandlerImpl
528537
} // namespace openPMD

include/openPMD/IO/IOTask.hpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,20 @@ Writable *getWritable(Attributable *);
4444
/** Type of IO operation between logical and persistent data.
4545
*/
4646
OPENPMDAPI_EXPORT_ENUM_CLASS(Operation){
47-
CREATE_FILE, OPEN_FILE, CLOSE_FILE, DELETE_FILE,
47+
CREATE_FILE, OPEN_FILE, CLOSE_FILE, DELETE_FILE,
4848

49-
CREATE_PATH, CLOSE_PATH, OPEN_PATH, DELETE_PATH,
49+
CREATE_PATH, CLOSE_PATH, OPEN_PATH, DELETE_PATH,
5050
LIST_PATHS,
5151

52-
CREATE_DATASET, EXTEND_DATASET, OPEN_DATASET, DELETE_DATASET,
53-
WRITE_DATASET, READ_DATASET, LIST_DATASETS, GET_BUFFER_VIEW,
52+
CREATE_DATASET, EXTEND_DATASET, OPEN_DATASET, DELETE_DATASET,
53+
WRITE_DATASET, READ_DATASET, LIST_DATASETS, GET_BUFFER_VIEW,
5454

55-
DELETE_ATT, WRITE_ATT, READ_ATT, LIST_ATTS,
55+
DELETE_ATT, WRITE_ATT, READ_ATT, LIST_ATTS,
5656

5757
ADVANCE,
58-
AVAILABLE_CHUNKS //!< Query chunks that can be loaded in a dataset
58+
AVAILABLE_CHUNKS, //!< Query chunks that can be loaded in a dataset
59+
KEEP_SYNCHRONOUS //!< Keep two items in the object model synchronous with
60+
//!< each other
5961
}; // note: if you change the enum members here, please update
6062
// docs/source/dev/design.rst
6163

@@ -257,8 +259,8 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::LIST_PATHS>
257259
new Parameter<Operation::LIST_PATHS>(*this));
258260
}
259261

260-
std::shared_ptr<std::vector<std::string> > paths =
261-
std::make_shared<std::vector<std::string> >();
262+
std::shared_ptr<std::vector<std::string>> paths =
263+
std::make_shared<std::vector<std::string>>();
262264
};
263265

264266
template <>
@@ -434,8 +436,8 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::LIST_DATASETS>
434436
new Parameter<Operation::LIST_DATASETS>(*this));
435437
}
436438

437-
std::shared_ptr<std::vector<std::string> > datasets =
438-
std::make_shared<std::vector<std::string> >();
439+
std::shared_ptr<std::vector<std::string>> datasets =
440+
std::make_shared<std::vector<std::string>>();
439441
};
440442

441443
template <>
@@ -569,8 +571,8 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::LIST_ATTS>
569571
new Parameter<Operation::LIST_ATTS>(*this));
570572
}
571573

572-
std::shared_ptr<std::vector<std::string> > attributes =
573-
std::make_shared<std::vector<std::string> >();
574+
std::shared_ptr<std::vector<std::string>> attributes =
575+
std::make_shared<std::vector<std::string>>();
574576
};
575577

576578
template <>
@@ -619,6 +621,23 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::AVAILABLE_CHUNKS>
619621
std::shared_ptr<ChunkTable> chunks = std::make_shared<ChunkTable>();
620622
};
621623

624+
template <>
625+
struct OPENPMDAPI_EXPORT Parameter<Operation::KEEP_SYNCHRONOUS>
626+
: public AbstractParameter
627+
{
628+
Parameter() = default;
629+
Parameter(Parameter const &p)
630+
: AbstractParameter(), otherWritable(p.otherWritable)
631+
{}
632+
633+
std::unique_ptr<AbstractParameter> clone() const override
634+
{
635+
return std::make_unique<Parameter<Operation::KEEP_SYNCHRONOUS>>(*this);
636+
}
637+
638+
Writable *otherWritable;
639+
};
640+
622641
/** @brief Self-contained description of a single IO operation.
623642
*
624643
* Contained are

include/openPMD/backend/Writable.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Writable final
7575
friend class ParticleSpecies;
7676
friend class Series;
7777
friend class Record;
78+
friend class AbstractIOHandlerImpl;
7879
template <typename>
7980
friend class CommonADIOS1IOHandlerImpl;
8081
friend class ADIOS1IOHandlerImpl;

src/IO/ADIOS/ADIOS1IOHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ std::future<void> ADIOS1IOHandlerImpl::flush()
134134
deref_dynamic_cast<Parameter<O::OPEN_FILE> >(
135135
i.parameter.get()));
136136
break;
137+
case O::KEEP_SYNCHRONOUS:
138+
keepSynchronous(
139+
i.writable,
140+
deref_dynamic_cast<Parameter<O::KEEP_SYNCHRONOUS> >(
141+
i.parameter.get()));
142+
break;
137143
default:
138144
VERIFY(
139145
false,
@@ -345,6 +351,7 @@ void ADIOS1IOHandler::enqueue(IOTask const &i)
345351
case Operation::CREATE_DATASET:
346352
case Operation::OPEN_FILE:
347353
case Operation::WRITE_ATT:
354+
case Operation::KEEP_SYNCHRONOUS:
348355
m_setup.push(i);
349356
return;
350357
default:

src/IO/ADIOS/ParallelADIOS1IOHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ std::future<void> ParallelADIOS1IOHandlerImpl::flush()
156156
deref_dynamic_cast<Parameter<O::OPEN_FILE> >(
157157
i.parameter.get()));
158158
break;
159+
case O::KEEP_SYNCHRONOUS:
160+
keepSynchronous(
161+
i.writable,
162+
deref_dynamic_cast<Parameter<O::KEEP_SYNCHRONOUS> >(
163+
i.parameter.get()));
164+
break;
159165
default:
160166
VERIFY(
161167
false,
@@ -364,6 +370,7 @@ void ParallelADIOS1IOHandler::enqueue(IOTask const &i)
364370
case Operation::CREATE_DATASET:
365371
case Operation::OPEN_FILE:
366372
case Operation::WRITE_ATT:
373+
case Operation::KEEP_SYNCHRONOUS:
367374
m_setup.push(i);
368375
return;
369376
default:

src/IO/AbstractIOHandlerImpl.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Copyright 2022 Franz Poeschel
2+
*
3+
* This file is part of openPMD-api.
4+
*
5+
* openPMD-api is free software: you can redistribute it and/or modify
6+
* it under the terms of of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* openPMD-api is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with openPMD-api.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#include "openPMD/IO/AbstractIOHandlerImpl.hpp"
23+
#include "openPMD/backend/Writable.hpp"
24+
25+
namespace openPMD
26+
{
27+
void AbstractIOHandlerImpl::keepSynchronous(
28+
Writable *writable, Parameter<Operation::KEEP_SYNCHRONOUS> param)
29+
{
30+
writable->abstractFilePosition = param.otherWritable->abstractFilePosition;
31+
writable->written = true;
32+
}
33+
} // namespace openPMD

src/Mesh.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,9 @@ void Mesh::flush_impl(
230230
MeshRecordComponent &mrc = at(RecordComponent::SCALAR);
231231
mrc.parent() = parent();
232232
mrc.flush(name, flushParams);
233-
IOHandler()->flush(flushParams);
234-
writable().abstractFilePosition =
235-
mrc.writable().abstractFilePosition;
236-
written() = true;
233+
Parameter<Operation::KEEP_SYNCHRONOUS> pSynchronize;
234+
pSynchronize.otherWritable = &mrc.writable();
235+
IOHandler()->enqueue(IOTask(this, pSynchronize));
237236
}
238237
else
239238
{

src/Record.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ void Record::flush_impl(
6060
RecordComponent &rc = at(RecordComponent::SCALAR);
6161
rc.parent() = parent();
6262
rc.flush(name, flushParams);
63-
IOHandler()->flush(flushParams);
64-
writable().abstractFilePosition =
65-
rc.writable().abstractFilePosition;
66-
written() = true;
63+
Parameter<Operation::KEEP_SYNCHRONOUS> pSynchronize;
64+
pSynchronize.otherWritable = &rc.writable();
65+
IOHandler()->enqueue(IOTask(this, pSynchronize));
6766
}
6867
else
6968
{

0 commit comments

Comments
 (0)