23 #include "openPMD/IO/AbstractIOHandler.hpp" 24 #include "openPMD/IO/AbstractIOHandlerImpl.hpp" 25 #include "openPMD/IO/AbstractIOHandlerImplCommon.hpp" 26 #include "openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp" 27 #include "openPMD/IO/ADIOS/ADIOS2FilePosition.hpp" 28 #include "openPMD/IO/ADIOS/ADIOS2PreloadAttributes.hpp" 29 #include "openPMD/IO/IOTask.hpp" 30 #include "openPMD/IO/InvalidatableFile.hpp" 31 #include "openPMD/auxiliary/JSON.hpp" 32 #include "openPMD/auxiliary/Option.hpp" 33 #include "openPMD/backend/Writable.hpp" 34 #include "openPMD/config.hpp" 35 #include "openPMD/IterationEncoding.hpp" 37 #if openPMD_HAVE_ADIOS2 43 #include <nlohmann/json.hpp> 52 #include <unordered_map> 59 #if openPMD_HAVE_ADIOS2 61 class ADIOS2IOHandler;
85 namespace ADIOS2Schema
87 using schema_t = uint64_t;
91 constexpr schema_t schema_0000_00_00 = 00000000;
95 constexpr schema_t schema_2021_02_09 = 20210209;
97 enum class SupportedSchema : char
103 using SupportedSchema = ADIOS2Schema::SupportedSchema;
123 static constexpr
bool ADIOS2_DEBUG_MODE =
false;
133 nlohmann::json config,
134 std::string engineType );
136 #endif // openPMD_HAVE_MPI 140 nlohmann::json config,
141 std::string engineType );
146 std::future< void > flush( )
override;
224 adios2::Mode adios2AccessMode( std::string
const & fullPath );
227 adios2::ADIOS m_ADIOS;
236 std::string m_engineType;
237 ADIOS2Schema::schema_t m_schema = ADIOS2Schema::schema_0000_00_00;
239 enum class UseSpan : char
246 UseSpan m_useSpanBasedPutByDefault = UseSpan::Auto;
248 enum class AttributeLayout : char
254 inline SupportedSchema schema()
const 258 case ADIOS2Schema::schema_0000_00_00:
259 return SupportedSchema::s_0000_00_00;
260 case ADIOS2Schema::schema_2021_02_09:
261 return SupportedSchema::s_2021_02_09;
263 throw std::runtime_error(
264 "[ADIOS2] Encountered unsupported schema version: " +
265 std::to_string( m_schema ) );
269 inline AttributeLayout attributeLayout()
const 273 case SupportedSchema::s_0000_00_00:
274 return AttributeLayout::ByAdiosAttributes;
275 case SupportedSchema::s_2021_02_09:
276 return AttributeLayout::ByAdiosVariables;
278 throw std::runtime_error(
"Unreachable!" );
281 struct ParameterizedOperator
284 adios2::Params params;
287 std::vector< ParameterizedOperator > defaultOperators;
293 init( nlohmann::json config );
295 template<
typename Key >
299 if( cfg.
json().is_object() && cfg.
json().contains( key ) )
309 template<
typename Key >
313 return config< Key >( std::forward< Key >( key ), m_config );
354 std::unique_ptr< detail::BufferedActions >
357 std::map< std::string, adios2::Operator > m_operators;
362 filePositionToString( std::shared_ptr< ADIOS2FilePosition > )
override;
364 std::shared_ptr< ADIOS2FilePosition >
365 extendFilePosition( std::shared_ptr< ADIOS2FilePosition >
const & pos,
366 std::string extend )
override;
371 getCompressionOperator( std::string
const & compression );
377 std::string nameOfVariable(
Writable * writable );
388 std::string nameOfAttribute(
Writable * writable, std::string attribute );
394 ADIOS2FilePosition::GD groupOrDataset(
Writable * );
396 enum class IfFileNotOpen : bool
403 getFileData( InvalidatableFile file, IfFileNotOpen );
405 void dropFileData( InvalidatableFile file );
415 template <
typename T >
416 adios2::Variable< T > verifyDataset( Offset
const & offset,
417 Extent
const & extent, adios2::IO & IO,
418 std::string
const & var );
425 namespace ADIOS2Defaults
427 using const_str =
char const *
const;
428 constexpr const_str str_engine =
"engine";
429 constexpr const_str str_type =
"type";
430 constexpr const_str str_params =
"parameters";
431 constexpr const_str str_usesteps =
"usesteps";
432 constexpr const_str str_usesstepsAttribute =
"__openPMD_internal/useSteps";
433 constexpr const_str str_adios2Schema =
434 "__openPMD_internal/openPMD2_adios2_schema";
435 constexpr const_str str_isBooleanOldLayout =
"__is_boolean__";
436 constexpr const_str str_isBooleanNewLayout =
437 "__openPMD_internal/is_boolean";
452 template <
typename T >
453 void operator( )(
BufferedGet & bp, adios2::IO & IO,
454 adios2::Engine & engine,
455 std::string
const & fileName );
457 std::string errorMsg =
"ADIOS2: readDataset()";
462 template<
typename T >
467 std::shared_ptr< Attribute::resource > resource );
469 template<
int n,
typename... Params >
471 operator()( Params &&... );
476 template<
typename T >
484 template<
int n,
typename... Params >
486 operator()( Params &&... );
491 template<
typename T >
497 std::shared_ptr< Attribute::resource > resource );
499 template <
int n,
typename... Params >
500 Datatype operator( )( Params &&... );
505 template <
typename T >
512 template <
int n,
typename... Params >
void operator( )( Params &&... );
522 template <
typename T >
527 std::string errorMsg =
"ADIOS2: openDataset()";
538 template <
typename T >
539 void operator( )(
BufferedPut & bp, adios2::IO & IO,
540 adios2::Engine & engine );
542 template <
int n,
typename... Params >
void operator( )( Params &&... );
562 template <
typename T >
565 std::string
const & name,
566 std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator >
const &
568 adios2::Dims
const & shape = adios2::Dims(),
569 adios2::Dims
const & start = adios2::Dims(),
570 adios2::Dims
const & count = adios2::Dims(),
571 bool const constantDims = false );
573 std::string errorMsg =
"ADIOS2: defineVariable()";
578 template <
typename T >
582 adios2::Engine & engine,
583 std::string
const & varName );
585 template <
int n,
typename... Params >
586 void operator( )( Params &&... );
597 template<
typename T >
610 std::shared_ptr< Attribute::resource > resource );
615 adios2::Engine & engine,
623 std::shared_ptr< Attribute::resource > resource );
632 auto attr = IO.InquireAttribute<
T >( name );
637 std::vector< T > data = attr.Data();
638 if( data.size() != 1 )
642 return data[ 0 ] == val;
652 std::complex< long double > )
654 throw std::runtime_error(
655 "[ADIOS2] Internal error: no support for long double complex attribute types" );
662 std::shared_ptr< Attribute::resource > )
664 throw std::runtime_error(
665 "[ADIOS2] Internal error: no support for long double complex attribute types" );
673 std::complex< long double > )
675 throw std::runtime_error(
676 "[ADIOS2] Internal error: no support for long double complex attribute types" );
683 std::shared_ptr< Attribute::resource > )
685 throw std::runtime_error(
686 "[ADIOS2] Internal error: no support for long double complex attribute types" );
691 adios2::IO &, std::string, std::complex< long double > )
693 throw std::runtime_error(
694 "[ADIOS2] Internal error: no support for long double complex attribute types" );
704 const std::vector< std::complex< long double > > & )
706 throw std::runtime_error(
707 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
714 std::shared_ptr< Attribute::resource > )
716 throw std::runtime_error(
717 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
725 const std::vector< std::complex< long double > > & )
727 throw std::runtime_error(
728 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
735 std::shared_ptr< Attribute::resource > )
737 throw std::runtime_error(
738 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
745 std::vector< std::complex< long double > > )
747 throw std::runtime_error(
748 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
758 const std::vector< T > & value );
764 std::shared_ptr< Attribute::resource > resource );
769 adios2::Engine & engine,
771 const std::vector< T > & value );
777 std::shared_ptr< Attribute::resource > resource );
783 std::vector< T > val )
785 auto attr = IO.InquireAttribute<
T >( name );
790 std::vector< T > data = attr.Data();
791 if( data.size() != val.size() )
795 for(
size_t i = 0; i < val.size(); ++i )
797 if( data[ i ] != val[ i ] )
813 const std::vector< std::string > & value );
819 std::shared_ptr< Attribute::resource > resource );
824 adios2::Engine & engine,
826 const std::vector< std::string > & vec );
832 std::shared_ptr< Attribute::resource > resource );
838 std::vector< std::string > val )
840 auto attr = IO.InquireAttribute< std::string >( name );
845 std::vector< std::string > data = attr.Data();
846 if( data.size() != val.size() )
850 for(
size_t i = 0; i < val.size(); ++i )
852 if( data[ i ] != val[ i ] )
861 template <
typename T,
size_t n >
868 const std::array< T, n > & value );
874 std::shared_ptr< Attribute::resource > resource );
879 adios2::Engine & engine,
881 const std::array< T, n > & value );
887 std::shared_ptr< Attribute::resource > resource );
893 std::array< T, n > val )
895 auto attr = IO.InquireAttribute<
T >( name );
900 std::vector< T > data = attr.Data();
901 if( data.size() != n )
905 for(
size_t i = 0; i < n; ++i )
907 if( data[ i ] != val[ i ] )
918 using rep = detail::bool_representation;
921 oldCreateAttribute( adios2::IO & IO, std::string name,
bool value );
927 std::shared_ptr< Attribute::resource > resource );
932 adios2::Engine & engine,
940 std::shared_ptr< Attribute::resource > resource );
943 static constexpr rep toRep(
bool b )
949 static constexpr
bool fromRep( rep r )
955 attributeUnchanged( adios2::IO & IO, std::string name,
bool val )
957 auto attr = IO.InquireAttribute< rep >( name );
962 std::vector< rep > data = attr.Data();
963 if( data.size() != 1 )
967 return data[ 0 ] == toRep( val );
1030 Attribute::resource resource;
1031 std::vector< char > bufferForVecString;
1038 virtual void *update() = 0;
1042 template<
typename T >
1045 adios2::detail::Span< T > span;
1049 void *update()
override;
1088 adios2::ADIOS & m_ADIOS;
1094 std::vector< std::unique_ptr< BufferedAction > >
m_buffer;
1119 adios2::Mode m_mode;
1139 std::set< std::string > uncommittedAttributes;
1151 bool optimizeAttributesStreaming =
false;
1153 using AttributeMap_t = std::map< std::string, adios2::Params >;
1166 adios2::Engine & getEngine( );
1167 adios2::Engine & requireActiveStep( );
1169 template <
typename BA >
void enqueue( BA && ba );
1171 template <
typename BA >
void enqueue( BA && ba, decltype( m_buffer ) & );
1189 template<
typename F >
1193 F && performPutsGets,
1194 bool writeAttributes,
1195 bool flushUnconditionally );
1203 flush(
FlushLevel,
bool writeAttributes =
false );
1219 AttributeMap_t
const &
1220 availableAttributes();
1222 std::vector< std::string >
1223 availableAttributesPrefixed( std::string
const & prefix );
1229 invalidateAttributesMap();
1231 AttributeMap_t
const &
1232 availableVariables();
1234 std::vector< std::string >
1235 availableVariablesPrefixed( std::string
const & prefix );
1241 invalidateVariablesMap();
1249 std::string m_engineType;
1274 enum class StreamStatus
1339 StreamStatus streamStatus = StreamStatus::OutsideOfStep;
1340 adios2::StepStatus m_lastStepStatus = adios2::StepStatus::OK;
1347 bool delayOpeningTheFirstStep =
false;
1367 bool finalized =
false;
1369 inline SupportedSchema schema()
const 1371 return m_impl->schema();
1377 using AttributeLayout = ADIOS2IOHandlerImpl::AttributeLayout;
1378 inline AttributeLayout attributeLayout()
const 1380 return m_impl->attributeLayout();
1385 #endif // openPMD_HAVE_ADIOS2 1390 #if openPMD_HAVE_ADIOS2 1405 catch( std::exception
const & ex )
1407 std::cerr <<
"[~ADIOS2IOHandler] An error occurred: " << ex.what() << std::endl;
1411 std::cerr <<
"[~ADIOS2IOHandler] An error occurred." << std::endl;
1419 #if openPMD_HAVE_MPI 1425 nlohmann::json options,
1426 std::string engineType );
1433 nlohmann::json options,
1434 std::string engineType );
1438 std::future< void > flush( )
override;
Definition: ADIOS2IOHandler.hpp:65
Wrapper around a shared pointer to:
Definition: InvalidatableFile.hpp:45
Definition: ADIOS2IOHandler.hpp:576
Definition: IOTask.hpp:541
Definition: ADIOS2IOHandler.hpp:1036
std::map< unsigned, std::unique_ptr< I_UpdateSpan > > m_updateSpans
The base pointer of an ADIOS2 span might change after reallocations.
Definition: ADIOS2IOHandler.hpp:1128
Definition: ADIOS2IOHandler.hpp:1017
Definition: ADIOS2IOHandler.hpp:474
Definition: ADIOS2IOHandler.hpp:489
Access
File access mode to use during IO.
Definition: Access.hpp:28
Definition: IOTask.hpp:158
Definition: ADIOS2IOHandler.hpp:545
Definition: IOTask.hpp:242
Definition: IOTask.hpp:337
std::string m_file
The full path to the file created on disk, including the containing directory and the file extension...
Definition: ADIOS2IOHandler.hpp:1068
Definition: ADIOS2IOHandler.hpp:105
Definition: ADIOS2IOHandler.hpp:1057
FlushLevel
Determine what items should be flushed upon Series::flush()
Definition: AbstractIOHandler.hpp:63
Definition: ADIOS2IOHandler.hpp:1001
Definition: ADIOS2IOHandler.cpp:669
AdvanceStatus
In step-based mode (i.e.
Definition: Streaming.hpp:20
Definition: ADIOS2IOHandler.hpp:75
AdvanceMode
In step-based mode (i.e.
Definition: Streaming.hpp:33
std::vector< std::unique_ptr< BufferedAction > > m_buffer
The default queue for deferred actions.
Definition: ADIOS2IOHandler.hpp:1094
Definition: ADIOS2IOHandler.hpp:1009
std::string const m_IOName
ADIOS requires giving names to instances of adios2::IO.
Definition: ADIOS2IOHandler.hpp:1087
Definition: ADIOS2IOHandler.hpp:993
Definition: ADIOS2IOHandler.hpp:1026
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Definition: IOTask.hpp:135
Definition: Container.cpp:51
Definition: IOTask.hpp:172
Definition: IOTask.hpp:460
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:98
Simple Option type based on variantSrc::variant.
Definition: Option.hpp:47
Public definitions of openPMD-api.
Definition: Date.cpp:29
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
Definition: IOTask.hpp:204
Definition: ADIOS2IOHandler.hpp:1388
Definition: IOTask.hpp:382
Definition: ADIOS2IOHandler.hpp:530
std::string backendName() const override
The currently used backend.
Definition: ADIOS2IOHandler.hpp:1436
Definition: IOTask.hpp:523
Class that is responsible for scheduling and buffering openPMD attribute loads from ADIOS2...
Definition: ADIOS2PreloadAttributes.hpp:63
std::vector< BufferedAttributeRead > m_attributeReads
Definition: ADIOS2IOHandler.hpp:1111
Definition: ADIOS2IOHandler.hpp:503
Extend nlohmann::json with tracing of which keys have been accessed by operator[]().
Definition: JSON.hpp:52
IterationEncoding
Encoding scheme of an Iterations Series'.
Definition: IterationEncoding.hpp:32
Definition: Writable.hpp:45
static bool attributeUnchanged(adios2::IO &IO, std::string name, T val)
Is the attribute given by parameters name and val already defined exactly in that way within the give...
Definition: ADIOS2IOHandler.hpp:630
Definition: ADIOS2IOHandler.hpp:515
Definition: ADIOS2IOHandler.hpp:444
Definition: IOTask.hpp:117
Definition: IOTask.hpp:564
Definition: IOTask.hpp:411
std::vector< std::unique_ptr< BufferedAction > > m_alreadyEnqueued
This contains deferred actions that have already been enqueued into ADIOS2, but not yet performed in ...
Definition: ADIOS2IOHandler.hpp:1118
std::map< std::string, BufferedAttributeWrite > m_attributeWrites
Buffer for attributes to be written in the new (variable-based) attribute layout. ...
Definition: ADIOS2IOHandler.hpp:1105
Definition: IOTask.hpp:316
Definition: IOTask.hpp:188
Definition: ADIOS2IOHandler.hpp:1043
Definition: IOTask.hpp:476
Definition: IOTask.hpp:275
nlohmann::json & json()
Access the underlying JSON value.
Definition: JSON.hpp:64
Definition: IOTask.hpp:429
Definition: ADIOS2IOHandler.hpp:72
Definition: ADIOS2IOHandler.hpp:979
Definition: IOTask.hpp:495
Definition: ADIOS2IOHandler.hpp:460
Definition: IOTask.hpp:300
Definition: IOTask.hpp:226
Definition: IOTask.hpp:353
Definition: IOTask.hpp:258