Skip to content

Commit d05a222

Browse files
committed
Automatically use new attribute layout if using step-based encoding
Also automatically use steps if using new attribute layout ADIOS2 schema Automatically detect layout when reading Make automatic recognition of access mode more intelligent Previous commits uncovered an old bug ADIOS2: Use YYYYMMDD schema tag Also fix a bug in Parallel IO tests that I noticed Undo unnecessary whitespace changes
1 parent 9734cfe commit d05a222

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 5 additions & 2 deletions
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>
@@ -213,6 +214,7 @@ class ADIOS2IOHandlerImpl
213214

214215
private:
215216
adios2::ADIOS m_ADIOS;
217+
IterationEncoding m_iterationEncoding = IterationEncoding::groupBased;
216218
/**
217219
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
218220
*/
@@ -1018,6 +1020,7 @@ namespace detail
10181020
detail::AttributeReader const m_attributeReader;
10191021
PreloadAdiosAttributes preloadAttributes;
10201022
ADIOS2Schema::schema_t & m_schema;
1023+
IterationEncoding & m_iterationEncoding;
10211024

10221025
/*
10231026
* We call an attribute committed if the step during which it was
@@ -1270,7 +1273,7 @@ class ADIOS2IOHandler : public AbstractIOHandler
12701273
{
12711274
#if openPMD_HAVE_ADIOS2
12721275

1273-
friend class ADIOS2IOHandlerImpl;
1276+
friend class ADIOS2IOHandlerImpl;
12741277

12751278
private:
12761279
ADIOS2IOHandlerImpl m_impl;
@@ -1289,7 +1292,7 @@ friend class ADIOS2IOHandlerImpl;
12891292
}
12901293
catch( ... )
12911294
{
1292-
std::cerr << "[~ADIOS2IOHandler] An error occurred." << std::endl;
1295+
std::cerr << "[~ADIOS2IOHandler] An error occurred." << std::endl;
12931296
}
12941297
}
12951298

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ void ADIOS2IOHandlerImpl::createFile(
289289
VERIFY( success, "[ADIOS2] Could not create directory." );
290290
}
291291

292+
m_iterationEncoding = parameters.encoding;
292293
associateWithFile( writable, shared_name );
293294
this->m_dirty.emplace( shared_name );
294295
getFileData( shared_name ).m_mode = adios2::Mode::Write; // WORKAROUND
@@ -427,6 +428,7 @@ void ADIOS2IOHandlerImpl::openFile(
427428
writable->written = true;
428429
writable->abstractFilePosition = std::make_shared< ADIOS2FilePosition >( );
429430

431+
m_iterationEncoding = parameters.encoding;
430432
// enforce opening the file
431433
// lazy opening is deathly in parallel situations
432434
getFileData( file );
@@ -1931,6 +1933,7 @@ namespace detail
19311933
, m_readDataset( &impl )
19321934
, m_attributeReader()
19331935
, m_schema( impl.m_schema )
1936+
, m_iterationEncoding( impl.m_iterationEncoding )
19341937
, m_engineType( impl.m_engineType )
19351938
{
19361939
if( !m_IO )
@@ -2002,6 +2005,12 @@ namespace detail
20022005
"bp4", "bp3", "hdf5", "file"
20032006
};
20042007

2008+
// step/variable-based iteration encoding requires the new schema
2009+
if( m_iterationEncoding == IterationEncoding::stepBased )
2010+
{
2011+
m_schema = ADIOS2Schema::schema_2021_02_09;
2012+
}
2013+
20052014
// set engine type
20062015
bool isStreaming = false;
20072016
{

src/Iteration.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ Iteration::flushFileBased(std::string const& filename, uint64_t i)
224224
{
225225
Parameter< Operation::OPEN_FILE > fOpen;
226226
fOpen.name = filename;
227+
fOpen.encoding = IterationEncoding::fileBased;
227228
IOHandler()->enqueue(IOTask(s, fOpen));
228229
flush();
229230

src/Series.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ SeriesImpl::flushGroupBased( iterations_iterator begin, iterations_iterator end
649649
{
650650
Parameter< Operation::CREATE_FILE > fCreate;
651651
fCreate.name = *series.m_name;
652+
fCreate.encoding = iterationEncoding();
652653
IOHandler()->enqueue(IOTask(this, fCreate));
653654
}
654655

@@ -735,6 +736,7 @@ SeriesImpl::readFileBased( )
735736
Parameter< Operation::OPEN_FILE > fOpen;
736737
Parameter< Operation::CLOSE_FILE > fClose;
737738
Parameter< Operation::READ_ATT > aRead;
739+
fOpen.encoding = iterationEncoding();
738740

739741
if( !auxiliary::directory_exists(IOHandler()->directory) )
740742
throw no_such_file_error("Supplied directory is not valid: " + IOHandler()->directory);
@@ -847,6 +849,7 @@ SeriesImpl::readGroupBased( bool do_init )
847849
{
848850
auto & series = get();
849851
Parameter< Operation::OPEN_FILE > fOpen;
852+
fOpen.encoding = iterationEncoding();
850853
fOpen.name = *series.m_name;
851854
IOHandler()->enqueue(IOTask(this, fOpen));
852855
IOHandler()->flush();
@@ -1174,6 +1177,7 @@ SeriesImpl::openIteration( uint64_t index, Iteration iteration )
11741177
auto & series = get();
11751178
// open the iteration's file again
11761179
Parameter< Operation::OPEN_FILE > fOpen;
1180+
fOpen.encoding = iterationEncoding();
11771181
fOpen.name = iterationFilename( index );
11781182
IOHandler()->enqueue( IOTask( this, fOpen ) );
11791183

test/SerialIOTest.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,20 +3296,9 @@ TEST_CASE( "serial_iterator", "[serial][adios2]" )
32963296
void
32973297
stepBasedSingleIteration( std::string const & file )
32983298
{
3299-
std::string config = R"END(
3300-
{
3301-
"adios2":
3302-
{
3303-
"new_attribute_layout": true,
3304-
"engine":
3305-
{
3306-
"usesteps": true
3307-
}
3308-
}
3309-
})END";
33103299
constexpr Extent::value_type extent = 1000;
33113300
{
3312-
Series writeSeries( file, Access::CREATE, config );
3301+
Series writeSeries( file, Access::CREATE );
33133302
writeSeries.setIterationEncoding( IterationEncoding::stepBased );
33143303
auto iterations = writeSeries.writeIterations();
33153304
auto iteration = writeSeries.iterations[ 0 ];
@@ -3323,7 +3312,7 @@ stepBasedSingleIteration( std::string const & file )
33233312
}
33243313

33253314
{
3326-
Series readSeries( file, Access::READ_ONLY, config );
3315+
Series readSeries( file, Access::READ_ONLY );
33273316

33283317
auto E_x = readSeries.iterations[ 0 ].meshes[ "E" ][ "x" ];
33293318
REQUIRE( E_x.getDimensionality() == 1 );
@@ -3332,7 +3321,7 @@ stepBasedSingleIteration( std::string const & file )
33323321
readSeries.flush();
33333322
for( size_t i = 0; i < extent; ++i )
33343323
{
3335-
REQUIRE( chunk.get()[ i ] == i );
3324+
REQUIRE( chunk.get()[ i ] == int( i ) );
33363325
}
33373326
}
33383327
}
@@ -3349,20 +3338,9 @@ TEST_CASE( "stepBasedSingleIteration", "[serial][adios2]" )
33493338
void
33503339
stepBasedSeries( std::string const & file )
33513340
{
3352-
std::string config = R"END(
3353-
{
3354-
"adios2":
3355-
{
3356-
"new_attribute_layout": true,
3357-
"engine":
3358-
{
3359-
"usesteps": true
3360-
}
3361-
}
3362-
})END";
33633341
constexpr Extent::value_type extent = 1000;
33643342
{
3365-
Series writeSeries( file, Access::CREATE, config );
3343+
Series writeSeries( file, Access::CREATE );
33663344
if( writeSeries.backend() == "ADIOS1" )
33673345
{
33683346
return;
@@ -3381,7 +3359,7 @@ stepBasedSeries( std::string const & file )
33813359
}
33823360
}
33833361

3384-
Series readSeries( file, Access::READ_ONLY, config );
3362+
Series readSeries( file, Access::READ_ONLY );
33853363

33863364
size_t last_iteration_index = 0;
33873365
for( auto iteration : readSeries.readIterations() )
@@ -3393,7 +3371,7 @@ stepBasedSeries( std::string const & file )
33933371
iteration.close();
33943372
for( size_t i = 0; i < extent; ++i )
33953373
{
3396-
REQUIRE( chunk.get()[ i ] == iteration.iterationIndex );
3374+
REQUIRE( chunk.get()[ i ] == int( iteration.iterationIndex ) );
33973375
}
33983376
last_iteration_index = iteration.iterationIndex;
33993377
}
@@ -3406,6 +3384,7 @@ TEST_CASE( "stepBasedSeries", "[serial][adios2]" )
34063384
}
34073385
#endif
34083386

3387+
// @todo Upon switching to ADIOS2 2.7.0, test this the other way around also
34093388
void
34103389
iterate_nonstreaming_series( std::string const & file )
34113390
{

0 commit comments

Comments
 (0)