Skip to content

Commit 3bf4aec

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 f32c4d2 commit 3bf4aec

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
@@ -650,6 +650,7 @@ SeriesImpl::flushGroupBased( iterations_iterator begin, iterations_iterator end
650650
{
651651
Parameter< Operation::CREATE_FILE > fCreate;
652652
fCreate.name = series.m_name;
653+
fCreate.encoding = iterationEncoding();
653654
IOHandler()->enqueue(IOTask(this, fCreate));
654655
}
655656

@@ -736,6 +737,7 @@ SeriesImpl::readFileBased( )
736737
Parameter< Operation::OPEN_FILE > fOpen;
737738
Parameter< Operation::CLOSE_FILE > fClose;
738739
Parameter< Operation::READ_ATT > aRead;
740+
fOpen.encoding = iterationEncoding();
739741

740742
if( !auxiliary::directory_exists(IOHandler()->directory) )
741743
throw no_such_file_error("Supplied directory is not valid: " + IOHandler()->directory);
@@ -849,6 +851,7 @@ SeriesImpl::readGroupBased( bool do_init )
849851
auto & series = get();
850852
Parameter< Operation::OPEN_FILE > fOpen;
851853
fOpen.name = series.m_name;
854+
fOpen.encoding = iterationEncoding();
852855
IOHandler()->enqueue(IOTask(this, fOpen));
853856
IOHandler()->flush();
854857

@@ -1175,6 +1178,7 @@ SeriesImpl::openIteration( uint64_t index, Iteration iteration )
11751178
auto & series = get();
11761179
// open the iteration's file again
11771180
Parameter< Operation::OPEN_FILE > fOpen;
1181+
fOpen.encoding = iterationEncoding();
11781182
fOpen.name = iterationFilename( index );
11791183
IOHandler()->enqueue( IOTask( this, fOpen ) );
11801184

test/SerialIOTest.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,20 +3307,9 @@ TEST_CASE( "serial_iterator", "[serial][adios2]" )
33073307
void
33083308
stepBasedSingleIteration( std::string const & file )
33093309
{
3310-
std::string config = R"END(
3311-
{
3312-
"adios2":
3313-
{
3314-
"new_attribute_layout": true,
3315-
"engine":
3316-
{
3317-
"usesteps": true
3318-
}
3319-
}
3320-
})END";
33213310
constexpr Extent::value_type extent = 1000;
33223311
{
3323-
Series writeSeries( file, Access::CREATE, config );
3312+
Series writeSeries( file, Access::CREATE );
33243313
writeSeries.setIterationEncoding( IterationEncoding::stepBased );
33253314
auto iterations = writeSeries.writeIterations();
33263315
auto iteration = writeSeries.iterations[ 0 ];
@@ -3334,7 +3323,7 @@ stepBasedSingleIteration( std::string const & file )
33343323
}
33353324

33363325
{
3337-
Series readSeries( file, Access::READ_ONLY, config );
3326+
Series readSeries( file, Access::READ_ONLY );
33383327

33393328
auto E_x = readSeries.iterations[ 0 ].meshes[ "E" ][ "x" ];
33403329
REQUIRE( E_x.getDimensionality() == 1 );
@@ -3343,7 +3332,7 @@ stepBasedSingleIteration( std::string const & file )
33433332
readSeries.flush();
33443333
for( size_t i = 0; i < extent; ++i )
33453334
{
3346-
REQUIRE( chunk.get()[ i ] == i );
3335+
REQUIRE( chunk.get()[ i ] == int( i ) );
33473336
}
33483337
}
33493338
}
@@ -3360,20 +3349,9 @@ TEST_CASE( "stepBasedSingleIteration", "[serial][adios2]" )
33603349
void
33613350
stepBasedSeries( std::string const & file )
33623351
{
3363-
std::string config = R"END(
3364-
{
3365-
"adios2":
3366-
{
3367-
"new_attribute_layout": true,
3368-
"engine":
3369-
{
3370-
"usesteps": true
3371-
}
3372-
}
3373-
})END";
33743352
constexpr Extent::value_type extent = 1000;
33753353
{
3376-
Series writeSeries( file, Access::CREATE, config );
3354+
Series writeSeries( file, Access::CREATE );
33773355
if( writeSeries.backend() == "ADIOS1" )
33783356
{
33793357
return;
@@ -3392,7 +3370,7 @@ stepBasedSeries( std::string const & file )
33923370
}
33933371
}
33943372

3395-
Series readSeries( file, Access::READ_ONLY, config );
3373+
Series readSeries( file, Access::READ_ONLY );
33963374

33973375
size_t last_iteration_index = 0;
33983376
for( auto iteration : readSeries.readIterations() )
@@ -3404,7 +3382,7 @@ stepBasedSeries( std::string const & file )
34043382
iteration.close();
34053383
for( size_t i = 0; i < extent; ++i )
34063384
{
3407-
REQUIRE( chunk.get()[ i ] == iteration.iterationIndex );
3385+
REQUIRE( chunk.get()[ i ] == int( iteration.iterationIndex ) );
34083386
}
34093387
last_iteration_index = iteration.iterationIndex;
34103388
}
@@ -3417,6 +3395,7 @@ TEST_CASE( "stepBasedSeries", "[serial][adios2]" )
34173395
}
34183396
#endif
34193397

3398+
// @todo Upon switching to ADIOS2 2.7.0, test this the other way around also
34203399
void
34213400
iterate_nonstreaming_series( std::string const & file )
34223401
{

0 commit comments

Comments
 (0)