Skip to content

Commit 3ef31f0

Browse files
committed
Automatically use new attribute layout if using step-based encoding
Also automatically use steps if using new attribute layout
1 parent 0963158 commit 3ef31f0

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "openPMD/auxiliary/Option.hpp"
3333
#include "openPMD/backend/Writable.hpp"
3434
#include "openPMD/config.hpp"
35+
#include "openPMD/IterationEncoding.hpp"
3536

3637
#if openPMD_HAVE_ADIOS2
3738
# include <adios2.h>
@@ -198,6 +199,7 @@ class ADIOS2IOHandlerImpl
198199

199200
private:
200201
adios2::ADIOS m_ADIOS;
202+
IterationEncoding m_iterationEncoding = IterationEncoding::groupBased;
201203
/**
202204
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
203205
*/
@@ -1085,7 +1087,8 @@ namespace detail
10851087
detail::AttributeReader const m_attributeReader;
10861088
PreloadAdiosAttributes preloadAttributes;
10871089
using AttributeLayout = ADIOS2IOHandlerImpl::AttributeLayout;
1088-
AttributeLayout m_attributeLayout = AttributeLayout::ByAdiosAttributes;
1090+
AttributeLayout & m_attributeLayout;
1091+
IterationEncoding & m_iterationEncoding;
10891092

