diff --git a/Makefile b/Makefile index 1c1e3ef4c7e35cd64e9dc2ec99fd60de7af55b76..4398777cb5e321d78e07fde97440f0e7c931d790 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ AR:=$(SYS_BIN)/ar MPICC:=$(SYS_BIN)/mpic++ LIBS:= -L$(SYS_LIB) -L$(LOCAL_LIB) -CFLAGS:=-c -Wall -O0 -g -Wpedantic -Woverloaded-virtual -std=c++11 +CFLAGS:=-c -Wall -O0 -g -Wpedantic -Woverloaded-virtual -std=c++14 ARFLAGS:=rcs #ADIOS @@ -54,4 +54,4 @@ nompi: $(HFiles) $(OBJNoMPI) $(CC) $(CFLAGS) $(INC) -o $@ $< clean: - rm ./bin/mpi/*.o ./lib/libadios.a ./bin/nompi/*.o ./lib/libadios_nompi.a \ No newline at end of file + rm ./bin/mpi/*.o ./lib/libadios.a ./bin/nompi/*.o ./lib/libadios_nompi.a diff --git a/include/core/CGroup.h b/include/core/CGroup.h index c363f90ef183748acc83db74002f3309a0068de1..4cb83d8a38eefecb80c4415a6ae889121583d3f2 100644 --- a/include/core/CGroup.h +++ b/include/core/CGroup.h @@ -23,7 +23,7 @@ #endif -#include "core/CVariableBase.h" +#include "core/CVariable.h" #include "core/SAttribute.h" #include "core/CTransport.h" @@ -83,29 +83,26 @@ public: /** - * @brief Sets a variable in current Group, name must be unique - * @param name variable name - * @param isGlobal - * @param type supported type - * @param dimensionsCSV comma separated dimensions, default 1D = {1} - * @param transform method, format = lib or lib:level, where lib = zlib, bzip2, szip, and level=1:9 . If no level is defined then library default is taken + * Sets a new variable in the group object + * @param name variable name, must be unique. If name exists it removes the current variable. In debug mode program will exit. + * @param type variable type, must be in SSupport::Datatypes[hostLanguage] in public/SSupport.h + * @param dimensionsCSV comma separated variable local dimensions (e.g. "Nx,Ny,Nz") + * @param transform method, format = lib or lib:level, where lib = zlib, bzip2, szip, and level=1:9 + * @param globalDimensionsCSV comma separated variable global dimensions (e.g. "gNx,gNy,gNz"), if globalOffsetsCSV is also empty variable is local + * @param globalOffsetsCSV comma separated variable global dimensions (e.g. "gNx,gNy,gNz"), if globalOffsetsCSV is also empty variable is local */ - void CreateLocalVariable( const std::string name, const std::string type, - const std::string dimensionsCSV, const std::string transform ); - - void CreateGlobalVariable( const std::string name, const std::string type, - const std::string dimensionsCSV, const std::string transform, - const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ); + void SetVariable( const std::string name, const std::string type, + const std::string dimensionsCSV, const std::string transform, + const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ); /** - * @brief Sets a variable in current Group - * @param name passed to Name + * @brief Sets a new attribute in current Group + * @param name attribute name, must be unique. If name exists it removes the current variable. In debug mode program will exit. * @param isGlobal * @param type - * @param path * @param value */ - void CreateAttribute( const std::string name, const bool isGlobal, const std::string type, const std::string path, const std::string value ); + void SetAttribute( const std::string name, const bool isGlobal, const std::string type, const std::string value ); /** @@ -115,8 +112,8 @@ public: * @param iteration iterations between writes of a group to gauge how quickly this data should be evacuated from the compute node * @param mpiComm MPI communicator from User->ADIOS->Group */ - void CreateTransport( const std::string method, const unsigned int priority, const unsigned int iteration, - const MPI_Comm mpiComm ); + void SetTransport( const std::string method, const unsigned int priority, const unsigned int iteration, + const MPI_Comm mpiComm ); /** @@ -139,7 +136,9 @@ private: * Value: Polymorphic value is always unique child defined in SVariableTemplate.h, allow different variable types * </pre> */ - std::map< std::string, std::shared_ptr<CVariableBase> > m_Variables; + std::map< std::string, CVariable > m_Variables; + std::vector< std::string > m_VariableTransforms; ///< if a variable has a transform it fills this container, the variable hold an index + /** * @brief Contains all group attributes from SAttribute.h @@ -150,14 +149,12 @@ private: */ std::map< std::string, SAttribute > m_Attributes; - std::vector<std::string> m_GlobalDimensions; ///< from global-bounds in XML File, data in global space - std::vector<std::string> m_GlobalOffsets; ///< from global-bounds in XML File, data in global space + std::vector< std::pair< std::string, std::string > > m_GlobalBounds; ///< if a variable or an attribute is global it fills this container, from global-bounds in XML File, data in global space, pair.first = global dimensions, pair.second = global bounds - std::shared_ptr<CTransport> m_Transport; ///< transport method defined in XML File, using shared_ptr as CGroup is put in a map copy constructor deleted - std::string m_ActiveTransport; + std::string m_CurrentTransport; ///< current transport method associated with this group + std::string m_OutputName; ///< associated output (file, stream, buffer, etc.) if the Group is opened. - std::string m_FileName; ///< associated fileName is the Group is opened. - std::string m_AcessMode; ///< file access mode "r"->read, "w"->write, "a"->append + 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 /** * Called from XML constructor diff --git a/include/core/CTransform.h b/include/core/CTransform.h index d4b08284e9e55e1f3482c56d5f408d1f6c2225e7..97c899e0fa17378a09d35128efdab840795dc3b0 100644 --- a/include/core/CTransform.h +++ b/include/core/CTransform.h @@ -10,10 +10,10 @@ /// \cond EXCLUDE_FROM_DOXYGEN +#include <core/CVariable.h> #include <string> /// \endcond -#include "core/CVariableBase.h" namespace adios diff --git a/include/core/CTransport.h b/include/core/CTransport.h index 13f83a0f688943e52922018442e9ae79b9f9dab6..c68219cafdf5a28491f870e3789c9c5aade616ab 100644 --- a/include/core/CTransport.h +++ b/include/core/CTransport.h @@ -18,7 +18,7 @@ #include "public/mpidummy.h" #endif -#include "core/CVariableBase.h" +#include <core/CVariable.h> namespace adios diff --git a/include/core/CVariable.h b/include/core/CVariable.h index 2a3961661301f049cedefb1dcc2012aaddf5acf5..82e575b019fd37acc06a1b3b84cf7e723b7a34b0 100644 --- a/include/core/CVariable.h +++ b/include/core/CVariable.h @@ -1,67 +1,55 @@ /* - * CVariableType.h + * CVariable.h * - * Created on: Oct 18, 2016 + * Created on: Oct 6, 2016 * Author: wfg */ #ifndef CVARIABLE_H_ #define CVARIABLE_H_ - -#include "core/CVariableBase.h" +/// \cond EXCLUDE_FROM_DOXYGEN +#include <string> +#include <vector> +#include <typeinfo> // for typeid +#include <sstream> +/// \endcond namespace adios { - /** - * Derived template class of CVariableBase. Will hold a pointer of the right type to the void* passed from user app in ADIOS. + * @param Base (parent) class for template derived (child) class CVariable. Required to put CVariable objects in STL containers. */ -template<class T> -class CVariable : public CVariableBase +class CVariable { public: /** - * Template constructor class required for putting CVariable objects as value in a STL map container - * @param isGlobal - * @param type - * @param dimensionsCSV - * @param transform + * Unique constructor for local and global variables + * @param type variable type, must be in SSupport::Datatypes[hostLanguage] in public/SSupport.h + * @param dimensionsCSV comma separated variable local dimensions (e.g. "Nx,Ny,Nz") + * @param transformIndex + * @param globalIndex */ - CVariable( const std::string type, const std::string dimensionsCSV, const std::string transform ): - CVariableBase( type, dimensionsCSV, transform ) - { } + CVariable( const std::string type, const std::string dimensionsCSV, + const int globalIndex, const int transformIndex ); - CVariable( const std::string type, const std::string dimensionsCSV, const std::string transform, - const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ): - CVariableBase( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ) - { } + virtual ~CVariable( ); - ~CVariable( ) - { } + void* m_Values; - const T* m_Value = nullptr; // pointer or no pointer? - const T* Get() const { return m_Value; } +protected: - void Set( const void* values ){ m_Value = static_cast<const T*>( values ); } + const std::string m_Type; ///< mandatory, double, float, unsigned integer, integer, etc. + const std::string m_DimensionsCSV; ///< comma separated list for variables to search for local dimensions }; -template<class T> const T* CVariableBase::Get( ) const -{ - return dynamic_cast< const CVariable<T>& >(*this).Get( ); -} - -template<class T> void CVariableBase::Set( const void* values ) -{ - return dynamic_cast< CVariable<T>& >( *this ).Set( values ); -} +} //end namespace -} //end namespace #endif /* CVARIABLE_H_ */ diff --git a/include/core/CVariableBase.h b/include/core/CVariableBase.h deleted file mode 100644 index 9dab28e0a082785548b46e2b3cb3c16e79b0caf2..0000000000000000000000000000000000000000 --- a/include/core/CVariableBase.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * CVariable.h - * - * Created on: Oct 6, 2016 - * Author: wfg - */ - -#ifndef CVARIABLEBASE_H_ -#define CVARIABLEBASE_H_ - -/// \cond EXCLUDE_FROM_DOXYGEN -#include <string> -#include <vector> -#include <typeinfo> // for typeid -#include <sstream> -/// \endcond - - -namespace adios -{ -/** - * @param Base (parent) class for template derived (child) class CVariable. Required to put CVariable objects in STL containers. - */ -class CVariableBase -{ - -public: - - CVariableBase( const std::string type, const std::string dimensionsCSV, const std::string transform ); - - CVariableBase( const std::string type, const std::string dimensionsCSV, const std::string transform, - const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ); - - - virtual ~CVariableBase( ); - - template<class T> const T* Get( ) const; - template<class T> void Set( const void* values ); - - -protected: - - const std::string m_Type; ///< mandatory, double, float, unsigned integer, integer, etc. - const std::string m_DimensionsCSV; ///< comma separated list for variables to search for local dimensions - const std::string m_Transform; ///< data transform: zlib:1, bzip2:4, szip:9 which level of compression - const std::string m_GlobalDimensionsCSV; ///< comma separated list for variables to search for global dimensions - const std::string m_GlobalOffsetsCSV; ///< comma separated list for variables to search for global offsets - const bool m_IsGlobal = false; ///< boolean flag that identifies is a variable is global or not - -}; - - -} //end namespace - - - -#endif /* CVARIABLEBASE_H_ */ diff --git a/include/core/SAttribute.h b/include/core/SAttribute.h index 04ce885e456e52b9bfc9bea7657f1705fbefdd80..b2f8c4564c130d92f2e4a8eeee26ccd9e9163391 100644 --- a/include/core/SAttribute.h +++ b/include/core/SAttribute.h @@ -20,9 +20,9 @@ namespace adios */ struct SAttribute { - const bool IsGlobal; ///< true: static, defined in XML Config file, false: dynamic, defined in non-XML API const std::string Type; ///< string or numeric type const std::string Value; ///< information about the attribute + const int GlobalIndex; ///< if -1, local, else corresponding index to m_GlobalBounds in CGroup }; diff --git a/include/functions/GroupFunctions.h b/include/functions/GroupFunctions.h index 7b4a39f6430a41db4e93f90bf0077c7a7eb53474..81d3c669731f1faa17c8d5702f6461a09d6a9a4f 100644 --- a/include/functions/GroupFunctions.h +++ b/include/functions/GroupFunctions.h @@ -1,5 +1,5 @@ /* - * GroupFunctions.h helper functions for class CGroup +ri * GroupFunctions.h helper functions for class CGroup * * Created on: Oct 27, 2016 * Author: wfg @@ -20,69 +20,31 @@ #include "public/mpidummy.h" #endif -#include "core/CVariableBase.h" +#include <core/CVariable.h> #include "core/CTransport.h" + namespace adios { /** * Create a language (C++, C, Fortran, etc.) supported type variable and add it to variables map - * @param hostLanguage must be in SSupport::HostLanguages in public/SSupport.h - * @param name name of variable, key in variables map - * @param isGlobal true: global variable defined in XML Config + * @param name key in variables map * @param type variable type, must be in SSupport::Datatypes[hostLanguage] in public/SSupport.h - * @param dimensionsCSV dimensionsCSV comma separated variable dimensions + * @param dimensionsCSV comma separated variable local dimensions (e.g. "Nx,Ny,Nz") * @param transform method, format = lib or lib:level, where lib = zlib, bzip2, szip, and level=1:9 + * @param globalDimensionsCSV comma separated variable global dimensions (e.g. "gNx,gNy,gNz"), if globalOffsetsCSV is also empty variable is local + * @param globalOffsetsCSV comma separated variable global dimensions (e.g. "gNx,gNy,gNz"), if globalOffsetsCSV is also empty variable is local * @param variables map belonging to class CGroup */ -void CreateVariableLanguage( const std::string hostLanguage, const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, +void CreateVariableLanguage( const std::string name, const std::string type, + const std::string dimensionsCSV, const std::string transform, + const std::string globalDimensionsCSV, const std::string globalOffsetsCSV, std::map<std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept; -/** - * Create a C++ supported variable, including STL vector types - * @param name name of variable, key in variables map - * @param isGlobal true: global variable defined in XML Config - * @param type variable type, must be in SSupport::Datatypes[hostLanguage] in public/SSupport.h - * @param dimensionsCSV dimensionsCSV comma separated variable dimensions - * @param transform method, format = lib or lib:level, where lib = zlib, bzip2, szip, and level=1:9 - * @param variables map belonging to class CGroup - */ -void CreateVariableCpp( const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, - std::map< std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept; - -/** - * Create a C supported variable, including STL vector types - * @param name name of variable, key in variables map - * @param isGlobal true: global variable defined in XML Config - * @param type variable type, must be in SSupport::Datatypes[hostLanguage] in public/SSupport.h - * @param dimensionsCSV dimensionsCSV comma separated variable dimensions - * @param transform method, format = lib or lib:level, where lib = zlib, bzip2, szip, and level=1:9 - * @param variables map belonging to class CGroup - */ -void CreateVariableC( const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, - std::map< std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept; - -/** - * Create a Fortran supported variable, including STL vector types - * @param name name of variable, key in variables map - * @param isGlobal true: global variable defined in XML Config - * @param type variable type, must be in SSupport::Datatypes[hostLanguage] in public/SSupport.h - * @param dimensionsCSV dimensionsCSV comma separated variable dimensions - * @param transform method, format = lib or lib:level, where lib = zlib, bzip2, szip, and level=1:9 - * @param variables map belonging to class CGroup - */ -void CreateVariableFortran( const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, - std::map< std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept; - /** * Looks up the variable type and cast the appropriate values type to m_Value in CVariable - * Maybe it produces exceptions? Must double-check * @param variables always a derived CVariable object from CVariableBase * @param values to be casted to the right type */ diff --git a/include/public/SSupport.h b/include/public/SSupport.h index 49d2ea990f0ef70d7b693bb012be767f30c71b69..6584f145ed557701a9e7da3df324f64956df7833 100644 --- a/include/public/SSupport.h +++ b/include/public/SSupport.h @@ -12,6 +12,7 @@ #include <set> #include <string> #include <map> +#include <array> /// \endcond namespace adios @@ -24,6 +25,7 @@ struct SSupport static const std::set<std::string> Transports; ///< supported transport methods static const std::set<std::string> Transforms; ///< supported data transform methods static const std::map<std::string, std::set<std::string> > Datatypes; ///< supported data types + }; diff --git a/src/core/CGroup.cpp b/src/core/CGroup.cpp index dcb5e8b356d1ddb758e43952deb4bf176b1055fa..a178628e4015ef5543171183873a19eb360619cc 100644 --- a/src/core/CGroup.cpp +++ b/src/core/CGroup.cpp @@ -20,13 +20,15 @@ namespace adios CGroup::CGroup( const std::string& hostLanguage, const bool debugMode ): m_HostLanguage{ hostLanguage }, - m_DebugMode{ debugMode } + m_DebugMode{ debugMode }, + m_SerialSize{ 0 } { } CGroup::CGroup( const std::string& hostLanguage, const std::string& xmlGroup, const bool debugMode ): m_HostLanguage{ hostLanguage }, - m_DebugMode{ debugMode } + m_DebugMode{ debugMode }, + m_SerialSize{ 0 } { ParseXMLGroup( xmlGroup ); } @@ -39,12 +41,12 @@ CGroup::~CGroup( ) void CGroup::Open( const std::string fileName, const std::string accessMode ) { m_IsOpen = true; - m_Transport->Open( fileName, accessMode ); } -void CGroup::SetVariable( const std::string name, const bool isGlobal, const std::string type, const std::string dimensionsCSV, - const std::string transform ) +void CGroup::SetVariable( const std::string name, const std::string type, + const std::string dimensionsCSV, const std::string transform, + const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) { if( m_DebugMode == true ) { @@ -52,18 +54,18 @@ void CGroup::SetVariable( const std::string name, const bool isGlobal, const std throw std::invalid_argument( "ERROR: type " + type + " for variable " + name + " is not supported.\n" ); if( m_Variables.count( name ) == 0 ) //variable doesn't exists - CreateVariableLanguage( m_HostLanguage, name, isGlobal, type, dimensionsCSV, transform, m_Variables ); + CreateVariableLanguage( name, type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV, m_Variables ); else //name is found throw std::invalid_argument( "ERROR: variable " + name + " exists more than once.\n" ); } else { - CreateVariableLanguage( m_HostLanguage, name, isGlobal, type, dimensionsCSV, transform, m_Variables ); + CreateVariableLanguage( name, type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV, m_Variables ); } } -void CGroup::SetAttribute( const std::string name, const bool isGlobal, const std::string type, const std::string path, +void CGroup::SetAttribute( const std::string name, const bool isGlobal, const std::string type, const std::string value ) { if( m_DebugMode == true ) @@ -80,29 +82,6 @@ void CGroup::SetAttribute( const std::string name, const bool isGlobal, const st } -void CGroup::SetGlobalBounds( const std::string dimensionsCSV, const std::string offsetsCSV ) -{ - auto lf_SetGlobalMember = []( const std::string inputCSV, std::vector<std::string>& output ) - { - if( inputCSV.empty() ) return; - std::istringstream inputSS( inputCSV ); - std::string element; - - while( std::getline( inputSS, element, ',' ) ) //might have to check for "comma" existence - output.push_back( element ); - }; - - if( m_DebugMode == true ) - { - if( m_GlobalDimensions.empty() == false ) throw std::invalid_argument("ERROR: global dimensions already set\n" ); - if( m_GlobalOffsets.empty() == false ) throw std::invalid_argument("ERROR: global offsets already set\n" ); - } - - lf_SetGlobalMember( dimensionsCSV, m_GlobalDimensions ); - lf_SetGlobalMember( offsetsCSV, m_GlobalOffsets ); -} - - void CGroup::SetTransport( const std::string method, const unsigned int priority, const unsigned int iteration, const MPI_Comm mpiComm ) { @@ -167,15 +146,23 @@ void CGroup::Monitor( std::ostream& logStream ) const void CGroup::ParseXMLGroup( const std::string& xmlGroup ) { std::string::size_type currentPosition( 0 ); - bool isGlobal = false; + bool isGlobal = false; //used to set attributes + std::string globalDimensionsCSV; //used to set variables + std::string globalOffsetsCSV; //used to set variables while( currentPosition != std::string::npos ) { //Get tag std::string tag; GetSubString( "<", ">", xmlGroup, tag, currentPosition ); - if( tag == "</adios-group>" ) break; - if( tag == "</global-bounds>" ) isGlobal = false; + if( tag == "</adios-group>" ) break; //end of current group + + if( tag == "</global-bounds>" ) + { + isGlobal = false; //used for attributes + globalDimensionsCSV.clear(); //used for variables + globalOffsetsCSV.clear(); //used for variables + } if( m_DebugMode == true ) { @@ -202,7 +189,7 @@ void CGroup::ParseXMLGroup( const std::string& xmlGroup ) else if( pair.first == "dimensions" ) dimensionsCSV = pair.second; else if( pair.first == "transform" ) transform = pair.second; } - SetVariable( name, isGlobal, type, dimensionsCSV, transform ); + SetVariable( name, type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); } else if( tagName == "attribute" ) { @@ -210,22 +197,31 @@ void CGroup::ParseXMLGroup( const std::string& xmlGroup ) for( auto& pair : pairs ) //loop through all pairs { if( pair.first == "name" ) name = pair.second; - else if( pair.first == "path" ) path = pair.second; else if( pair.first == "value" ) value = pair.second; else if( pair.first == "type" ) type = pair.second; } - SetAttribute( name, isGlobal, type, path, value ); + SetAttribute( name, isGlobal, type, value ); } else if( tagName == "global-bounds" ) { - isGlobal = true; - std::string dimensionsCSV, offsetsCSV; for( auto& pair : pairs ) //loop through all pairs { - if( pair.first == "dimensions" ) dimensionsCSV = pair.second; - else if( pair.first == "offsets" ) offsetsCSV = pair.second; + if( pair.first == "dimensions" ) + globalDimensionsCSV = pair.second; + else if( pair.first == "offsets" ) + globalOffsetsCSV = pair.second; + } + + if( m_DebugMode == true ) + { + if( globalDimensionsCSV.empty() ) + throw std::invalid_argument( "ERROR: dimensions missing in global-bounds tag\n"); + + if( globalDimensionsCSV.empty() ) + throw std::invalid_argument( "ERROR: offsets missing in global-bounds tag\n"); } - SetGlobalBounds( dimensionsCSV, offsetsCSV ); + + isGlobal = true; } } //end while loop } diff --git a/src/core/CVariable.cpp b/src/core/CVariable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eec3520ee564abee07c62ee7b6343a51948706b8 --- /dev/null +++ b/src/core/CVariable.cpp @@ -0,0 +1,33 @@ +/* + * CVariable.cpp + * + * Created on: Oct 18, 2016 + * Author: wfg + */ + + +#include "core/CVariable.h" + +namespace adios +{ + +CVariable::CVariable( const std::string type, const std::string dimensionsCSV, const std::string transform, + const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ): + m_Type{ type }, + m_DimensionsCSV{ dimensionsCSV }, + m_Transform{ transform }, + m_GlobalDimensionsCSV{ globalDimensionsCSV }, + m_GlobalOffsetsCSV{ globalOffsetsCSV } +{ + if( m_GlobalDimensionsCSV.empty() || m_GlobalOffsetsCSV.empty() ) + m_IsGlobal = false; + else + m_IsGlobal = true; +} + + +CVariable::~CVariable() +{ } + + +} //end namespace diff --git a/src/core/CVariableBase.cpp b/src/core/CVariableBase.cpp deleted file mode 100644 index 6f71277605be21da734eedab4ccd45cefcf370dc..0000000000000000000000000000000000000000 --- a/src/core/CVariableBase.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * CVariable.cpp - * - * Created on: Oct 18, 2016 - * Author: wfg - */ - - -#include "core/CVariableBase.h" - -namespace adios -{ - - -CVariableBase::CVariableBase( const std::string type, const std::string dimensionsCSV, const std::string transform ): - m_Type{ type }, - m_DimensionsCSV{ dimensionsCSV }, - m_Transform{ transform }, - m_IsGlobal{ false } -{ } - -CVariableBase::CVariableBase( const std::string type, const std::string dimensionsCSV, const std::string transform, - const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ): - m_Type{ type }, - m_DimensionsCSV{ dimensionsCSV }, - m_Transform{ transform }, - m_GlobalDimensionsCSV{ globalDimensionsCSV }, - m_GlobalOffsetsCSV{ globalOffsetsCSV }, - m_IsGlobal{ true } -{ } - - -CVariableBase::~CVariableBase() -{ } - - - -} //end namespace diff --git a/src/functions/GroupFunctions.cpp b/src/functions/GroupFunctions.cpp index 07a13eb4ed6a0b290bf3074f57814b5d5ed1988f..dafe410d561e11fabf900cd667742f5f8d2569bb 100644 --- a/src/functions/GroupFunctions.cpp +++ b/src/functions/GroupFunctions.cpp @@ -18,134 +18,184 @@ namespace adios { -void CreateVariableLanguage( const std::string hostLanguage, const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, +void CreateVariableLanguage( const std::string name, const std::string type, + const std::string dimensionsCSV, const std::string transform, + const std::string globalDimensionsCSV, const std::string globalOffsetsCSV, std::map<std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept { - if( hostLanguage == "C++" ) - CreateVariableCpp( name, isGlobal, type, dimensionsCSV, transform, variables ); + std::shared_ptr<CVariableBase> variable; + //Common Primitive types to most languages + if( type == "char" || type == "character" ) + variable = std::make_shared< CVariable<char> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( hostLanguage == "C" ) - CreateVariableC( name, isGlobal, type, dimensionsCSV, transform, variables ); + else if( type == "unsigned char" ) + variable = std::make_shared< CVariable<unsigned char> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( hostLanguage == "Fortran" ) - CreateVariableFortran( name, isGlobal, type, dimensionsCSV, transform, variables ); -} - - -void CreateVariableCpp( const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, - std::map< std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept -{ - //Primitive types - if( type == "char") - variables.emplace( name, std::make_shared< CVariable<char> >( isGlobal, type, dimensionsCSV, transform ) ); + else if( type == "short" || type == "integer*2" ) + variables = std::make_shared< CVariable<short> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( type == "unsigned char") - variables.emplace( name, std::make_shared< CVariable<unsigned char> >( isGlobal, type, dimensionsCSV, transform ) ); + else if( type == "unsigned short" ) + variables = std::make_shared< CVariable<unsigned short> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "int" || type == "integer" ) - variables.emplace( name, std::make_shared< CVariable<int> >( isGlobal, type, dimensionsCSV, transform ) ); + variables = std::make_shared< CVariable<int> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); + + else if( type == "unsigned int" || type == "unsigned integer" ) + variable = std::make_shared< CVariable<unsigned int> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( type == "unsigned int" ) - variables.emplace( name, std::make_shared< CVariable<unsigned int> >( isGlobal, type, dimensionsCSV, transform ) ); + else if( type == "long int" || type == "long" || type == "long integer" ) + variable = std::make_shared< CVariable<long int> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( type == "long int" || type == "long" ) - variables.emplace( name, std::make_shared< CVariable<long int> >( isGlobal, type, dimensionsCSV, transform ) ); + else if( type == "long long int" || type == "long long" || type == "long long integer" ) + variable = std::make_shared< CVariable<long long int> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( type == "long long int" || type == "long long" ) - variables.emplace( name, std::make_shared< CVariable<long long int> >( isGlobal, type, dimensionsCSV, transform ) ); + else if( type == "float" || type == "real" || type == "real*4" ) + variable = std::make_shared< CVariable<float> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( type == "float" ) - variables.emplace( name, std::make_shared< CVariable<float> >( isGlobal, type, dimensionsCSV, transform ) ); + else if( type == "double" || type == "double precision" || type == "real*8" ) + variable = std::make_shared< CVariable<double> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( type == "double") - variables.emplace( name, std::make_shared< CVariable<double> >( isGlobal, type, dimensionsCSV, transform ) ); + else if( type == "long double" || type == "real*16" ) + variable = std::make_shared< CVariable<long double> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - else if( type == "long double") - variables.emplace( name, std::make_shared< CVariable<long double> >( isGlobal, type, dimensionsCSV, transform ) ); + //C++ + else if( type == "std::string" || type == "string" ) + variable = std::make_shared< CVariable<std::string> >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); - //STL types else if( type == "std::vector<char>" || type == "vector<char>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector<char> > >( isGlobal, type, dimensionsCSV, transform ) ); + variable = std::make_shared< CVariable< std::vector<char> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<int>" || type == "vector<int>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector<int> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector<int> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<unsigned int>" || type == "vector<unsigned int>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector<unsigned int> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector<unsigned int> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<long int>" || type == "std::vector<long>" || - type == "vector<long int>" || type == "vector<long>" ) - variables.emplace( name, std::make_shared< CVariable<std::vector<long int> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + type == "vector<long int>" || type == "vector<long>" ) + variable = std::make_shared< CVariable<std::vector<long int> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<long long int>" || type == "std::vector<long long>" || - type == "vector<long long int>" || type == "vector<long long>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector<long long int> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + type == "vector<long long int>" || type == "vector<long long>" ) + variable = std::make_shared< CVariable< std::vector<long long int> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<float>" || type == "vector<float>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector<float> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector<float> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<double>" || type == "vector<double>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector<double> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector<double> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<long double>" || type == "vector<long double>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector<long double> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector<long double> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); //STL Complex types else if( type == "std::complex<float>" || type == "complex<float>" ) - variables.emplace( name, std::make_shared< CVariable< std::complex<float> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::complex<float> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::complex<double>" || type == "complex<double>" ) - variables.emplace( name, std::make_shared< CVariable< std::complex<double> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::complex<double> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::complex<long double>" || type == "complex<long double>" ) - variables.emplace( name, std::make_shared< CVariable< std::complex<long double> > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::complex<long double> > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<std::complex<float>>" || type == "vector<complex<float>>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector< std::complex<float> > > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector< std::complex<float> > > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<std::complex<double>>" || type == "vector<complex<double>>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector< std::complex<double> > > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector< std::complex<double> > > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); else if( type == "std::vector<std::complex<long double>>" || type == "vector<complex<long double>>" ) - variables.emplace( name, std::make_shared< CVariable< std::vector< std::complex<long double> > > >( isGlobal, type, dimensionsCSV, transform ) ) ; + variable = std::make_shared< CVariable< std::vector< std::complex<long double> > > >( type, dimensionsCSV, transform, globalDimensionsCSV, globalOffsetsCSV ); + + variables[name] = variable; } -void CreateVariableC( const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, - std::map< std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept +void SetVariableValues( CVariableBase& variable, const void* values ) noexcept { + const std::string type( variable.m_Type ); -} + if( type == "char" || type == "character" ) + variable.Set<char>( values ); + else if( type == "unsigned char" ) + variable.Set<unsigned char>( values ); -void CreateVariableFortran( const std::string name, const bool isGlobal, - const std::string type, const std::string dimensionsCSV, const std::string transform, - std::map< std::string, std::shared_ptr<CVariableBase> >& variables ) noexcept -{ + else if( type == "short" || type == "integer*2" ) + variable.Set<short>( values ); -} + else if( type == "unsigned short" ) + variable.Set<unsigned short>( values ); + else if( type == "int" || type == "integer" ) + variable.Set<int>( values ); -void SetVariableValues( CVariableBase& variable, const void* values ) noexcept -{ - const std::string type = variable.m_Type; + else if( type == "unsigned int" || type == "unsigned integer" ) + variable.Set<unsigned int>( values ); + + else if( type == "long int" || type == "long" || type == "long integer" ) + variable.Set<long int>( values ); - //Set variable values, add more support - if( type == "double" ) + else if( type == "long long int" || type == "long long" || type == "long long integer" ) + variable.Set<long long int>( values ); + + else if( type == "float" || type == "real" || type == "real*4" ) + variable.Set<float>( values ); + + else if( type == "double" || type == "double precision" || type == "real*8" ) variable.Set<double>( values ); - else if( type == "int" || type == "integer" ) - variable.Set<int>( values ); + else if( type == "long double" || type == "real*16" ) + variable.Set<long double>( values ); + + //C++ + else if( type == "std::string" || type == "string" ) + variable.Set<std::string>( values ); - else if( type == "std::vector<int>" || type == "vector<int>" ) + else if( type == "std::vector<char>" || type == "vector<char>" ) + variable.Set< std::vector<char> >( values ); + + else if( type == "std::vector<int>" || type == "vector<int>" ) variable.Set< std::vector<int> >( values ); - else if( type == "std::vector<double>" || type == "vector<double>" ) + else if( type == "std::vector<unsigned int>" || type == "vector<unsigned int>" ) + variable.Set< std::vector<unsigned int> >( values ); + + else if( type == "std::vector<long int>" || type == "std::vector<long>" || + type == "vector<long int>" || type == "vector<long>" ) + variable.Set<std::vector<long int> >( values ); + + else if( type == "std::vector<long long int>" || type == "std::vector<long long>" || + type == "vector<long long int>" || type == "vector<long long>" ) + variable.Set< std::vector<long long int> >( values ); + + else if( type == "std::vector<float>" || type == "vector<float>" ) + variable.Set< std::vector<float> >( values ); + + else if( type == "std::vector<double>" || type == "vector<double>" ) variable.Set< std::vector<double> >( values ); + else if( type == "std::vector<long double>" || type == "vector<long double>" ) + variable.Set< std::vector<long double> >( values ); + + //STL Complex types + else if( type == "std::complex<float>" || type == "complex<float>" ) + variable.Set< std::complex<float> >( values ); + + else if( type == "std::complex<double>" || type == "complex<double>" ) + variable.Set< std::complex<double> >( values ); + + else if( type == "std::complex<long double>" || type == "complex<long double>" ) + variable.Set< std::complex<long double> >( values ); + + else if( type == "std::vector<std::complex<float>>" || type == "vector<complex<float>>" ) + variable.Set< std::vector< std::complex<float> > >( values ); + + else if( type == "std::vector<std::complex<double>>" || type == "vector<complex<double>>" ) + variable.Set< std::vector< std::complex<double> > >( values ); + + else if( type == "std::vector<std::complex<long double>>" || type == "vector<complex<long double>>" ) + variable.Set< std::vector< std::complex<long double> > >( values ); } diff --git a/src/public/SSupport.cpp b/src/public/SSupport.cpp index 2942c9fec7b572aea1ccfca0a40c8a0509134ec1..94dae63fefb0d60d27d04a919bc5d2fdeb81b362 100644 --- a/src/public/SSupport.cpp +++ b/src/public/SSupport.cpp @@ -31,6 +31,8 @@ const std::set<std::string> SSupport::Transforms{ }; + + const std::map<std::string, std::set<std::string> > SSupport::Datatypes { { "C++", @@ -58,12 +60,12 @@ const std::map<std::string, std::set<std::string> > SSupport::Datatypes "unsigned char", "short", "unsigned short", - "int", - "unsigned int", - "long int", "long", - "unsigned long int", "unsigned long", - "long long int", "long long" - "unsigned long long int", "unsigned long long", + "int", "integer" + "unsigned int", "unsigned integer", + "long int", "long", "long integer", + "unsigned long int", "unsigned long", "unsigned long integer", + "long long int", "long long", "long long integer", + "unsigned long long int", "unsigned long long", "unsigned long long integer", "float", "float complex" "double", @@ -74,10 +76,11 @@ const std::map<std::string, std::set<std::string> > SSupport::Datatypes { "Fortran", { "character", + "integer*2", "integer", - "real", + "real", "real*4", + "double precision", "real*8", "complex", - "double precision", "double complex" } } diff --git a/src/transport/CFStream.cpp b/src/transport/CFStream.cpp index e3eb90773e0abc2bb630fa71045c83bab397daa4..ea14fa2f8f9312dc7ad0256ee2b30da28dc500bd 100644 --- a/src/transport/CFStream.cpp +++ b/src/transport/CFStream.cpp @@ -6,6 +6,7 @@ */ /// \cond EXCLUDED_FROM_DOXYGEN +#include <core/CVariable.h> #include <iostream> #include <sstream> #include <cmath> @@ -15,7 +16,8 @@ #include "transport/CFStream.h" #include "core/CVariable.h" - +#include "functions/GroupFunctions.h" +#include "functions/Templates.h" namespace adios { @@ -55,65 +57,69 @@ void CFStream::Open( const std::string fileName, const std::string accessMode ) } -void CFStream::Write( const CVariableBase& variable ) +void CFStream::Write( const CVariable& variable ) { //local buffer, to be send over MPI std::vector<char> buffer; - - if( variable.m_Type.find( "vector" ) ) //is a vector - { - //find total size first - auto values = variable.Get< std::vector<int> >(); - unsigned int sizeSum = 0; - for( auto element : *values ) - sizeSum += (int) std::log10( (double) std::abs( element ) ) + 1; - - buffer.reserve( 2*sizeSum ); - - for( auto element : *values ) - { - const char* elementChar = std::to_string( element ).c_str(); - buffer.insert( buffer.end(), elementChar, elementChar + strlen( elementChar ) ); - buffer.push_back(' '); - } - - if( m_RankMPI == 0 ) - { - std::cout << "Writing to file " << m_StreamName << "\n"; - - m_FStream << "Hello from rank " << m_RankMPI << " : "; - m_FStream.write( &buffer[0], buffer.size() ); - m_FStream << "\n"; - - MPI_Status* status = NULL; - - for( int r = 1; r < m_SizeMPI; ++r ) - { - int bufferSize; - MPI_Recv( &bufferSize, 1, MPI_INT, r, 0, m_MPIComm, status ); //receive from r the buffer size - std::cout << "Getting from rank: " << r << " buffer size "<< bufferSize << "\n"; - - buffer.resize( bufferSize ); - MPI_Recv( &buffer[0], bufferSize, MPI_CHAR, r, 1, m_MPIComm, status ); //receive from r the buffer - - m_FStream << "Hello from rank " << r << " : "; - m_FStream.write( &buffer[0], bufferSize ); - m_FStream << "\n"; - } - } - else - { - int bufferSize = (int)buffer.size(); - MPI_Send( &bufferSize, 1, MPI_INT, 0, 0, m_MPIComm ); //send to rank=0 the buffer size - - std::cout << "Hello from rank: " << m_RankMPI << "\n"; - std::cout << "Buffer size: " << bufferSize << "\n"; - - MPI_Send( &buffer[0], bufferSize, MPI_CHAR, 0, 1, m_MPIComm ); //send to rank=0 the buffer - } - - MPI_Barrier( m_MPIComm ); - } + const std::string type( variable.m_Type ); + auto var = GetVariableValues( variable ); + +// if( type.find( "vector" ) ) //is a vector +// { +// //find total size first +// //auto values = variable.Get< std::vector<int> >(); +// auto values = GetVariableValues( variable ); +// //auto values = GetVariableValues( variable ); +// unsigned int sizeSum = 0; +// for( auto element : *values ) +// sizeSum += (int) std::log10( (double) std::abs( element ) ) + 1; +// +// buffer.reserve( 2*sizeSum ); +// +// for( auto element : *values ) +// { +// const char* elementChar = std::to_string( element ).c_str(); +// buffer.insert( buffer.end(), elementChar, elementChar + strlen( elementChar ) ); +// buffer.push_back(' '); +// } +// +// if( m_RankMPI == 0 ) +// { +// std::cout << "Writing to file " << m_StreamName << "\n"; +// +// m_FStream << "Hello from rank " << m_RankMPI << " : "; +// m_FStream.write( &buffer[0], buffer.size() ); +// m_FStream << "\n"; +// +// MPI_Status* status = NULL; +// +// for( int r = 1; r < m_SizeMPI; ++r ) +// { +// int bufferSize; +// MPI_Recv( &bufferSize, 1, MPI_INT, r, 0, m_MPIComm, status ); //receive from r the buffer size +// std::cout << "Getting from rank: " << r << " buffer size "<< bufferSize << "\n"; +// +// buffer.resize( bufferSize ); +// MPI_Recv( &buffer[0], bufferSize, MPI_CHAR, r, 1, m_MPIComm, status ); //receive from r the buffer +// +// m_FStream << "Hello from rank " << r << " : "; +// m_FStream.write( &buffer[0], bufferSize ); +// m_FStream << "\n"; +// } +// } +// else +// { +// int bufferSize = (int)buffer.size(); +// MPI_Send( &bufferSize, 1, MPI_INT, 0, 0, m_MPIComm ); //send to rank=0 the buffer size +// +// std::cout << "Hello from rank: " << m_RankMPI << "\n"; +// std::cout << "Buffer size: " << bufferSize << "\n"; +// +// MPI_Send( &buffer[0], bufferSize, MPI_CHAR, 0, 1, m_MPIComm ); //send to rank=0 the buffer +// } +// +// MPI_Barrier( m_MPIComm ); +// } } void CFStream::Close( )