Skip to content

Commit a32c0dd

Browse files
committed
Enable openPath(path="") in ADIOS1 backend
1 parent 6e38bf8 commit a32c0dd

File tree

7 files changed

+97
-24
lines changed

7 files changed

+97
-24
lines changed

include/openPMD/backend/Attributable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class Attributable
153153

154154
OPENPMD_protected:
155155
void flushAttributes();
156-
void readAttributes();
156+
void readAttributes( bool reread = false );
157157

158158
/** Retrieve the value of a floating point Attribute of user-defined precision with ensured type-safety.
159159
*

src/IO/ADIOS/ADIOS1IOHandler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ ADIOS1IOHandlerImpl::flush()
9595
case O::CREATE_PATH:
9696
createPath(i.writable, deref_dynamic_cast< Parameter< O::CREATE_PATH > >(i.parameter.get()));
9797
break;
98+
case O::OPEN_PATH:
99+
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
100+
break;
98101
case O::CREATE_DATASET:
99102
createDataset(i.writable, deref_dynamic_cast< Parameter< O::CREATE_DATASET > >(i.parameter.get()));
100103
break;
@@ -129,9 +132,6 @@ ADIOS1IOHandlerImpl::flush()
129132
case O::EXTEND_DATASET:
130133
extendDataset(i.writable, deref_dynamic_cast< Parameter< O::EXTEND_DATASET > >(i.parameter.get()));
131134
break;
132-
case O::OPEN_PATH:
133-
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
134-
break;
135135
case O::CLOSE_PATH:
136136
closePath(i.writable, deref_dynamic_cast< Parameter< O::CLOSE_PATH > >(i.parameter.get()));
137137
break;
@@ -240,6 +240,7 @@ ADIOS1IOHandler::enqueue(IOTask const& i)
240240
{
241241
case Operation::CREATE_FILE:
242242
case Operation::CREATE_PATH:
243+
case Operation::OPEN_PATH:
243244
case Operation::CREATE_DATASET:
244245
case Operation::OPEN_FILE:
245246
case Operation::WRITE_ATT:

src/IO/ADIOS/CommonADIOS1IOHandler.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,13 @@ CommonADIOS1IOHandlerImpl::openPath(
677677
{
678678
/* Sanitize path */
679679
std::string path = parameters.path;
680-
if( auxiliary::starts_with(path, '/') )
681-
path = auxiliary::replace_first(path, "/", "");
682-
if( !auxiliary::ends_with(path, '/') )
683-
path += '/';
680+
if( !path.empty() )
681+
{
682+
if( auxiliary::starts_with(path, '/') )
683+
path = auxiliary::replace_first(path, "/", "");
684+
if( !auxiliary::ends_with(path, '/') )
685+
path += '/';
686+
}
684687

685688
writable->written = true;
686689
writable->abstractFilePosition = std::make_shared< ADIOS1FilePosition >(path);

