23 #include "ADIOS2FilePosition.hpp" 24 #include "openPMD/config.hpp" 25 #include "openPMD/IO/AbstractIOHandler.hpp" 26 #include "openPMD/IO/AbstractIOHandlerImpl.hpp" 27 #include "openPMD/IO/AbstractIOHandlerImplCommon.hpp" 28 #include "openPMD/IO/IOTask.hpp" 29 #include "openPMD/IO/InvalidatableFile.hpp" 30 #include "openPMD/auxiliary/JSON.hpp" 31 #include "openPMD/backend/Writable.hpp" 33 #if openPMD_HAVE_ADIOS2 35 # include "openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp" 42 #include <nlohmann/json.hpp> 50 #include <unordered_map> 56 #if openPMD_HAVE_ADIOS2 58 class ADIOS2IOHandler;
91 static constexpr
bool ADIOS2_DEBUG_MODE =
false;
102 #endif // openPMD_HAVE_MPI 106 , nlohmann::json config
112 std::future< void > flush( )
override;
178 adios2::Mode adios2AccessMode( );
182 adios2::ADIOS m_ADIOS;
184 struct ParameterizedOperator
186 adios2::Operator
const op;
187 adios2::Params
const params;
190 std::vector< ParameterizedOperator > defaultOperators;
196 init( nlohmann::json config );
198 template<
typename Key >
202 if( cfg.
json().is_object() && cfg.
json().contains( key ) )
212 template<
typename Key >
216 return config< Key >( std::forward< Key >( key ), m_config );
226 std::pair< std::vector< ParameterizedOperator >,
bool >
230 std::pair< std::vector< ParameterizedOperator >,
bool >
254 std::unique_ptr< detail::BufferedActions >
257 std::map< std::string, adios2::Operator > m_operators;
262 filePositionToString( std::shared_ptr< ADIOS2FilePosition > )
override;
264 std::shared_ptr< ADIOS2FilePosition >
265 extendFilePosition( std::shared_ptr< ADIOS2FilePosition >
const & pos,
266 std::string extend )
override;
270 std::unique_ptr< adios2::Operator >
271 getCompressionOperator( std::string
const & compression );
277 std::string nameOfVariable(
Writable * writable );
288 std::string nameOfAttribute(
Writable * writable, std::string attribute );
294 ADIOS2FilePosition::GD groupOrDataset(
Writable * );
298 void dropFileData( InvalidatableFile file );
308 template <
typename T >
309 adios2::Variable< T > verifyDataset( Offset
const & offset,
310 Extent
const & extent, adios2::IO & IO,
311 std::string
const & var );
318 namespace ADIOS2Defaults
320 using const_str =
char const *
const;
321 constexpr const_str str_engine =
"engine";
322 constexpr const_str str_type =
"type";
323 constexpr const_str str_params =
"parameters";
338 template <
typename T >
339 void operator( )(
BufferedGet & bp, adios2::IO & IO,
340 adios2::Engine & engine,
341 std::string
const & fileName );
343 template <
int T,
typename... Params >
void operator( )( Params &&... );
348 template <
typename T >
349 Datatype operator( )( adios2::IO & IO, std::string name,
350 std::shared_ptr< Attribute::resource > resource );
352 template <
int n,
typename... Params >
353 Datatype operator( )( Params &&... );
358 template <
typename T >
364 template <
int n,
typename... Params >
void operator( )( Params &&... );
375 template <
typename T >
380 template <
int n,
typename... Params >
void operator( )( Params &&... );
391 template <
typename T >
392 void operator( )(
BufferedPut & bp, adios2::IO & IO,
393 adios2::Engine & engine );
395 template <
int n,
typename... Params >
void operator( )( Params &&... );
401 template <
typename T,
typename... Params >
402 void operator( )( Params &&... params );
404 template<
int n,
typename... Params >
406 operator()( Params &&... );
422 using Attr = adios2::Attribute< T >;
425 static Attr createAttribute( adios2::IO & IO, std::string name,
429 readAttribute( adios2::IO & IO, std::string name,
430 std::shared_ptr< Attribute::resource > resource );
435 using Attr = adios2::Attribute< std::complex< double > >;
436 using BasicType = double;
438 static Attr createAttribute( adios2::IO &, std::string,
439 std::complex< long double > )
441 throw std::runtime_error(
442 "[ADIOS2] Internal error: no support for long double complex attribute types" );
446 readAttribute( adios2::IO &, std::string,
447 std::shared_ptr< Attribute::resource > )
449 throw std::runtime_error(
450 "[ADIOS2] Internal error: no support for long double complex attribute types" );
456 using Attr = adios2::Attribute< std::complex< double > >;
457 using BasicType = double;
459 static Attr createAttribute( adios2::IO &, std::string,
460 const std::vector< std::complex< long double > > & )
462 throw std::runtime_error(
463 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
467 readAttribute( adios2::IO &, std::string,
468 std::shared_ptr< Attribute::resource > )
470 throw std::runtime_error(
471 "[ADIOS2] Internal error: no support for long double complex vector attribute types" );
477 using Attr = adios2::Attribute< T >;
480 static Attr createAttribute( adios2::IO & IO, std::string name,
481 const std::vector< T > & value );
484 readAttribute( adios2::IO & IO, std::string name,
485 std::shared_ptr< Attribute::resource > resource );
488 template <
typename T,
size_t n >
491 using Attr = adios2::Attribute< T >;
494 static Attr createAttribute( adios2::IO & IO, std::string name,
495 const std::array< T, n > & value );
498 readAttribute( adios2::IO & IO, std::string name,
499 std::shared_ptr< Attribute::resource > resource );
504 using rep = detail::bool_representation;
505 using Attr = adios2::Attribute< rep >;
506 using BasicType = rep;
508 static Attr createAttribute( adios2::IO & IO, std::string name,
512 readAttribute( adios2::IO & IO, std::string name,
513 std::shared_ptr< Attribute::resource > resource );
516 static constexpr rep toRep(
bool b )
522 static constexpr
bool fromRep( rep r )
536 static constexpr
bool validType =
true;
541 static constexpr
bool validType =
false;
546 static constexpr
bool validType =
false;
552 static constexpr
bool validType =
false;
557 static constexpr
bool validType =
false;
568 template <
typename T >
570 T, typename
std::enable_if< DatasetTypes< T >::validType >::type >
581 void readDataset(
BufferedGet &, adios2::IO &, adios2::Engine &,
582 std::string
const & fileName );
602 std::string
const & name,
603 std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator >
const &
605 adios2::Dims
const & shape = adios2::Dims(),
606 adios2::Dims
const & start = adios2::Dims(),
607 adios2::Dims
const & count = adios2::Dims(),
608 bool const constantDims =
false );
610 void writeDataset(
BufferedPut &, adios2::IO &, adios2::Engine & );
613 template <
typename T >
615 T, typename
std::enable_if< !DatasetTypes< T >::validType >::type >
620 static void throwErr( );
622 template <
typename... Params >
void openDataset( Params &&... );
624 template <
typename... Params >
void readDataset( Params &&... );
626 template <
typename... Params >
627 static void defineVariable( Params &&... );
629 template <
typename... Params >
void writeDataset( Params &&... );
682 std::vector< std::unique_ptr< BufferedAction > > m_buffer;
695 using AttributeMap_t = std::map< std::string, adios2::Params >;
704 adios2::Engine & getEngine( );
706 template <
typename BA >
void enqueue( BA && ba );
716 AttributeMap_t
const &
717 availableAttributes();
719 std::vector< std::string >
720 availableAttributesPrefixed( std::string
const & prefix );
726 invalidateAttributesMap();
728 AttributeMap_t
const &
729 availableVariables();
731 std::vector< std::string >
732 availableVariablesPrefixed( std::string
const & prefix );
738 invalidateVariablesMap();
755 bool m_availableAttributesValid =
false;
756 AttributeMap_t m_availableAttributes;
758 bool m_availableVariablesValid =
false;
759 AttributeMap_t m_availableVariables;
764 #endif // openPMD_HAVE_ADIOS2 769 #if openPMD_HAVE_ADIOS2 784 catch( std::exception
const & ex )
786 std::cerr <<
"[~ADIOS2IOHandler] An error occurred: " << ex.what() << std::endl;
790 std::cerr <<
"[~ADIOS2IOHandler] An error occurred." << std::endl;
804 nlohmann::json options
813 std::future< void > flush( )
override;
Definition: ADIOS2IOHandler.hpp:62
Wrapper around a shared pointer to:
Definition: InvalidatableFile.hpp:45
Definition: ADIOS2IOHandler.hpp:663
Definition: ADIOS2IOHandler.hpp:346
Access
File access mode to use during IO.
Definition: Access.hpp:30
Definition: IOTask.hpp:132
Definition: ADIOS2IOHandler.hpp:398
Definition: IOTask.hpp:194
Definition: IOTask.hpp:290
Definition: ADIOS2IOHandler.hpp:77
Definition: ADIOS2IOHandler.hpp:676
Definition: ADIOS2IOHandler.hpp:655
This struct's only field indicates whether the template parameter is a valid datatype to use for a da...
Definition: ADIOS2IOHandler.hpp:68
Definition: ADIOS2IOHandler.hpp:647
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:42
Definition: IOTask.hpp:116
Definition: Container.cpp:51
Definition: IOTask.hpp:146
Definition: IOTask.hpp:382
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:68
Public definitions of openPMD-api.
Definition: Date.cpp:28
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:55
Definition: ADIOS2IOHandler.hpp:767
Definition: IOTask.hpp:335
Definition: ADIOS2IOHandler.hpp:383
std::string backendName() const override
The currently used backend.
Definition: ADIOS2IOHandler.hpp:811
Definition: IOTask.hpp:445
Definition: ADIOS2IOHandler.hpp:356
Extend nlohmann::json with tracing of which keys have been accessed by operator[]().
Definition: JSON.hpp:48
Definition: Writable.hpp:43
Definition: ADIOS2IOHandler.hpp:367
Definition: ADIOS2IOHandler.hpp:330
Definition: IOTask.hpp:100
Definition: IOTask.hpp:364
Definition: IOTask.hpp:269
Definition: IOTask.hpp:162
Definition: IOTask.hpp:398
Definition: IOTask.hpp:227
nlohmann::json & json()
Access the underlying JSON value.
Definition: JSON.hpp:60
Definition: ADIOS2IOHandler.hpp:66
Definition: ADIOS2IOHandler.hpp:640
Definition: IOTask.hpp:417
Definition: IOTask.hpp:251
Definition: IOTask.hpp:178
std::unique_ptr< adios2::Engine > m_engine
std::optional would be more idiomatic, but it's not in the C++11 standard
Definition: ADIOS2IOHandler.hpp:688
Definition: IOTask.hpp:306
Definition: IOTask.hpp:210