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/IOTask.hpp" 29 #include "openPMD/IO/InvalidatableFile.hpp" 30 #include "openPMD/auxiliary/JSON.hpp" 31 #include "openPMD/auxiliary/Option.hpp" 32 #include "openPMD/backend/Writable.hpp" 33 #include "openPMD/config.hpp" 35 #if openPMD_HAVE_ADIOS2 41 #include <nlohmann/json.hpp> 50 #include <unordered_map> 57 #if openPMD_HAVE_ADIOS2 59 class ADIOS2IOHandler;
92 static constexpr
bool ADIOS2_DEBUG_MODE =
false;
102 nlohmann::json config,
103 std::string engineType );
105 #endif // openPMD_HAVE_MPI 109 nlohmann::json config,
110 std::string engineType );
115 std::future< void > flush( )
override;
190 adios2::Mode adios2AccessMode( std::string
const & fullPath );
193 adios2::ADIOS m_ADIOS;
197 std::string m_engineType;
199 struct ParameterizedOperator
202 adios2::Params params;
205 std::vector< ParameterizedOperator > defaultOperators;
211 init( nlohmann::json config );
213 template<
typename Key >
217 if( cfg.
json().is_object() && cfg.
json().contains( key ) )
227 template<
typename Key >
231 return config< Key >( std::forward< Key >( key ), m_config );
272 std::unique_ptr< detail::BufferedActions >
275 std::map< std::string, adios2::Operator > m_operators;
280 filePositionToString( std::shared_ptr< ADIOS2FilePosition > )
override;
282 std::shared_ptr< ADIOS2FilePosition >
283 extendFilePosition( std::shared_ptr< ADIOS2FilePosition >
const & pos,
284 std::string extend )
override;
289 getCompressionOperator( std::string
const & compression );
295 std::string nameOfVariable(
Writable * writable );
306 std::string nameOfAttribute(
Writable * writable, std::string attribute );
312 ADIOS2FilePosition::GD groupOrDataset(
Writable * );
316 void dropFileData( InvalidatableFile file );
326 template <
typename T >
327 adios2::Variable< T > verifyDataset( Offset
const & offset,
328 Extent
const & extent, adios2::IO & IO,
329 std::string
const & var );
336 namespace ADIOS2Defaults
338 using const_str =
char const *
const;
339 constexpr const_str str_engine =
"engine";
340 constexpr const_str str_type =
"type";
341 constexpr const_str str_params =
"parameters";
342 constexpr const_str str_usesteps =
"usesteps";
343 constexpr const_str str_usesstepsAttribute =
"__openPMD_internal/useSteps";
358 template <
typename T >
359 void operator( )(
BufferedGet & bp, adios2::IO & IO,
360 adios2::Engine & engine,
361 std::string
const & fileName );
363 template <
int T,
typename... Params >
void operator( )( Params &&... );
368 template <
typename T >
369 Datatype operator( )( adios2::IO & IO, std::string name,
370 std::shared_ptr< Attribute::resource > resource );
372 template <
int n,
typename... Params >
373 Datatype operator( )( Params &&... );
378 template <
typename T >
384 template <
int n,
typename... Params >
void operator( )( Params &&... );
395 template <
typename T >
400 template <
int n,
typename... Params >
void operator( )( Params &&... );
411 template <
typename T >
412 void operator( )(
BufferedPut & bp, adios2::IO & IO,
413 adios2::Engine & engine );
415 template <
int n,
typename... Params >
void operator( )( Params &&... );
421 template <
typename T,
typename... Params >
422 void operator( )( Params &&... params );
424 template<
int n,
typename... Params >
426 operator()( Params &&... );
431 template <
typename T,
typename... Params >
432 void operator( )( Params &&... );
434 template <
int n,
typename... Params >
435 void operator( )( Params &&... );
448 using Attr = adios2::Attribute< T >;
451 static Attr createAttribute( adios2::IO & IO, std::string name,
455 readAttribute( adios2::IO & IO, std::string name,
456 std::shared_ptr< Attribute::resource > resource );
465 auto attr = IO.InquireAttribute< BasicType >( name );
470 std::vector< BasicType > data = attr.Data();
471 if( data.size() != 1 )
475 return data[ 0 ] == val;
481 using Attr = adios2::Attribute< std::complex< double > >;
482 using BasicType = double;
484 static Attr createAttribute( adios2::IO &, std::string,
485 std::complex< long double > )
487 throw std::runtime_error(
488 "[ADIOS2] Internal error: no support for long double complex attribute types" );
492 readAttribute( adios2::IO &, std::string,
493 std::shared_ptr< Attribute::resource > )
495 throw std::runtime_error(
496 "[ADIOS2] Internal error: no support for long double complex attribute types" );
501 adios2::IO &, std::string, std::complex< long double > )
503 throw std::runtime_error(
504 "[ADIOS2] Internal error: no support for long double complex attribute types" );
510 using Attr = adios2::Attribute< std::complex< double > >;
511 using BasicType = double;
513 static Attr createAttribute( adios2::IO &, std::string,
514 const std::vector< std::complex< long double > > & )
516 throw std::runtime_error(
517 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
521 readAttribute( adios2::IO &, std::string,
522 std::shared_ptr< Attribute::resource > )
524 throw std::runtime_error(
525 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
532 std::vector< std::complex< long double > > )
534 throw std::runtime_error(
535 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
541 using Attr = adios2::Attribute< T >;
544 static Attr createAttribute( adios2::IO & IO, std::string name,
545 const std::vector< T > & value );
548 readAttribute( adios2::IO & IO, std::string name,
549 std::shared_ptr< Attribute::resource > resource );
555 std::vector< T > val )
557 auto attr = IO.InquireAttribute< BasicType >( name );
562 std::vector< BasicType > data = attr.Data();
563 if( data.size() != val.size() )
567 for(
size_t i = 0; i < val.size(); ++i )
569 if( data[ i ] != val[ i ] )
578 template <
typename T,
size_t n >
581 using Attr = adios2::Attribute< T >;
584 static Attr createAttribute( adios2::IO & IO, std::string name,
585 const std::array< T, n > & value );
588 readAttribute( adios2::IO & IO, std::string name,
589 std::shared_ptr< Attribute::resource > resource );
595 std::array< T, n > val )
597 auto attr = IO.InquireAttribute< BasicType >( name );
602 std::vector< BasicType > data = attr.Data();
603 if( data.size() != n )
607 for(
size_t i = 0; i < n; ++i )
609 if( data[ i ] != val[ i ] )
620 using rep = detail::bool_representation;
621 using Attr = adios2::Attribute< rep >;
622 using BasicType = rep;
624 static Attr createAttribute( adios2::IO & IO, std::string name,
628 readAttribute( adios2::IO & IO, std::string name,
629 std::shared_ptr< Attribute::resource > resource );
632 static constexpr rep toRep(
bool b )
638 static constexpr
bool fromRep( rep r )
644 attributeUnchanged( adios2::IO & IO, std::string name,
bool val )
646 auto attr = IO.InquireAttribute< BasicType >( name );
651 std::vector< BasicType > data = attr.Data();
652 if( data.size() != 1 )
656 return data[ 0 ] == toRep( val );
668 static constexpr
bool validType =
true;
673 static constexpr
bool validType =
false;
678 static constexpr
bool validType =
false;
684 static constexpr
bool validType =
false;
689 static constexpr
bool validType =
false;
700 template <
typename T >
702 T, typename
std::enable_if< DatasetTypes< T >::validType >::type >
713 void readDataset(
BufferedGet &, adios2::IO &, adios2::Engine &,
714 std::string
const & fileName );
734 std::string
const & name,
735 std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator >
const &
737 adios2::Dims
const & shape = adios2::Dims(),
738 adios2::Dims
const & start = adios2::Dims(),
739 adios2::Dims
const & count = adios2::Dims(),
740 bool const constantDims =
false );
742 void writeDataset(
BufferedPut &, adios2::IO &, adios2::Engine & );
748 adios2::Engine & engine,
749 std::string
const & varName );
752 template <
typename T >
754 T, typename
std::enable_if< !DatasetTypes< T >::validType >::type >
759 static void throwErr( );
761 template <
typename... Params >
void openDataset( Params &&... );
763 template <
typename... Params >
void readDataset( Params &&... );
765 template <
typename... Params >
766 static void defineVariable( Params &&... );
768 template <
typename... Params >
void writeDataset( Params &&... );
770 template <
typename... Params >
static void blocksInfo( Params &&... );
848 adios2::ADIOS & m_ADIOS;
850 std::vector< std::unique_ptr< BufferedAction > > m_buffer;
861 std::set< std::string > uncommittedAttributes;
873 bool optimizeAttributesStreaming =
false;
875 using AttributeMap_t = std::map< std::string, adios2::Params >;
888 adios2::Engine & getEngine( );
889 adios2::Engine & requireActiveStep( );
891 template <
typename BA >
void enqueue( BA && ba );
893 template <
typename BA >
void enqueue( BA && ba, decltype( m_buffer ) & );
908 template<
typename F >
910 flush( F && performPutsGets,
bool flushUnconditionally );
934 AttributeMap_t
const &
935 availableAttributes();
937 std::vector< std::string >
938 availableAttributesPrefixed( std::string
const & prefix );
944 invalidateAttributesMap();
946 AttributeMap_t
const &
947 availableVariables();
949 std::vector< std::string >
950 availableVariablesPrefixed( std::string
const & prefix );
956 invalidateVariablesMap();
963 std::string m_engineType;
985 enum class StreamStatus
1033 StreamStatus streamStatus = StreamStatus::OutsideOfStep;
1034 adios2::StepStatus m_lastStepStatus = adios2::StepStatus::OK;
1041 bool delayOpeningTheFirstStep =
false;
1061 bool finalized =
false;
1069 #endif // openPMD_HAVE_ADIOS2 1074 #if openPMD_HAVE_ADIOS2 1089 catch( std::exception
const & ex )
1091 std::cerr <<
"[~ADIOS2IOHandler] An error occurred: " << ex.what() << std::endl;
1095 std::cerr <<
"[~ADIOS2IOHandler] An error occurred." << std::endl;
1103 #if openPMD_HAVE_MPI 1109 nlohmann::json options,
1110 std::string engineType );
1117 nlohmann::json options,
1118 std::string engineType );
1122 std::future< void > flush( )
override;
Definition: ADIOS2IOHandler.hpp:63
Wrapper around a shared pointer to:
Definition: InvalidatableFile.hpp:45
Definition: ADIOS2IOHandler.hpp:429
Definition: IOTask.hpp:493
Definition: ADIOS2IOHandler.hpp:804
Definition: ADIOS2IOHandler.hpp:366
Access
File access mode to use during IO.
Definition: Access.hpp:28
Definition: IOTask.hpp:139
static bool attributeUnchanged(adios2::IO &IO, std::string name, BasicType val)
Is the attribute given by parameters name and val already defined exactly in that way within the give...
Definition: ADIOS2IOHandler.hpp:463
Definition: ADIOS2IOHandler.hpp:418
Definition: IOTask.hpp:223
Definition: IOTask.hpp:320
std::string m_file
The full path to the file created on disk, including the containing directory and the file extension...
Definition: ADIOS2IOHandler.hpp:828
Definition: ADIOS2IOHandler.hpp:78
Definition: ADIOS2IOHandler.hpp:817
Definition: ADIOS2IOHandler.hpp:796
AdvanceStatus
In step-based mode (i.e.
Definition: Streaming.hpp:20
This struct's only field indicates whether the template parameter is a valid datatype to use for a da...
Definition: ADIOS2IOHandler.hpp:69
AdvanceMode
In step-based mode (i.e.
Definition: Streaming.hpp:33
std::string const m_IOName
ADIOS requires giving names to instances of adios2::IO.
Definition: ADIOS2IOHandler.hpp:847
Definition: ADIOS2IOHandler.hpp:788
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:42
Definition: IOTask.hpp:123
Definition: Container.cpp:51
Definition: IOTask.hpp:153
Definition: IOTask.hpp:412
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:68
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:55
Definition: IOTask.hpp:185
Definition: ADIOS2IOHandler.hpp:1072
Definition: IOTask.hpp:365
Definition: ADIOS2IOHandler.hpp:403
std::string backendName() const override
The currently used backend.
Definition: ADIOS2IOHandler.hpp:1120
Definition: IOTask.hpp:475
Definition: ADIOS2IOHandler.hpp:376
Extend nlohmann::json with tracing of which keys have been accessed by operator[]().
Definition: JSON.hpp:48
Definition: Writable.hpp:43
Definition: ADIOS2IOHandler.hpp:387
Definition: ADIOS2IOHandler.hpp:350
Definition: IOTask.hpp:107
Definition: IOTask.hpp:516
Definition: IOTask.hpp:394
Definition: IOTask.hpp:299
Definition: IOTask.hpp:169
Definition: IOTask.hpp:428
Definition: IOTask.hpp:256
nlohmann::json & json()
Access the underlying JSON value.
Definition: JSON.hpp:60
Definition: ADIOS2IOHandler.hpp:67
Definition: ADIOS2IOHandler.hpp:781
Definition: IOTask.hpp:447
Definition: IOTask.hpp:281
Definition: IOTask.hpp:207
Definition: IOTask.hpp:336
Definition: IOTask.hpp:239