From 52d0a7a6125d9cb91b3e5a9361c99be64d8b190a Mon Sep 17 00:00:00 2001 From: wfg <wfg@pc0098504.ornl.gov> Date: Fri, 11 Nov 2016 18:03:02 -0500 Subject: [PATCH] Continue working with API changes --- include/capsule/CBoostInterprocess.h | 12 +++++++++- include/capsule/CEmptyCapsule.h | 6 ++--- include/core/CCapsule.h | 26 ++++++++++++++------- include/core/CGroup.h | 4 ++-- include/public/ADIOS.h | 33 +++++++++++++++++++++++---- src/core/CCapsule.cpp | 27 ++++++++++++++++++++++ src/public/ADIOS.cpp | 34 +++++++++++++++++++++++++--- 7 files changed, 121 insertions(+), 21 deletions(-) create mode 100644 src/core/CCapsule.cpp diff --git a/include/capsule/CBoostInterprocess.h b/include/capsule/CBoostInterprocess.h index 427426d8e..24407c948 100644 --- a/include/capsule/CBoostInterprocess.h +++ b/include/capsule/CBoostInterprocess.h @@ -42,7 +42,17 @@ public: template< class T> - void WriteVariableToBuffer( const CGroup& group, const SVariable<T>& variable ); + void WriteVariableToBuffer( const CGroup& group, const SVariable<T>& variable ) + { +// while +// { +// +// send +// receive status +// if( status ) +// switch Transport +// } + } /** * Closes the buffer and moves it into the diff --git a/include/capsule/CEmptyCapsule.h b/include/capsule/CEmptyCapsule.h index 332600fb8..dadaf9b9a 100644 --- a/include/capsule/CEmptyCapsule.h +++ b/include/capsule/CEmptyCapsule.h @@ -8,6 +8,9 @@ #ifndef CEMPTYCAPSULE_H_ #define CEMPTYCAPSULE_H_ +#include "core/CCapsule.h" + + namespace adios { @@ -30,9 +33,6 @@ public: void OpenGroupBuffer( const CGroup& group ); - - void WriteVariableToBuffer( const CGroup& group, const SVariable<T>& variable ); - /** * Closes the buffer and moves it into the * @param group diff --git a/include/core/CCapsule.h b/include/core/CCapsule.h index d926f9ce7..b078b32cb 100644 --- a/include/core/CCapsule.h +++ b/include/core/CCapsule.h @@ -39,21 +39,22 @@ public: MPI_Comm m_MPIComm = 0; ///< only used as reference to MPI communicator passed from parallel constructor, MPI_Comm is a pointer itself. Public as called from C #endif - unsigned long int m_BufferSize; ///< buffer size - std::vector<char> m_Buffer; ///< buffer to be managed, just one type for now + std::map< std::string, std::vector<char> > m_Buffer; ///< buffer to be managed, just one type for now std::map< std::string, std::shared_ptr<CTransform> > m_Transforms; ///< transforms associated with ADIOS run std::map< std::string, std::shared_ptr<CTransport> > m_Transports; ///< transports associated with ADIOS run /** * Unique constructor * @param mpiComm communicator passed from ADIOS + * @param bufferSize passed by the user */ - CCapsule( const MPI_Comm mpiComm, const unsigned long int bufferSize ): - m_MPIComm{ mpiComm }, - m_BufferSize{ bufferSize } - { } + CCapsule( const MPI_Comm mpiComm, const unsigned long int bufferSize ); - virtual ~CCapsule( ){ }; + virtual ~CCapsule( ); + + void CreateTransform( const std::string transform ); + + void CreateTransport( const std::string transport ); /** * This will add to the m_Transports and m_Transforms map @@ -61,10 +62,19 @@ public: */ void OpenGroupBuffer( const CGroup& group ) = 0; - virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<unsigned int>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<char>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<unsigned char>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<short>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<unsigned short>& variable ); virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<int>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<unsigned int>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<long int>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<unsigned long int>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<long long int>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<unsigned long long int>& variable ); virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<float>& variable ); virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<double>& variable ); + virtual void WriteVariableToBuffer( const CGroup& group, const SVariable<long double>& variable ); /** * Closes the buffer and moves it into the diff --git a/include/core/CGroup.h b/include/core/CGroup.h index c94f99c15..061c535a9 100644 --- a/include/core/CGroup.h +++ b/include/core/CGroup.h @@ -143,7 +143,7 @@ private: std::string m_Transport; ///< current transport method associated with this group std::string m_BufferName; ///< associated buffer (file, stream, vector, etc.) if the Group is opened. - std::string m_AccessMode; /// associated access mode for associated buffer from m_BufferName + std::string m_AccessMode; ///< associated access mode for associated buffer from m_BufferName unsigned long int m_SerialSize; ///< size used for potential serialization of metadata into a std::vector<char>. Counts sizes from m_Variables, m_Attributes, m_GlobalBounds @@ -160,7 +160,7 @@ private: * Used by SetVariable and SetAttribute to check if global bounds exist in m_GlobalBounds * @param globalDimensionsCSV comma separated variables defining global dimensions (e.g. "Nx,NY,Nz") * @param globalOffsetsCSV comma separated variables defining global offsets (e.g. "oNx,oNY,oNz") - * @return -1 if not global -> both inputs are empty, otherwise index in m_GlobalBounds if exist or create a new element in m_GlobalBounds; + * @return -1 if not global --> both inputs are empty, otherwise index in m_GlobalBounds if exist or create a new element in m_GlobalBounds; */ const int SetGlobalBounds( const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) noexcept; diff --git a/include/public/ADIOS.h b/include/public/ADIOS.h index 97a8e4519..52e58ef0c 100644 --- a/include/public/ADIOS.h +++ b/include/public/ADIOS.h @@ -42,11 +42,13 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO MPI_Comm m_MPIComm = 0; ///< only used as reference to MPI communicator passed from parallel constructor, MPI_Comm is a pointer itself. Public as called from C #endif + /** * @brief ADIOS empty constructor. Used for non XML config file API calls. */ ADIOS( ); + /** * @brief Serial constructor for XML config file * @param xmlConfigFile passed to m_XMLConfigFile @@ -54,6 +56,7 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO */ ADIOS( const std::string xmlConfigFile, const bool debugMode = false ); + /** * @brief Parallel constructor for XML config file and MPI * @param xmlConfigFile passed to m_XMLConfigFile @@ -73,6 +76,7 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO ~ADIOS( ); ///< virtual destructor overriden by children's own destructors + /** * @brief Open or Append to an output file * @param groupName should match an existing group from XML file or created through CreateGroup @@ -81,13 +85,15 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO */ void Open( const std::string groupName, const std::string fileName, const std::string accessMode = "w" ); + /** * Submits a data element values for writing and associates it with the given variableName * @param groupName name of group that owns the variable * @param variableName name of existing scalar or vector variable in the XML file or created with CreateVariable * @param values pointer to the variable values passed from the user application, use dynamic_cast to check that pointer is of the same value type */ - void Write( const std::string groupName, const std::string variableName, T* values ) + template< class T> + void Write( const std::string groupName, const std::string variableName, const T* values ) { auto itGroup = m_Groups.find( groupName ); if( m_DebugMode == true ) @@ -100,12 +106,14 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO WriteVariable( variableName, values, itGroup->second, m_Capsule ); } + /** * Close a particular group, group will be out of scope and destroyed * @param groupName group to be closed */ void Close( const std::string groupName ); + /** * @brief Dumps groups information to a file stream or standard output. * Note that either the user closes this fileStream or it's closed at the end. @@ -114,10 +122,27 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO void MonitorGroups( std::ostream& logStream ) const; + /** + * @brief Create a new group or replace an existing one + * @param groupName unique name + * @param transport transport method + * @param streamFile + */ + void CreateGroup( const std::string groupName, const std::string transport = "" ); + + + void CreateVariable( const std::string groupName, const std::string variableName, const std::string type, + const std::string dimensionsCSV = "", const std::string transform = "", + const std::string globalDimensionsCSV = "", const std::string globalOffsetsCSV = "" ); + + void CreateAttribute( const std::string groupName, const std::string attributeName, + const std::string type, const std::string value, + const std::string globalDimensionsCSV = "", const std::string globalOffsetsCSV = "" ); + + private: std::string m_XMLConfigFile; ///< XML File to be read containing configuration information - std::string m_HostLanguage = "C++"; ///< Supported languages: C, C++, Fortran, Python, etc. bool m_DebugMode = false; ///< if true will do more checks, exceptions, warnings, expect slower code @@ -138,10 +163,10 @@ private: * ADIOS will allocate two separate buffers each with the specified maximum limit. * Default = 0 means there is no limit */ - unsigned int MaxBufferSizeInMB = 0; + unsigned long int MaxBufferSizeInMB = 0; /** - * Checks for group existence in m_Groups, if failed throws std::invalid_argument exception + * @brief Checks for group existence in m_Groups, if failed throws std::invalid_argument exception * @param itGroup group iterator, usually from find function * @param groupName passed for thrown exception only * @param hint adds information to thrown exception diff --git a/src/core/CCapsule.cpp b/src/core/CCapsule.cpp new file mode 100644 index 000000000..9bcbbeafe --- /dev/null +++ b/src/core/CCapsule.cpp @@ -0,0 +1,27 @@ +/* + * CCapsule.cpp + * + * Created on: Nov 11, 2016 + * Author: wfg + */ + +#include "core/CCapsule.h" + + +namespace adios +{ + +CCapsule::CCapsule( const MPI_Comm mpiComm, const unsigned long int bufferSize ): + m_MPIComm{ mpiComm }, + m_BufferSize{ bufferSize } +{ } + + +CCapsule::~CCapsule( ) +{ } + + + + + +} diff --git a/src/public/ADIOS.cpp b/src/public/ADIOS.cpp index b22826238..16c47091a 100644 --- a/src/public/ADIOS.cpp +++ b/src/public/ADIOS.cpp @@ -46,14 +46,27 @@ ADIOS::~ADIOS( ) { } +void ADIOS::CreateGroup( const std::string groupName, const std::string transport ) +{ + if( m_DebugMode == true ) + { + if( m_Groups.find( groupName ) != m_Groups.end() ) + throw std::invalid_argument( "ERROR: group " + groupName + " already exist, from call to CreateGroup\n" ); + } + + m_Groups.emplace( groupName, CGroup( m_HostLanguage, m_DebugMode ) ); +} + + + void ADIOS::Open( const std::string groupName, const std::string fileName, const std::string accessMode ) { auto itGroup = m_Groups.find( groupName ); + if( m_DebugMode == true ) CheckGroup( itGroup, groupName, " from call to Open with file " + fileName ); itGroup->second.Open( fileName, accessMode ); - } @@ -68,12 +81,27 @@ void ADIOS::Close( const std::string groupName ) throw std::invalid_argument( "ERROR: group " + groupName + " is not open in Write function.\n" ); } - m_Capsule.CloseGroupBuffer( itGroup->second ); - + m_Capsule->CloseGroupBuffer( itGroup->second ); itGroup->second.Close( ); } +void ADIOS::CreateVariable( const std::string groupName, const std::string variableName, const std::string type, + const std::string dimensionsCSV, const std::string transform, + const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) +{ + auto itGroup = m_Groups.find( groupName ); + if( m_DebugMode == true ) + { + CheckGroup( itGroup, groupName, " from call to CreateVariable \n" ); + } + + itGroup->second.CreateVariable( variableName, type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); + + + +} + void ADIOS::MonitorGroups( std::ostream& logStream ) const { for( auto& groupPair : m_Groups ) -- GitLab