10901093
/*
10911094
* We call an attribute committed if the step during which it was

include/openPMD/IO/IOTask.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "openPMD/backend/Attribute.hpp"
2626
#include "openPMD/ChunkInfo.hpp"
2727
#include "openPMD/Dataset.hpp"
28+
#include "openPMD/IterationEncoding.hpp"
2829

2930
#include <memory>
3031
#include <map>
@@ -107,7 +108,8 @@ template<>
107108
struct OPENPMDAPI_EXPORT Parameter< Operation::CREATE_FILE > : public AbstractParameter
108109
{
109110
Parameter() = default;
110-
Parameter(Parameter const & p) : AbstractParameter(), name(p.name) {}
111+
Parameter(Parameter const & p) :
112+
AbstractParameter(), name(p.name), encoding(p.encoding) {}
111113

112114
std::unique_ptr< AbstractParameter >
113115
clone() const override
@@ -117,13 +119,15 @@ struct OPENPMDAPI_EXPORT Parameter< Operation::CREATE_FILE > : public AbstractPa
117119
}
118120

119121
std::string name = "";
122+
IterationEncoding encoding = IterationEncoding::groupBased;
120123
};
121124

122125
template<>
123126
struct OPENPMDAPI_EXPORT Parameter< Operation::OPEN_FILE > : public AbstractParameter
124127
{
125128
Parameter() = default;
126-
Parameter(Parameter const & p) : AbstractParameter(), name(p.name) {}
129+
Parameter(Parameter const & p) :
130+
AbstractParameter(), name(p.name), encoding(p.encoding) {}
127131

128132
std::unique_ptr< AbstractParameter >
129133
clone() const override
@@ -133,6 +137,7 @@ struct OPENPMDAPI_EXPORT Parameter< Operation::OPEN_FILE > : public AbstractPara
133137
}
134138

135139
std::string name = "";
140+
IterationEncoding encoding = IterationEncoding::groupBased;
136141
};
137142

138143
template<>

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ void ADIOS2IOHandlerImpl::createFile(
295295
VERIFY( success, "[ADIOS2] Could not create directory." );
296296
}
297297

298+
m_iterationEncoding = parameters.encoding;
298299
associateWithFile( writable, shared_name );
299300
this->m_dirty.emplace( shared_name );
300301
getFileData( shared_name ).m_mode = adios2::Mode::Write; // WORKAROUND
@@ -433,6 +434,7 @@ void ADIOS2IOHandlerImpl::openFile(
433434
writable->written = true;
434435
writable->abstractFilePosition = std::make_shared< ADIOS2FilePosition >( );
435436

437+
m_iterationEncoding = parameters.encoding;
436438
// enforce opening the file
437439
// lazy opening is deathly in parallel situations
438440
getFileData( file );
@@ -2056,6 +2058,7 @@ namespace detail
20562058
, m_readDataset( &impl )
20572059
, m_attributeReader()
20582060
, m_attributeLayout( impl.m_attributeLayout )
2061+
, m_iterationEncoding( impl.m_iterationEncoding )
20592062
, m_engineType( impl.m_engineType )
20602063
{
20612064
if( !m_IO )
@@ -2127,7 +2130,15 @@ namespace detail
21272130
"bp4", "bp3", "hdf5", "file"
21282131
};
21292132

2133+
// step/variable-based iteration encoding requires the new attribute
2134+
// layout
2135+
if( m_iterationEncoding == IterationEncoding::stepBased )
2136+
{
2137+
m_attributeLayout = AttributeLayout::ByAdiosVariables;
2138+
}
2139+
21302140
// set engine type
2141+
bool isStreaming = false;
21312142
{
21322143
// allow overriding through environment variable
21332144
m_engineType = auxiliary::getEnvString(
@@ -2142,6 +2153,7 @@ namespace detail
21422153
auto it = streamingEngines.find( m_engineType );
21432154
if( it != streamingEngines.end() )
21442155
{
2156+
isStreaming = true;
21452157
optimizeAttributesStreaming =
21462158
m_attributeLayout == AttributeLayout::ByAdiosAttributes;
21472159
streamStatus = StreamStatus::OutsideOfStep;
@@ -2153,16 +2165,34 @@ namespace detail
21532165
{
21542166
switch( m_mode )
21552167
{
2156-
case adios2::Mode::Read:
2157-
streamStatus = StreamStatus::Undecided;
2158-
delayOpeningTheFirstStep = m_attributeLayout ==
2159-
AttributeLayout::ByAdiosAttributes;
2168+
case adios2::Mode::Read:
2169+
/*
2170+
* File engines, read mode:
2171+
* Use of steps is dictated by what is detected in the
2172+
* file being read.
2173+
*/
2174+
streamStatus = StreamStatus::Undecided;
2175+
delayOpeningTheFirstStep = m_attributeLayout ==
2176+
AttributeLayout::ByAdiosAttributes;
2177+
break;
2178+
case adios2::Mode::Write:
2179+
/*
2180+
* File engines, write mode:
2181+
* Default for old layout is no steps.
2182+
* Default for new layout is to use steps.
2183+
*/
2184+
switch( m_attributeLayout )
2185+
{
2186+
case AttributeLayout::ByAdiosVariables:
2187+
streamStatus = StreamStatus::OutsideOfStep;
21602188
break;
2161-
case adios2::Mode::Write:
2189+
case AttributeLayout::ByAdiosAttributes:
21622190
streamStatus = StreamStatus::NoStream;
21632191
break;
2164-
default:
2165-
throw std::runtime_error( "Unreachable!" );
2192+
}
2193+
break;
2194+
default:
2195+
throw std::runtime_error( "Unreachable!" );
21662196
}
21672197
optimizeAttributesStreaming = false;
21682198
}
@@ -2200,8 +2230,7 @@ namespace detail
22002230
m_mode != adios2::Mode::Read )
22012231
{
22022232
bool tmp = _useAdiosSteps.json();
2203-
if( streamStatus == StreamStatus::OutsideOfStep &&
2204-
!bool( tmp ) )
2233+
if( isStreaming && !bool( tmp ) )
22052234
{
22062235
throw std::runtime_error(
22072236
"Cannot switch off steps for streaming engines." );

src/Iteration.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ Iteration::flushFileBased(std::string const& filename, uint64_t i)
259259
{
260260
Parameter< Operation::OPEN_FILE > fOpen;
261261
fOpen.name = filename;
262+
fOpen.encoding = IterationEncoding::fileBased;
262263
IOHandler->enqueue(IOTask(s, fOpen));
263264
flush();
264265

src/Series.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ Series::flushGroupBased( iterations_iterator begin, iterations_iterator end )
696696
{
697697
Parameter< Operation::CREATE_FILE > fCreate;
698698
fCreate.name = *m_name;
699+
fCreate.encoding = iterationEncoding();
699700
IOHandler->enqueue(IOTask(this, fCreate));
700701
}
701702

@@ -782,6 +783,7 @@ Series::readFileBased( )
782783
Parameter< Operation::OPEN_FILE > fOpen;
783784
Parameter< Operation::CLOSE_FILE > fClose;
784785
Parameter< Operation::READ_ATT > aRead;
786+
fOpen.encoding = iterationEncoding();
785787

786788
if( !auxiliary::directory_exists(IOHandler->directory) )
787789
throw no_such_file_error("Supplied directory is not valid: " + IOHandler->directory);
@@ -892,6 +894,7 @@ void
892894
Series::readGroupBased( bool do_init )
893895
{
894896
Parameter< Operation::OPEN_FILE > fOpen;
897+
fOpen.encoding = iterationEncoding();
895898
fOpen.name = *m_name;
896899
IOHandler->enqueue(IOTask(this, fOpen));
897900
IOHandler->flush();
@@ -1210,6 +1213,7 @@ Series::openIteration( uint64_t index, Iteration iteration )
12101213
{
12111214
// open the iteration's file again
12121215
Parameter< Operation::OPEN_FILE > fOpen;
1216+
fOpen.encoding = iterationEncoding();
12131217
fOpen.name = iterationFilename( index );
12141218
IOHandler->enqueue( IOTask( this, fOpen ) );
12151219

test/SerialIOTest.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,20 +3252,9 @@ TEST_CASE( "serial_iterator", "[serial][adios2]" )
32523252
void
32533253
stepBasedSingleIteration( std::string const & file )
32543254
{
3255-
std::string config = R"END(
3256-
{
3257-
"adios2":
3258-
{
3259-
"new_attribute_layout": true,
3260-
"engine":
3261-
{
3262-
"usesteps": true
3263-
}
3264-
}
3265-
})END";
32663255
constexpr Extent::value_type extent = 1000;
32673256
{
3268-
Series writeSeries( file, Access::CREATE, config );
3257+
Series writeSeries( file, Access::CREATE );
32693258
writeSeries.setIterationEncoding( IterationEncoding::stepBased );
32703259
auto iterations = writeSeries.writeIterations();
32713260
auto iteration = writeSeries.iterations[ 0 ];
@@ -3279,7 +3268,7 @@ stepBasedSingleIteration( std::string const & file )
32793268
}
32803269

32813270
{
3282-
Series readSeries( file, Access::READ_ONLY, config );
3271+
Series readSeries( file, Access::READ_ONLY );
32833272

32843273
auto E_x = readSeries.iterations[ 0 ].meshes[ "E" ][ "x" ];
32853274
REQUIRE( E_x.getDimensionality() == 1 );

0 commit comments

Comments
 (0)