src/IO/ADIOS/ParallelADIOS1IOHandler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ ParallelADIOS1IOHandlerImpl::flush()
119119
case O::CREATE_PATH:
120120
createPath(i.writable, deref_dynamic_cast< Parameter< O::CREATE_PATH > >(i.parameter.get()));
121121
break;
122+
case O::OPEN_PATH:
123+
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
124+
break;
122125
case O::CREATE_DATASET:
123126
createDataset(i.writable, deref_dynamic_cast< Parameter< O::CREATE_DATASET > >(i.parameter.get()));
124127
break;
@@ -151,9 +154,6 @@ ParallelADIOS1IOHandlerImpl::flush()
151154
case O::EXTEND_DATASET:
152155
extendDataset(i.writable, deref_dynamic_cast< Parameter< O::EXTEND_DATASET > >(i.parameter.get()));
153156
break;
154-
case O::OPEN_PATH:
155-
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
156-
break;
157157
case O::CLOSE_PATH:
158158
closePath(i.writable, deref_dynamic_cast< Parameter< O::CLOSE_PATH > >(i.parameter.get()));
159159
break;
@@ -262,6 +262,7 @@ ParallelADIOS1IOHandler::enqueue(IOTask const& i)
262262
{
263263
case Operation::CREATE_FILE:
264264
case Operation::CREATE_PATH:
265+
case Operation::OPEN_PATH:
265266
case Operation::CREATE_DATASET:
266267
case Operation::OPEN_FILE:
267268
case Operation::WRITE_ATT:

src/Series.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,10 @@ Series::read()
10271027
IOHandler->enqueue(IOTask(&iterations, pOpen));
10281028

10291029
readAttributes();
1030-
iterations.readAttributes();
1030+
/*
1031+
* iterationIndex changes over steps, so reread that.
1032+
*/
1033+
iterations.readAttributes( /* reread = */ true );
10311034

10321035
/* obtain all paths inside the basepath (i.e. all iterations) */
10331036
switch(*m_iterationEncoding)
@@ -1056,10 +1059,12 @@ Series::read()
10561059
case IE::stepBased:
10571060
{
10581061
Parameter< Operation::READ_ATT > aRead;
1059-
aRead.name = "iterationIndex";
1060-
IOHandler->enqueue( IOTask( &iterations, aRead ) );
1061-
IOHandler->flush();
1062-
uint64_t index = Attribute( *aRead.resource ).get< uint64_t >();
1062+
uint64_t index = 0;
1063+
if( iterations.containsAttribute( "iterationIndex" ) )
1064+
{
1065+
index = iterations.getAttribute( "iterationIndex" )
1066+
.get< uint64_t >();
1067+
}
10631068
Iteration & i = iterations[ index ];
10641069
pOpen.path = "";
10651070
IOHandler->enqueue( IOTask( &i, pOpen ) );

src/backend/Attributable.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,31 @@ Attributable::flushAttributes()
142142
}
143143

144144
void
145-
Attributable::readAttributes()
145+
Attributable::readAttributes( bool reread )
146146
{
147147
Parameter< Operation::LIST_ATTS > aList;
148148
IOHandler->enqueue(IOTask(this, aList));
149149
IOHandler->flush();
150150
std::vector< std::string > written_attributes = attributes();
151151

152-
/* std::set_difference requires sorted ranges */
153-
std::sort(aList.attributes->begin(), aList.attributes->end());
154-
std::sort(written_attributes.begin(), written_attributes.end());
155-
156152
std::set< std::string > tmpAttributes;
157-
std::set_difference(aList.attributes->begin(), aList.attributes->end(),
158-
written_attributes.begin(), written_attributes.end(),
159-
std::inserter(tmpAttributes, tmpAttributes.begin()));
153+
if( reread )
154+
{
155+
tmpAttributes = std::set< std::string >(
156+
aList.attributes->begin(),
157+
aList.attributes->end() );
158+
}
159+
else
160+
{
161+
/* std::set_difference requires sorted ranges */
162+
std::sort(aList.attributes->begin(), aList.attributes->end());
163+
std::sort(written_attributes.begin(), written_attributes.end());
164+
165+
std::set_difference(
166+
aList.attributes->begin(), aList.attributes->end(),
167+
written_attributes.begin(), written_attributes.end(),
168+
std::inserter(tmpAttributes, tmpAttributes.begin()));
169+
}
160170

161171
using DT = Datatype;
162172
Parameter< Operation::READ_ATT > aRead;

test/SerialIOTest.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,59 @@ TEST_CASE( "serial_iterator", "[serial][adios2]" )
32173217
}
32183218
}
32193219

3220+
void
3221+
stepBasedSingleIteration( std::string const & file )
3222+
{
3223+
std::string config = R"END(
3224+
{
3225+
"adios2":
3226+
{
3227+
"new_attribute_layout": true,
3228+
"engine":
3229+
{
3230+
"usesteps": true
3231+
}
3232+
}
3233+
})END";
3234+
constexpr Extent::value_type extent = 1000;
3235+
{
3236+
Series writeSeries( file, Access::CREATE, config );
3237+
writeSeries.setIterationEncoding( IterationEncoding::stepBased );
3238+
auto iterations = writeSeries.writeIterations();
3239+
auto iteration = writeSeries.iterations[ 0 ];
3240+
auto E_x = iteration.meshes[ "E" ][ "x" ];
3241+
E_x.resetDataset(
3242+
openPMD::Dataset( openPMD::Datatype::INT, { 1000 } ) );
3243+
std::vector< int > data( 1000, 0 );
3244+
std::iota( data.begin(), data.end(), 0 );
3245+
E_x.storeChunk( data, { 0 }, { 1000 } );
3246+
writeSeries.flush();
3247+
}
3248+
3249+
{
3250+
Series readSeries( file, Access::READ_ONLY, config );
3251+
3252+
auto E_x = readSeries.iterations[ 0 ].meshes[ "E" ][ "x" ];
3253+
REQUIRE( E_x.getDimensionality() == 1 );
3254+
REQUIRE( E_x.getExtent()[ 0 ] == extent );
3255+
auto chunk = E_x.loadChunk< int >( { 0 }, { extent } );
3256+
readSeries.flush();
3257+
for( size_t i = 0; i < extent; ++i )
3258+
{
3259+
REQUIRE( chunk.get()[ i ] == i );
3260+
}
3261+
}
3262+
}
3263+
3264+
TEST_CASE( "stepBasedSingleIteration", "[serial][adios2]" )
3265+
{
3266+
stepBasedSingleIteration("../samples/stepBasedSingleIteration.bp");
3267+
// for( auto const & t : getFileExtensions() )
3268+
// {
3269+
// stepBasedSingleIteration( "../samples/stepBasedSingleIteration." + t );
3270+
// }
3271+
}
3272+
32203273
#if openPMD_HAVE_ADIOS2
32213274
void
32223275
stepBasedSeries( std::string const & file )

0 commit comments

Comments
 (0)