Skip to content

Commit a57e7a4

Browse files
committed
Backend additions
1) New streaming status: RANDOM_ACCESS, for non-streaming situations 2) Variable attributes, to be written only if the backend has support for steps
1 parent 013946e commit a57e7a4

8 files changed

Lines changed: 58 additions & 13 deletions

File tree

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,13 +1156,6 @@ namespace detail
11561156
*/
11571157
void invalidateVariablesMap();
11581158

1159-
private:
1160-
ADIOS2IOHandlerImpl *m_impl;
1161-
std::optional<adios2::Engine> m_engine; //! ADIOS engine
1162-
/**
1163-
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
1164-
*/
1165-
std::string m_engineType;
11661159
/*
11671160
* streamStatus is NoStream for file-based ADIOS engines.
11681161
* This is relevant for the method BufferedActions::requireActiveStep,
@@ -1254,6 +1247,14 @@ namespace detail
12541247
};
12551248
StreamStatus streamStatus = StreamStatus::OutsideOfStep;
12561249

1250+
private:
1251+
ADIOS2IOHandlerImpl *m_impl;
1252+
std::optional<adios2::Engine> m_engine; //! ADIOS engine
1253+
/**
1254+
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
1255+
*/
1256+
std::string m_engineType;
1257+
12571258
/**
12581259
* See documentation for StreamStatus::Parsing.
12591260
* Will be set true under the circumstance described there in order to

include/openPMD/IO/AbstractIOHandlerImpl.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ class AbstractIOHandlerImpl
252252
* The advance mode is determined by parameters.mode.
253253
* The return status code shall be stored as parameters.status.
254254
*/
255-
virtual void advance(Writable *, Parameter<Operation::ADVANCE> &)
256-
{}
255+
virtual void advance(Writable *, Parameter<Operation::ADVANCE> &parameters)
256+
{
257+
*parameters.status = AdvanceStatus::RANDOMACCESS;
258+
}
257259

258260
/** Close an openPMD group.
259261
*
@@ -488,8 +490,13 @@ class AbstractIOHandlerImpl
488490
* datatype parameters.dtype. Any existing attribute with the same name
489491
* should be overwritten. If possible, only the value should be changed if
490492
* the datatype stays the same. The attribute should be written to physical
491-
* storage after the operation completes successfully. All datatypes of
492-
* Datatype should be supported in a type-safe way.
493+
* storage after the operation completes successfully. If the parameter
494+
* changesOverSteps is true, then the attribute must be able to hold
495+
* different values across IO steps. If the backend does not support IO
496+
* steps in such a way, the attribute should not be written. (IO steps are
497+
* an optional backend feature and the frontend must implement fallback
498+
* measures in such a case) All datatypes of Datatype should be supported in
499+
* a type-safe way.
493500
*/
494501
virtual void
495502
writeAttribute(Writable *, Parameter<Operation::WRITE_ATT> const &) = 0;

include/openPMD/IO/IOTask.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::WRITE_ATT>
537537
: AbstractParameter()
538538
, name(p.name)
539539
, dtype(p.dtype)
540+
, changesOverSteps(p.changesOverSteps)
540541
, resource(p.resource)
541542
{}
542543

@@ -548,6 +549,13 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::WRITE_ATT>
548549

549550
std::string name = "";
550551
Datatype dtype = Datatype::UNDEFINED;
552+
/*
553+
* If true, this attribute changes across IO steps.
554+
* It should only be written in backends that support IO steps,
555+
* otherwise writing should be skipped.
556+
* The frontend is responsible for handling both situations.
557+
*/
558+
bool changesOverSteps = false;
551559
Attribute::resource resource;
552560
};
553561

include/openPMD/Streaming.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace openPMD
2020
enum class AdvanceStatus : unsigned char
2121
{
2222
OK, /* stream goes on */
23-
OVER /* stream is over */
23+
OVER, /* stream is over */
24+
RANDOMACCESS /* there is no stream, it will never be over */
2425
};
2526

2627
/**

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,11 @@ void ADIOS2IOHandlerImpl::writeAttribute(
815815
switch (attributeLayout())
816816
{
817817
case AttributeLayout::ByAdiosAttributes:
818+
if (parameters.changesOverSteps)
819+
{
820+
// cannot do this
821+
return;
822+
}
818823
switchType<detail::OldAttributeWriter>(
819824
parameters.dtype, this, writable, parameters);
820825
break;
@@ -829,6 +834,13 @@ void ADIOS2IOHandlerImpl::writeAttribute(
829834
auto prefix = filePositionToString(pos);
830835

831836
auto &filedata = getFileData(file, IfFileNotOpen::ThrowError);
837+
if (parameters.changesOverSteps &&
838+
filedata.streamStatus ==
839+
detail::BufferedActions::StreamStatus::NoStream)
840+
{
841+
// cannot do this
842+
return;
843+
}
832844
filedata.requireActiveStep();
833845
filedata.invalidateAttributesMap();
834846
m_dirty.emplace(std::move(file));
@@ -2800,6 +2812,7 @@ namespace detail
28002812
"[ADIOS2] Operation requires active step but no step is "
28012813
"left.");
28022814
case AdvanceStatus::OK:
2815+
case AdvanceStatus::RANDOMACCESS:
28032816
// pass
28042817
break;
28052818
}
@@ -3003,7 +3016,7 @@ namespace detail
30033016
m_IO.DefineAttribute<bool_representation>(
30043017
ADIOS2Defaults::str_usesstepsAttribute, 0);
30053018
flush({FlushLevel::UserFlush}, /* writeAttributes = */ false);
3006-
return AdvanceStatus::OK;
3019+
return AdvanceStatus::RANDOMACCESS;
30073020
}
30083021

30093022
/*

src/IO/ADIOS/CommonADIOS1IOHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,11 @@ template <typename ChildClass>
11291129
void CommonADIOS1IOHandlerImpl<ChildClass>::writeAttribute(
11301130
Writable *writable, Parameter<Operation::WRITE_ATT> const &parameters)
11311131
{
1132+
if (parameters.changesOverSteps)
1133+
{
1134+
// cannot do this
1135+
return;
1136+
}
11321137
if (m_handler->m_backendAccess == Access::READ_ONLY)
11331138
throw std::runtime_error(
11341139
"[ADIOS1] Writing an attribute in a file opened as read only is "

src/IO/HDF5/HDF5IOHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,11 @@ void HDF5IOHandlerImpl::writeDataset(
13281328
void HDF5IOHandlerImpl::writeAttribute(
13291329
Writable *writable, Parameter<Operation::WRITE_ATT> const &parameters)
13301330
{
1331+
if (parameters.changesOverSteps)
1332+
{
1333+
// cannot do this
1334+
return;
1335+
}
13311336
if (m_handler->m_backendAccess == Access::READ_ONLY)
13321337
throw std::runtime_error(
13331338
"[HDF5] Writing an attribute in a file opened as read only is not "

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,11 @@ void JSONIOHandlerImpl::writeDataset(
797797
void JSONIOHandlerImpl::writeAttribute(
798798
Writable *writable, Parameter<Operation::WRITE_ATT> const &parameter)
799799
{
800+
if (parameter.changesOverSteps)
801+
{
802+
// cannot do this
803+
return;
804+
}
800805
if (m_handler->m_backendAccess == Access::READ_ONLY)
801806
{
802807
throw std::runtime_error(

0 commit comments

Comments
 (0)