From eab9abecc6590ff7cddd9465f37c07037fe3c02e Mon Sep 17 00:00:00 2001 From: wfg <wfg@pc0098504.ornl.gov> Date: Mon, 3 Oct 2016 17:01:59 -0400 Subject: [PATCH] Redesign to separate MPI and noMPI code To do: 1) Test Makefile with and without MPI --- doc/CodingGuidelines | 32 ++++++------ include/ADIOS.h | 86 +++++++++++++++++++++++++++++++++ include/CADIOS.h | 70 --------------------------- include/CFile.h | 52 ++++++++++++++++++++ include/SMetadata.h | 4 +- include/file_mpi/CFileMPI.h | 48 ++++++++++++++++++ include/file_nompi/CFileNoMPI.h | 44 +++++++++++++++++ src/{CADIOS.cpp => ADIOS.cpp} | 0 8 files changed, 249 insertions(+), 87 deletions(-) create mode 100644 include/ADIOS.h delete mode 100644 include/CADIOS.h create mode 100644 include/CFile.h create mode 100644 include/file_mpi/CFileMPI.h create mode 100644 include/file_nompi/CFileNoMPI.h rename src/{CADIOS.cpp => ADIOS.cpp} (100%) diff --git a/doc/CodingGuidelines b/doc/CodingGuidelines index 3a03572fa..724365f30 100644 --- a/doc/CodingGuidelines +++ b/doc/CodingGuidelines @@ -10,10 +10,10 @@ Many items from this list are taken from Stroustrup, Sutter, and Meyers books. Objectives: 1) Improve collaboration: - 1.a. Reduce new code development and integration times for developers and users, by making code easy to understand - 1.b. Allocate more time for discussion and pathfinding rather than understanding developers' coding - 1.c. Expand developers and users base - + 1.a. Reduce new code development and integration times for developers and users, by making code easy to understand + 1.b. Allocate more time for discussion and pathfinding rather than understanding developers' coding + 1.c. Expand developers and users base + 2) Execute new ideas faster 3) Allocate more time to research and publication from new ideas @@ -47,23 +47,23 @@ Text style for readability (Coding format setup in Eclipse with Window > Prefere 5) Brackets: use an extra space for brackets - Do: - if( number < 1 ) - { - number = 4; - ... - } - - Don't: - if( number < 1 ){ - number = 4; ..... + Do: + if( number < 1 ) + { + number = 4; + ... + } + + Don't: + if( number < 1 ){ + number = 4; ..... .....} - + 6) Prefer the keyword "using" over "typedef". Only rename complex types, do not rename standard types (int, double, std::vector) Don't: typedef std::vector<std::vector<double>> Vector2D; Do: using std::vector<std::vector<double>> = Vector2D; - + Documentation/Comments 1) Use Doxygen as the official API documentation tool. Eclipse has a template autocomplete option for function declarations. diff --git a/include/ADIOS.h b/include/ADIOS.h new file mode 100644 index 000000000..cf471d2b4 --- /dev/null +++ b/include/ADIOS.h @@ -0,0 +1,86 @@ +/* + * ADIOS.h + * + * Created on: Oct 3, 2016 + * Author: wfg + */ + +#ifndef ADIOS_H_ +#define ADIOS_H_ + +#include <string> +#include <memory> + +//#ifdef USE_MPI +#include <mpi.h> +//#endif + +#include "SMetadata.h" + + +namespace adios +{ +/** + * Class ADIOS, interface between user call and ADIOS library + */ +class ADIOS +{ + +public: // can be accessed by anyone + + std::string m_XMLConfigFile; ///< XML File to be read containing configuration information + bool m_IsUsingMPI = false; ///< bool flag false: sequential, true: parallel MPI, to be checked instead of communicator + std::unique_ptr<CFile> m_File; + + ADIOS( ); ///< empty constructor, to be defined. Since we have an empty constructor we can't have const variables not defined by this constructor + + /** + * Serial constructor for XML config file + * @param xmlConfigFile passed to m_XMLConfigFile + */ + ADIOS( const std::string xmlConfigFile ); + + //#ifdef USE_MPI //MPI only section + MPI_Comm* m_MPIComm = nullptr; ///< only used as reference to MPI communicator passed from parallel constructor, using pointer instead of reference as null is a possible value + /** + * Parallel constructor for XML config file and MPI + * @param xmlConfigFile passed to m_XMLConfigFile + * @param mpiComm MPI communicator ...const to be discussed + */ + ADIOS( const std::string xmlConfigFile, const MPI_Comm& mpiComm ); + + /** + * Parallel MPI communicator without XML config + * @param mpiComm MPI communicator passed to m_MPIComm ...const to be discussed + */ + ADIOS( const MPI_Comm& mpiComm ); + //#endif //MPI only section + + virtual ~ADIOS( ); ///< virtual destructor overriden by children's own destructors + + virtual void Init( ) = 0; ///< calls to read XML file among other initialization tasks + +private: + + SMetadata m_Metadata; ///< contains all metadata information from XML Config File + bool m_IsUsingMPI = false; ///< bool flag false: sequential, true: parallel MPI, to be checked instead of communicator + + void InitNoMPI( ); ///< called from Init, initialize Serial + + //#ifdef USE_MPI + void InitMPI( ); ///< called from Init, initialize parallel MPI + //#endif + + void ReadXMLConfigFile( ); ///< populates SMetadata by reading the XML Config File + + +}; + + + +} //end namespace + + + + +#endif /* ADIOS_H_ */ diff --git a/include/CADIOS.h b/include/CADIOS.h deleted file mode 100644 index 6222bce38..000000000 --- a/include/CADIOS.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * CADIOS.h - * - * Created on: Sep 29, 2016 - * Author: William F Godoy - */ - -#ifndef CADIOS_H_ -#define CADIOS_H_ - -#include <string> -#include <mpi.h> -#include <memory> // unique_ptr - -#include "include/SMetadata.h" - -namespace adios -{ -/** - * Class CADIOS, interface between user call and ADIOS library - */ -class CADIOS -{ - -public: // can be accessed by anyone - - std::string m_XMLConfigFile; ///< XML File to be read containing configuration information - bool m_IsUsingMPI = false; ///< bool flag false: sequential, true: parallel MPI, to be checked instead of communicator - MPI_Comm* m_MPIComm = nullptr; ///< only used as reference to MPI communicator passed from parallel constructor, using pointer instead of reference as null is a possible value - - CADIOS( ); ///< empty constructor, to be defined. Since we have an empty constructor we can't have const variables not defined by this constructor - - /** - * Serial constructor for XML config file - * @param xmlConfigFile passed to m_XMLConfigFile - */ - CADIOS( const std::string xmlConfigFile ); - - /** - * Parallel constructor for XML config file and MPI - * @param xmlConfigFile passed to m_XMLConfigFile - * @param mpiComm MPI communicator ...const to be discussed - */ - CADIOS( const std::string xmlConfigFile, const MPI_Comm& mpiComm ); - - ~CADIOS( ); ///< virtual destructor overriden by children's own destructors - - void Init( ); ///< calls to read XML file among other initialization tasks - -private: - - SMetadata m_Metadata; ///< contains all metadata information from XML Config File - - void InitSerial( ); ///< called from Init, initialize Serial - void InitMPI( ); ///< called from Init, initialize parallel MPI - - void ReadXMLConfigFile( ); ///< populates SMetadata by reading the XML Config File - - -}; - - - - - - - -} - -#endif /* CADIOS_H_ */ diff --git a/include/CFile.h b/include/CFile.h new file mode 100644 index 000000000..3402acb79 --- /dev/null +++ b/include/CFile.h @@ -0,0 +1,52 @@ +/* + * CFile.h + * + * Created on: Oct 3, 2016 + * Author: wfg + */ + +#ifndef CFILE_H_ +#define CFILE_H_ + +#include <string> + +#include "SMetadata.h" + +namespace adios +{ + +class CFile +{ + +public: + + const std::string m_FileName; ///< serial: file name, MPI: prefix for file name + const std::string m_FileType; ///< netCDF, PHDF5, POSIX + const bool m_IsUsingMPI; ///< true: Communicator is passed, false: serial process (might include threads) + const SMetadata& m_Metadata; ///< reference to metadata info + + CFile( const std::string fileName, const std::string fileType, const SMetadata& metadata, const bool isUsingMPI ): + m_FileName{ fileName }, + m_FileType{ fileType }, + m_Metadata{ metadata }, + m_IsUsingMPI{ isUsingMPI } + { } + + virtual ~CFile( ) { }; + + virtual void Open( const std::string fileName, const std::string groupName, const std::string accessMode ) = 0; + + virtual unsigned long int GroupSize( const std::string fileName, const std::string groupName ) const = 0; + + virtual void Write( const std::string fileName, const std::string variableName ) = 0; + + virtual void Close( ) = 0; + +}; + + +} //end namespace + + + +#endif /* CFILE_H_ */ diff --git a/include/SMetadata.h b/include/SMetadata.h index b4044cd4b..6d30dedf5 100644 --- a/include/SMetadata.h +++ b/include/SMetadata.h @@ -16,6 +16,8 @@ namespace adios struct SMetadata { std::string hostLanguage; ///< Supported: C, C++, Fortran + ///add more Metadata? + @@ -23,6 +25,6 @@ struct SMetadata }; -} +} //end namespace #endif /* SMETADATA_H_ */ diff --git a/include/file_mpi/CFileMPI.h b/include/file_mpi/CFileMPI.h new file mode 100644 index 000000000..8c58e93fb --- /dev/null +++ b/include/file_mpi/CFileMPI.h @@ -0,0 +1,48 @@ +/* + * CFileMPI.h + * + * Created on: Oct 3, 2016 + * Author: wfg + */ + +#ifndef CFILEMPI_H_ +#define CFILEMPI_H_ + +#include <mpi.h> + +#include "CFile.h" + + +namespace adios +{ + +class CFileMPI : public CFile +{ + +public: + + MPI_Comm* m_MPIComm; + + CFileMPI( const std::string fileName, const std::string fileType, const SMetadata& metadata, const MPI_Comm& mpiComm ): + CFile( fileName, fileType, metadata, true ), + m_MPIComm{ mpiComm } + { } + + virtual ~CFileMPI( ) { }; + + virtual void Open( const std::string fileName, const std::string groupName, const std::string accessMode ); + + virtual unsigned long int GroupSize( const std::string fileName, const std::string groupName ) const = 0; + + virtual void Write( const std::string fileName, const std::string variableName ) = 0; + + virtual void Close( ) = 0; + +}; + + +} //end namespace + + + +#endif /* CFILEMPI_H_ */ diff --git a/include/file_nompi/CFileNoMPI.h b/include/file_nompi/CFileNoMPI.h new file mode 100644 index 000000000..9a86f7d5c --- /dev/null +++ b/include/file_nompi/CFileNoMPI.h @@ -0,0 +1,44 @@ +/* + * CFileNoMPI.h + * + * Created on: Oct 3, 2016 + * Author: wfg + */ + +#ifndef CFILENOMPI_H_ +#define CFILENOMPI_H_ + + +#include "CFile.h" + + +namespace adios +{ + +class CFileNoMPI : public CFile +{ + +public: + + CFileNoMPI( const std::string fileName, const std::string fileType, const SMetadata& metadata ): + CFile( fileName, fileName, metadata, false ) + { }; + + virtual ~CFileNoMPI( ){ }; + + virtual void Open( const std::string fileName, const std::string groupName, const std::string accessMode ) = 0; + + virtual unsigned long int GroupSize( const std::string fileName, const std::string groupName ) const = 0; + + virtual void Write( const std::string fileName, const std::string variableName ) = 0; + + virtual void Close( ) = 0; + +}; + + +} //end namespace + + + +#endif /* CFILENOMPI_H_ */ diff --git a/src/CADIOS.cpp b/src/ADIOS.cpp similarity index 100% rename from src/CADIOS.cpp rename to src/ADIOS.cpp -- GitLab