diff --git a/Makefile b/Makefile index 27f123ee3ab70e90b313adec7b966e2ed8a41ea9..86b405b8d6fb215b39fc4d13322042cc9cf72a7a 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ HFiles:=$(shell find ./include -type f -name "*.h") CPPFiles:=$(shell find ./src -type f -name "*.cpp") INC:=-I./include VPATH = ./src ./src/core ./src/functions \ - ./src/engine ./src/engine/writer ./src/engine/dataman ./src/engine/vis \ + ./src/engine ./src/engine/writer ./src/engine/dataman \ ./src/capsule ./src/transform ./src/transport ./src/format #SEPARATE EXTERNAL LIBRARIES HANDLING in Makefile.libs diff --git a/examples/hello/dataman/Makefile b/examples/hello/dataman/Makefile index 9ecfbc12f24b21580460c90522398550ada5970e..64efaa2a4a3c30103831febc991815633b58f634 100644 --- a/examples/hello/dataman/Makefile +++ b/examples/hello/dataman/Makefile @@ -3,11 +3,9 @@ # Author: wfg -BASE_NAME=helloDataMan_OOP - -TOOL_DIR=/usr/bin +BASE_NAME=helloDataMan -CC=g++ # Compiling with mpicc for now +CC=g++ # Compiling with defaults MPICC=mpic++ #ADIOS LOCATION @@ -24,11 +22,11 @@ CFLAGS=-Wall -O0 -g -Wpedantic -std=c++11 all: mpi nompi mpi: $(ADIOS_LIB) $(ADIOS_HFiles) - $(MPICC) $(CFLAGS) $(ADIOS_INCLUDE) -DHAVE_MPI $(BASE_NAME).cpp -o $(BASE_NAME)_mpi $(ADIOS_LIB) -lpthread + $(MPICC) $(CFLAGS) $(ADIOS_INCLUDE) -DHAVE_MPI $(BASE_NAME).cpp -o $(BASE_NAME).exe $(ADIOS_LIB) -lpthread nompi: $(ADIOS_NOMPI_LIB) $(NoMPI_HFiles) - $(CC) $(CFLAGS) $(ADIOS_INCLUDE) $(BASE_NAME).cpp -o $(BASE_NAME)_nompi $(ADIOS_NOMPI_LIB) -lpthread + $(CC) $(CFLAGS) $(ADIOS_INCLUDE) $(BASE_NAME)_nompi.cpp -o $(BASE_NAME)_nompi.exe $(ADIOS_NOMPI_LIB) -lpthread clean: - rm *_mpi; rm *_nompi + rm *.exe; diff --git a/examples/hello/dataman/dataman.xml b/examples/hello/dataman/dataman.xml deleted file mode 100644 index 71bfdb72b64dcfef5d6b17a21761fac0fcad78bc..0000000000000000000000000000000000000000 --- a/examples/hello/dataman/dataman.xml +++ /dev/null @@ -1,62 +0,0 @@ -<?xml version="1.0"?> -<adios-config> - - <!-- Changes to ADIOS-1 XML - Accommodate for the following extensions and flexiblity: - - Multiple engines e.g. SIRIUS can have it's own - - Do not bind one transport to a group, i.e. we can reuse a group in multiple I/O - with different transports - - Do not bind one group to each output file, i.e., we can write variables from - different groups into a single file at the same step - --> - - <!-- Execution Engines: default-engine, sirius, dataman, hdf5 - --> - - - <adios-group name="solid"> - <var name="NX" type="integer"/> - <var name="size" type="integer"/> - <var name="rank" type="integer"/> - - <global-bounds dimensions="size,NX" offsets="rank,0"> - <var name="temperature" gwrite="solid.t" type="double" dimensions="1,NX"/> - <var name="pressure" gwrite="solid.p" type="std::vector<double>" dimensions="1,NX"/> - </global-bounds> - - <attribute name="temperature/description" - value="Global array written from 'size' processes over several timesteps" - type="string"/> - </adios-group> - - - <adios-group name="fluid"> - <var name="NX" type="integer"/> - <var name="size" type="integer"/> - <var name="rank" type="integer"/> - - <global-bounds dimensions="size,NX" offsets="rank,0"> - <var name="temperature" gwrite="fluid.t" type="double" dimensions="1,NX"/> - <var name="pressure" gwrite="fluid.p" type="std::vector<double>" dimensions="1,NX"/> - </global-bounds> - - <attribute name="temperature/description" - value="Global array written from 'size' processes over several timesteps" - type="string"/> - </adios-group> - - - <!-- Associate an engine with a group and parameterize it here - The manager will define the transport(s) used in an output - --> - <method name="dataMan2Fermi" group="fluid" engine="DataMan" real_time="yes"> - <transport="ZeroMQ" target="128.1.1.20">options to ZeroMQ transport</transport> - <transport="MDTM" target="128.1.1.1.10">options to MDTM transport</transport> - <!-- filenames overwrite the value provided in Open() call --> - </method> - - - - -</adios-config> - diff --git a/examples/hello/dataman/helloDataMan.cpp b/examples/hello/dataman/helloDataMan.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c6c1f653e366e895ca770aa70f8729375b0549d4 --- /dev/null +++ b/examples/hello/dataman/helloDataMan.cpp @@ -0,0 +1,83 @@ +/* + * helloWriter.cpp + * + * Created on: Feb 16, 2017 + * Author: wfg + */ + + + +#include <vector> +#include <iostream> + + +#include <mpi.h> + + +#include "ADIOS_CPP.h" + + +int main( int argc, char* argv [] ) +{ + MPI_Init( &argc, &argv ); + int rank; + MPI_Comm_rank( MPI_COMM_WORLD, &rank ); + const bool adiosDebug = true; + adios::ADIOS adios( MPI_COMM_WORLD, adiosDebug ); + + //Application variable + std::vector<double> myDoubles = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const std::size_t Nx = myDoubles.size(); + + try + { + //Define variable and local size + auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {Nx} ); + + //Define method for engine creation, it is basically straight-forward parameters + adios::Method& datamanSettings = adios.DeclareMethod( "WAN", "DataMan" ); //default method type is Writer + datamanSettings.SetParameters( "peer-to-peer=yes", "optimize=yes", "compress=yes" ); + datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + //datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported, will throw an exception + + //Create engine smart pointer to DataMan Engine due to polymorphism, + //Open returns a smart pointer to Engine containing the Derived class DataMan + auto datamanWriter = adios.Open( "myDoubles.bp", "w", datamanSettings ); + + if( datamanWriter == nullptr ) + throw std::ios_base::failure( "ERROR: failed to create DataMan I/O engine at Open\n" ); + + datamanWriter->Write( ioMyDoubles, myDoubles.data() ); // Base class Engine own the Write<T> that will call overloaded Write from Derived + datamanWriter->Close( ); + + } + catch( std::invalid_argument& e ) + { + if( rank == 0 ) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + } + catch( std::ios_base::failure& e ) + { + if( rank == 0 ) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + } + catch( std::exception& e ) + { + if( rank == 0 ) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + } + + MPI_Finalize( ); + + return 0; + +} diff --git a/examples/hello/dataman/helloDataMan_OOP.cpp b/examples/hello/dataman/helloDataMan_OOP.cpp deleted file mode 100644 index 90248225697844810cc97bcebeb443583a52aab9..0000000000000000000000000000000000000000 --- a/examples/hello/dataman/helloDataMan_OOP.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * helloADIOSNoXML_OOP.cpp - * - * Created on: Jan 9, 2017 - * Author: wfg - */ - -#include <vector> -#include <iostream> - -#ifdef HAVE_MPI - #include <mpi.h> -#else - #include "mpidummy.h" - using adios::MPI_Init; - using adios::MPI_Comm_rank; - using adios::MPI_Finalize; -#endif - - -#include "ADIOS_OOP.h" - - -int main( int argc, char* argv [] ) -{ - MPI_Init( &argc, &argv ); - int rank; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - const bool adiosDebug = true; - adios::ADIOS adios( MPI_COMM_WORLD, adiosDebug ); - - //Application variable - std::vector<double> myNumbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - int myNX = static_cast<int>( myNumbers.size() ); - - try - { - //Define group and variables - adios::Group& wanGroup = adios.DeclareGroup( "WAN_Group" ); - adios::Var ioNX = wanGroup.DefineVariable<int>( "myNX" ); - adios::Dims ioDim1D = wanGroup.SetDimensions( {ioNX} ); //can be extended to many dimensions {ioNx, ioNy} - adios::Var ioNumbers = wanGroup.DefineVariable<double>( "myNumbers", ioDim1D ); - - adios::Method& wanMethod = adios.DeclareMethod( "WAN_Method", "DataMan" ); //name and type - wanMethod.AddTransport( "Mdtm", "localIP=128.0.0.0.1", "remoteIP=128.0.0.0.2", "tolerances=1,2,3" );//add as many as you want - wanMethod.SetDefaultGroup( wanGroup ); - - auto dataManWriter = adios.Open( "hello_dataman", "w", wanMethod ); //here pass the method to your engine - dataManWriter->Write<int>( ioDim1D, &myNX ); //a template Write is good to have - dataManWriter->Write<double>( ioNumbers, myNumbers.data() ); - dataManWriter->Close( ); - - } - catch( std::invalid_argument& e ) - { - if( rank == 0 ) - { - std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - } - catch( std::ios_base::failure& e ) - { - if( rank == 0 ) - { - std::cout << "System exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - } - catch( std::exception& e ) - { - if( rank == 0 ) - { - std::cout << "Exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - } - - MPI_Finalize( ); - - return 0; - -} - - - diff --git a/examples/hello/dataman/helloDataMan_nompi.cpp b/examples/hello/dataman/helloDataMan_nompi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe7ebbafd5da3c5bc668535b5652c28df3ddcf71 --- /dev/null +++ b/examples/hello/dataman/helloDataMan_nompi.cpp @@ -0,0 +1,66 @@ +/* + * helloADIOSNoXML_OOP.cpp + * + * Created on: Jan 9, 2017 + * Author: wfg + */ + +#include <vector> +#include <iostream> + +#include "ADIOS_CPP.h" + + +int main( int argc, char* argv [] ) +{ + const bool adiosDebug = true; + adios::ADIOS adios( adiosDebug ); + + //Application variable + std::vector<double> myDoubles = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const std::size_t Nx = myDoubles.size(); + + try + { + //Define variable and local size + //Define variable and local size + auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {Nx} ); + + //Define method for engine creation, it is basically straight-forward parameters + adios::Method& datamanSettings = adios.DeclareMethod( "WAN", "DataMan" ); //default method type is Writer + datamanSettings.SetParameters( "peer-to-peer=yes", "optimize=yes", "compress=yes" ); + datamanSettings.AddTransport( "Mdtm", "localIP=128.0.0.0.1", "remoteIP=128.0.0.0.2", "tolerances=1,2,3" ); + //datamanSettings.AddTransport( "ZeroMQ", "localIP=128.0.0.0.1.1", "remoteIP=128.0.0.0.2.1", "tolerances=1,2,3" ); not yet supported , will throw an exception + + //Create engine smart pointer to DataMan Engine due to polymorphism, + //Open returns a smart pointer to Engine containing the Derived class DataMan + auto datamanWriter = adios.Open( "myDoubles.bp", "w", datamanSettings ); + + if( datamanWriter == nullptr ) + throw std::ios_base::failure( "ERROR: failed to create DataMan I/O engine at Open\n" ); + + //datamanWriter->Write( "myDoubles", myDoubles.data() ); //you can write either by string or by object + datamanWriter->Write( ioMyDoubles, myDoubles.data() ); // Base class Engine own the Write<T> that will call overloaded Write from Derived + datamanWriter->Close( ); + } + catch( std::invalid_argument& e ) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch( std::ios_base::failure& e ) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch( std::exception& e ) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + + return 0; +} + + + diff --git a/examples/hello/writer/Makefile b/examples/hello/writer/Makefile index 633a4445f629eddb64846e2b1c8c724485459e2c..30851e670e052a65824167c3d545ce7a272facaa 100644 --- a/examples/hello/writer/Makefile +++ b/examples/hello/writer/Makefile @@ -2,10 +2,10 @@ # Created on: Oct 4, 2016 # Author: wfg -BASE_NAME=helloWriter_OOP +BASE_NAME=helloWriter #COMPILERS -CC=g++ +CC=g++ MPICC=mpic++ #ADIOS LOCATION @@ -21,11 +21,11 @@ LDFLAGS= all: mpi nompi mpi: $(ADIOS_LIB) $(ADIOS_HFiles) - $(MPICC) $(CFLAGS) $(ADIOS_INCLUDE) -DHAVE_MPI $(BASE_NAME).cpp -o $(BASE_NAME)_mpi $(ADIOS_LIB) $(LDFLAGS) -lpthread + $(MPICC) $(CFLAGS) $(ADIOS_INCLUDE) -DHAVE_MPI $(BASE_NAME).cpp -o $(BASE_NAME).exe $(ADIOS_LIB) $(LDFLAGS) -lpthread nompi: $(ADIOS_NOMPI_LIB) $(NoMPI_HFiles) - $(CC) $(CFLAGS) $(ADIOS_INCLUDE) $(BASE_NAME).cpp -o $(BASE_NAME)_nompi $(ADIOS_NOMPI_LIB) $(LDFLAGS) -lpthread + $(CC) $(CFLAGS) $(ADIOS_INCLUDE) $(BASE_NAME)_nompi.cpp -o $(BASE_NAME)_nompi.exe $(ADIOS_NOMPI_LIB) $(LDFLAGS) -lpthread clean: - rm *_mpi; rm *_nompi + rm *.exe \ No newline at end of file diff --git a/examples/hello/writer/helloWriter_OOP.cpp b/examples/hello/writer/helloWriter.cpp similarity index 51% rename from examples/hello/writer/helloWriter_OOP.cpp rename to examples/hello/writer/helloWriter.cpp index af6cebb409fe06cc9354de0cb0e04ba67996d765..57dc41ad8b44f0753345f3a83144d681f903376b 100644 --- a/examples/hello/writer/helloWriter_OOP.cpp +++ b/examples/hello/writer/helloWriter.cpp @@ -1,24 +1,20 @@ /* - * helloADIOSNoXML_OOP.cpp + * helloWriter.cpp * - * Created on: Jan 9, 2017 + * Created on: Feb 16, 2017 * Author: wfg */ + + #include <vector> #include <iostream> -#ifdef HAVE_MPI - #include <mpi.h> -#else - #include "mpidummy.h" - using adios::MPI_Init; - using adios::MPI_Comm_rank; - using adios::MPI_Finalize; -#endif +#include <mpi.h> -#include "ADIOS_OOP.h" + +#include "ADIOS_CPP.h" int main( int argc, char* argv [] ) @@ -28,39 +24,28 @@ int main( int argc, char* argv [] ) MPI_Comm_rank( MPI_COMM_WORLD, &rank ); const bool adiosDebug = true; adios::ADIOS adios( MPI_COMM_WORLD, adiosDebug ); - //adios::ADIOS adios( "xmlFile.adios", MPI_COMM_WORLD, adiosDebug ); //Application variable std::vector<double> myDoubles = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - std::vector<float> myFloats = { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 }; - const unsigned int Nx = 10; //static_cast<unsigned int>( myDoubles.size() ); + const std::size_t Nx = myDoubles.size(); try { - //Define group and variables with transforms, variables don't have functions, only group can access variables - adios::Group& ioGroup = adios.DeclareGroup( "ioGroup" ); - adios::Var ioNx = ioGroup.DefineVariable<unsigned int>( "Nx" ); - adios::Dims dimNx = ioGroup.SetDimensions( {ioNx} ); - adios::Var ioMyDoubles = ioGroup.DefineVariable<double>( "myDoubles", dimNx ); - - //add transform to variable in group...not executed (just testing API) - adios::Transform bzip2 = adios::transform::BZIP2( ); - ioGroup.AddTransform( ioMyDoubles, bzip2, 1 ); + //Define variable and local size + auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {Nx} ); //Define method for engine creation, it is basically straight-forward parameters adios::Method& bpWriterSettings = adios.DeclareMethod( "SinglePOSIXFile" ); //default method type is Writer bpWriterSettings.AddTransport( "POSIX", "have_metadata_file=yes" ); - bpWriterSettings.SetDefaultGroup( ioGroup ); //Create engine smart pointer due to polymorphism, //Open returns a smart pointer to Engine containing the Derived class Writer - auto bpWriter = adios.Open( "myNumbers.bp", "w", bpWriterSettings ); + auto bpWriter = adios.Open( "myDoubles.bp", "w", bpWriterSettings ); if( bpWriter == nullptr ) - throw std::ios_base::failure( "ERROR: failed to open ADIOS bpWriter\n" ); + throw std::ios_base::failure( "ERROR: couldn't create bpWriter at Open\n" ); - bpWriter->Write<unsigned int>( ioNx, &Nx ); - bpWriter->Write<double>( ioMyDoubles, myDoubles.data() ); // Base class Engine own the Write<T> that will call overloaded Write from Derived + bpWriter->Write( ioMyDoubles, myDoubles.data() ); // Base class Engine own the Write<T> that will call overloaded Write from Derived bpWriter->Close( ); } catch( std::invalid_argument& e ) @@ -93,6 +78,3 @@ int main( int argc, char* argv [] ) return 0; } - - - diff --git a/examples/hello/writer/helloWriter_nompi.cpp b/examples/hello/writer/helloWriter_nompi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ba6b4ffe90c227d6cbe72a82467293581cf36d2 --- /dev/null +++ b/examples/hello/writer/helloWriter_nompi.cpp @@ -0,0 +1,62 @@ +/* + * helloADIOSNoXML_OOP.cpp + * + * Created on: Jan 9, 2017 + * Author: wfg + */ + +#include <vector> +#include <iostream> + +#include "ADIOS_CPP.h" + + +int main( int argc, char* argv [] ) +{ + const bool adiosDebug = true; + adios::ADIOS adios( adiosDebug ); + + //Application variable + std::vector<double> myDoubles = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const std::size_t Nx = myDoubles.size(); + + try + { + //Define variable and local size + auto& ioMyDoubles = adios.DefineVariable<double>( "myDoubles", {Nx} ); + + //Define method for engine creation, it is basically straight-forward parameters + adios::Method& bpWriterSettings = adios.DeclareMethod( "SinglePOSIXFile" ); //default method type is Writer + bpWriterSettings.AddTransport( "POSIX", "have_metadata_file=yes" ); + + //Create engine smart pointer due to polymorphism, + //Open returns a smart pointer to Engine containing the Derived class Writer + auto bpWriter = adios.Open( "myDoubles_nompi.bp", "w", bpWriterSettings ); + + if( bpWriter == nullptr ) + throw std::ios_base::failure( "ERROR: couldn't create bpWriter at Open\n" ); + + bpWriter->Write<double>( ioMyDoubles, myDoubles.data() ); // Base class Engine own the Write<T> that will call overloaded Write from Derived + bpWriter->Close( ); + } + catch( std::invalid_argument& e ) + { + std::cout << "Invalid argument exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch( std::ios_base::failure& e ) + { + std::cout << "System exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + catch( std::exception& e ) + { + std::cout << "Exception, STOPPING PROGRAM\n"; + std::cout << e.what() << "\n"; + } + + return 0; +} + + + diff --git a/include/ADIOS.h b/include/ADIOS.h index c001fa9222dd127774a6d9e4dbf8f67d79913494..caaeb76a440594d2e4540c46965dce2e659ee444 100644 --- a/include/ADIOS.h +++ b/include/ADIOS.h @@ -23,14 +23,18 @@ #include "mpidummy.h" #endif -#include "core/Engine.h" +#include "core/Transform.h" #include "core/Variable.h" #include "core/Method.h" #include "core/Support.h" +#include "functions/adiosTemplates.h" namespace adios { + +class Engine; + /** * @brief Unique class interface between user application and ADIOS library */ @@ -40,7 +44,7 @@ class ADIOS public: // PUBLIC Constructors and Functions define the User Interface with ADIOS #ifdef HAVE_MPI - MPI_Comm m_MPIComm = NULL; ///< only used as reference to MPI communicator passed from parallel constructor, MPI_Comm is a pointer itself. Public as called from C + MPI_Comm m_MPIComm = MPI_COMM_NULL; ///< only used as reference to MPI communicator passed from parallel constructor, MPI_Comm is a pointer itself. Public as called from C #else 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 @@ -48,6 +52,8 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO int m_RankMPI = 0; ///< current MPI rank process int m_SizeMPI = 1; ///< current MPI processes size + std::string m_HostLanguage = "C++"; + std::vector< Variable<char> > m_Char; ///< Key: variable name, Value: variable of type char std::vector< Variable<unsigned char> > m_UChar; ///< Key: variable name, Value: variable of type unsigned char std::vector< Variable<short> > m_Short; ///< Key: variable name, Value: variable of type short @@ -65,24 +71,24 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO /** * @brief ADIOS empty constructor. Used for non XML config file API calls. */ - ADIOS( ); + ADIOS( const bool debugMode = false ); /** - * @brief Serial constructor for XML config file - * @param xmlConfigFile passed to m_XMLConfigFile + * @brief Serial constructor for config file + * @param configFileName passed to m_ConfigFile * @param debugMode true: on throws exceptions and do additional checks, false: off (faster, but unsafe) */ - ADIOS( const std::string xmlConfigFile, const bool debugMode = false ); + ADIOS( const std::string configFileName, const bool debugMode = false ); /** * @brief Parallel constructor for XML config file and MPI - * @param xmlConfigFile passed to m_XMLConfigFile + * @param configFileName passed to m_XMLConfigFile * @param mpiComm MPI communicator ...const to be discussed * @param debugMode true: on, false: off (faster, but unsafe) */ - ADIOS( const std::string xmlConfigFile, const MPI_Comm mpiComm, const bool debugMode = false ); + ADIOS( const std::string configFileName, const MPI_Comm mpiComm, const bool debugMode = false ); /** @@ -96,12 +102,22 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO ~ADIOS( ); ///< empty, using STL containers for memory management + void InitMPI( ); ///< sets rank and size in m_rank and m_Size, respectively. + + template<class T> inline Variable<T>& DefineVariable( const std::string name, const Dims dimensions = Dims{1}, const Dims globalDimensions = Dims( ), const Dims globalOffsets = Dims() ) { - throw std::invalid_argument( "ERROR: type not supported for variable " + name + "\n" ); + //throw std::invalid_argument( "ERROR: type not supported for variable " + name + "\n" ); + } + + + template<class T> inline + Variable<T>& GetVariable( const std::string name ) + { + //throw std::invalid_argument( "ERROR: variable " + name + " and type don't match in call to GetVariable\n" ); } @@ -163,27 +179,18 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO std::shared_ptr<Engine> Open( const std::string streamName, const std::string accessMode, const std::string methodName, const unsigned int cores = 1 ); - /** - * Close a particular stream and the corresponding transport - * @param streamName stream to be closed with all corresponding transports - * @param transportIndex identifier to a particular transport, if == -1 Closes all transports - */ - void Close( const unsigned int handler, const int transportIndex = -1 ); - - /** * @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. * @param logStream either std::cout standard output, or a std::ofstream file */ - void MonitorGroups( std::ostream& logStream ) const; + void MonitorVariables( std::ostream& logStream ) const; private: //no const to allow default empty and copy constructors - std::string m_XMLConfigFile; ///< XML File to be read containing configuration information - std::string m_HostLanguage = "C++"; ///< Supported languages: C, C++, Fortran, Python, etc. + std::string m_ConfigFile; ///< XML File to be read containing configuration information bool m_DebugMode = false; ///< if true will do more checks, exceptions, warnings, expect slower code //Variables @@ -208,8 +215,16 @@ private: //no const to allow default empty and copy constructors * @param groupName unique name, passed for thrown exception only * @param hint adds information to thrown exception */ - void CheckVariable( const std::string name, const Dims& dimensions ) const; + void CheckVariableInput( const std::string name, const Dims& dimensions ) const; + /** + * Checks for variable name, if not found throws an invalid exception + * @param itVariable iterator pointing to the variable name in m_Variables + * @param name variable name + * @param hint message to be thrown for debugging purporses + */ + void CheckVariableName( std::map< std::string, std::pair< std::string, unsigned int > >::const_iterator itVariable, + const std::string name, const std::string hint ) const; /** * @brief Checks for method existence in m_Methods, if failed throws std::invalid_argument exception @@ -220,145 +235,215 @@ private: //no const to allow default empty and copy constructors void CheckMethod( std::map< std::string, Method >::const_iterator itMethod, const std::string methodName, const std::string hint ) const; + template< class T > + unsigned int GetVariableIndex( const std::string name ) const + { + auto itVariable = m_Variables.find( name ); + CheckVariableName( itVariable, name, "in call to GetVariable<" + GetType<T>() + ">" ); + return itVariable->second.second; + } + }; //template specializations of DefineVariable: - -template<class T> inline -Variable<T>& ADIOS::DefineVariable<char>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<char>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_Char.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_Char.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<char>(), m_Char.size()-1 ) ); return m_Char.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<short>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<unsigned char>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_UChar.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_UChar.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<unsigned char>(), m_UChar.size()-1 ) ); return m_UChar.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<unsigned short>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<short>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) +{ + CheckVariableInput( name, dimensions ); + m_Short.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + m_Variables.emplace( name, std::make_pair( GetType<unsigned char>(), m_Short.size()-1 ) ); + return m_Short.back(); +} + + +template<> inline +Variable<unsigned short>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_UShort.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_UShort.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<unsigned short>(), m_UShort.size()-1 ) ); return m_UShort.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<int>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<int>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_Int.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_Int.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<int>(), m_Int.size()-1 ) ); return m_Int.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<unsigned int>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<unsigned int>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_UInt.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_UInt.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<unsigned int>(), m_UInt.size()-1 ) ); return m_UInt.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<long int>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<long int>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_LInt.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_LInt.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<long int>(), m_LInt.size()-1 ) ); return m_LInt.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<unsigned long int>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<unsigned long int>& ADIOS::DefineVariable<unsigned long int>( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_ULInt.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_ULInt.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<unsigned long int>(), m_ULInt.size()-1 ) ); return m_ULInt.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<long long int>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<long long int>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_LLInt.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_LLInt.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<long long int>(), m_LLInt.size()-1 ) ); return m_LLInt.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<unsigned long long int>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<unsigned long long int>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_ULLInt.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_ULLInt.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<unsigned long long int>(), m_ULLInt.size()-1 ) ); return m_ULLInt.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<float>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<float>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_Float.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_Float.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<float>(), m_Float.size()-1 ) ); return m_Float.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<double>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<double>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_Double.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_Double.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<double>(), m_Double.size()-1 ) ); return m_Double.back(); } -template<class T> inline -Variable<T>& ADIOS::DefineVariable<long double>( const std::string name, const Dims dimensions = Dims{1}, - const Dims globalDimensions = Dims(), const Dims globalOffsets = Dims() ) +template<> inline +Variable<long double>& ADIOS::DefineVariable( const std::string name, const Dims dimensions, + const Dims globalDimensions, const Dims globalOffsets ) { - CheckVariable( name, dimensions ); - m_LDouble.emplace_back( *this, name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); + CheckVariableInput( name, dimensions ); + m_LDouble.emplace_back( name, dimensions, globalDimensions, globalOffsets, m_DebugMode ); m_Variables.emplace( name, std::make_pair( GetType<long double>(), m_LDouble.size()-1 ) ); return m_LDouble.back(); } +//Get template specialization +template<> inline +Variable<char>& ADIOS::GetVariable( const std::string name ) +{ return m_Char[ GetVariableIndex<char>(name) ]; } -} //end namespace +template<> inline +Variable<unsigned char>& ADIOS::GetVariable( const std::string name ) +{ return m_UChar[ GetVariableIndex<unsigned char>(name) ]; } + +template<> inline +Variable<short>& ADIOS::GetVariable( const std::string name ) +{ return m_Short[ GetVariableIndex<short>(name) ]; } + +template<> inline +Variable<unsigned short>& ADIOS::GetVariable( const std::string name ) +{ return m_UShort[ GetVariableIndex<unsigned short>(name) ]; } + +template<> inline +Variable<int>& ADIOS::GetVariable( const std::string name ) +{ return m_Int[ GetVariableIndex<int>(name) ]; } + +template<> inline +Variable<unsigned int>& ADIOS::GetVariable( const std::string name ) +{ return m_UInt[ GetVariableIndex<unsigned int>(name) ]; } +template<> inline +Variable<long int>& ADIOS::GetVariable( const std::string name ) +{ return m_LInt[ GetVariableIndex<unsigned int>(name) ]; } +template<> inline +Variable<unsigned long int>& ADIOS::GetVariable( const std::string name ) +{ return m_ULInt[ GetVariableIndex<unsigned long int>(name) ]; } + +template<> inline +Variable<long long int>& ADIOS::GetVariable( const std::string name ) +{ return m_LLInt[ GetVariableIndex<long long int>(name) ]; } + +template<> inline +Variable<unsigned long long int>& ADIOS::GetVariable( const std::string name ) +{ return m_ULLInt[ GetVariableIndex<unsigned long long int>(name) ]; } + +template<> inline +Variable<float>& ADIOS::GetVariable( const std::string name ) +{ return m_Float[ GetVariableIndex<float>(name) ]; } + +template<> inline +Variable<double>& ADIOS::GetVariable( const std::string name ) +{ return m_Double[ GetVariableIndex<double>(name) ]; } + +template<> inline +Variable<long double>& ADIOS::GetVariable<long double>( const std::string name ) +{ return m_LDouble[ GetVariableIndex<long double>(name) ]; } + + + +} //end namespace #endif /* ADIOS_H_ */ diff --git a/include/ADIOS_C.h b/include/ADIOS_C.h index efe9ed2865288befab52c5aef860ef42308ff75b..e9a20fe84b5cb29360ae7d6342941fcfbd0b5dae 100644 --- a/include/ADIOS_C.h +++ b/include/ADIOS_C.h @@ -19,7 +19,6 @@ typedef void ADIOS; -typedef void Group; typedef void Method; typedef void Engine; diff --git a/include/ADIOS_OOP.h b/include/ADIOS_CPP.h similarity index 65% rename from include/ADIOS_OOP.h rename to include/ADIOS_CPP.h index 0178a189f2c112843dbf9127220dad40bb3477ba..033de1873b91eecbaea946bc5e52b406a7ec4d6d 100644 --- a/include/ADIOS_OOP.h +++ b/include/ADIOS_CPP.h @@ -1,23 +1,23 @@ /* - * ADIOS_OOP.h + * ADIOS_CPP.h * * Created on: Jan 9, 2017 * Author: wfg */ -#ifndef ADIOS_OOP_H_ -#define ADIOS_OOP_H_ +#ifndef ADIOS_CPP_H_ +#define ADIOS_CPP_H_ #include "ADIOS.h" -#include "core/Group.h" #include "core/Method.h" #include "core/Engine.h" #include "engine/writer/Writer.h" +#include "engine/dataman/DataMan.h" #include "core/Transform.h" #include "transform/BZip2.h" -#endif /* ADIOS_OOP_H_ */ +#endif /* ADIOS_CPP_H_ */ diff --git a/include/capsule/Heap.h b/include/capsule/Heap.h index 739ec7ff857743b60fe7110feb0dd7c90529911e..5a1fa8d1966093e046b8b646eb6bd9c75cebaaef 100644 --- a/include/capsule/Heap.h +++ b/include/capsule/Heap.h @@ -8,6 +8,10 @@ #ifndef HEAP_H_ #define HEAP_H_ +/// \cond EXCLUDE_FROM_DOXYGEN +#include <vector> +/// \endcond + #include "core/Capsule.h" diff --git a/include/core/Capsule.h b/include/core/Capsule.h index d8c8bf459e7fc62c377edea93ea6f412b4dccfa3..e7b54b5558b021883bce7a89f7be03d840a9849a 100644 --- a/include/core/Capsule.h +++ b/include/core/Capsule.h @@ -8,7 +8,9 @@ #ifndef CAPSULE_H_ #define CAPSULE_H_ -#include "core/Variable.h" +/// \cond EXCLUDE_FROM_DOXYGEN +#include <string> +/// \endcond namespace adios @@ -37,10 +39,8 @@ public: * @param type derived class type * @param accessMode 'w':write, 'r':read, 'a':append * @param rankMPI current MPI rank - * @param cores if using threads */ - Capsule( const std::string type, const std::string accessMode, const int rankMPI, - const bool debugMode ); + Capsule( const std::string type, const std::string accessMode, const int rankMPI, const bool debugMode ); virtual ~Capsule( ); diff --git a/include/core/Engine.h b/include/core/Engine.h index 4543bf872ac27662712d83a7107c41669a19c103..d2adc18e830e3092b60340f82d3faf8a00e35dcc 100644 --- a/include/core/Engine.h +++ b/include/core/Engine.h @@ -23,8 +23,8 @@ #include "mpidummy.h" #endif +#include "ADIOS.h" #include "core/Method.h" -#include "core/Group.h" #include "core/Variable.h" #include "core/Transform.h" #include "core/Transport.h" @@ -43,7 +43,7 @@ class Engine public: #ifdef HAVE_MPI - MPI_Comm m_MPIComm = NULL; ///< only used as reference to MPI communicator passed from parallel constructor, MPI_Comm is a pointer itself. Public as called from C + MPI_Comm m_MPIComm = MPI_COMM_NULL; ///< only used as reference to MPI communicator passed from parallel constructor, MPI_Comm is a pointer itself. Public as called from C #else 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 @@ -52,27 +52,29 @@ public: const std::string m_Name; ///< name used for this engine const std::string m_AccessMode; ///< accessMode for buffers used by this engine const Method& m_Method; ///< associated method containing engine metadata - Group* m_Group = nullptr; ///< associated group to look for variable information int m_RankMPI = 0; ///< current MPI rank process int m_SizeMPI = 1; ///< current MPI processes size + const std::string m_HostLanguage = "C++"; + /** - * Unique constructor based on a method (engine metadata) - * @param engineType given by derived classes - * @param name engine name + * Unique constructor + * @param engineType + * @param name * @param accessMode * @param mpiComm * @param method + * @param debugMode + * @param cores + * @param endMessage */ - Engine( const std::string engineType, const std::string name, const std::string accessMode, - MPI_Comm mpiComm, const Method& method, const bool debugMode = false, const unsigned int cores = 1, - const std::string endMessage = "", const std::string hostLanguage = "C++" ); + Engine( ADIOS& adios, const std::string engineType, const std::string name, const std::string accessMode, + MPI_Comm mpiComm, const Method& method, const bool debugMode, const unsigned int cores, + const std::string endMessage ); virtual ~Engine( ); - void SetDefaultGroup( Group& group ); - /** * Write function that adds static checking on the variable to be passed by values * It then calls its corresponding derived class virtual function @@ -81,47 +83,24 @@ public: * @param values pointer passed from the application */ template< class T > - void Write( const Var variableName, const T* values ) + void Write( Variable<T>& variable, const T* values ) { - Write( variableName, values ); + Write( variable, values ); } - /** - * Write function that adds static checking on the variable to be passed by values. - * It then calls its corresponding derived class virtual function. - * This version accepts a group explicitly. - * @param group group object that contains the variable with variableName - * @param variableName name of variable to the written - * @param values pointer passed from the application - */ - template< class T > - void Write( Group& group, const Var variableName, const T* values ) - { - Write( group, variableName, values ); - } - - /** - * @brief Write functions can be overridden by derived classes. Base class behavior is to: - * 1) Write to Variable values (m_Values) in a group - * 2) Transform the data - * 3) Write to all capsules -> data and metadata - * @param group - * @param variableName - * @param values coming from user app - */ - virtual void Write( Group& group, const std::string variableName, const char* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const unsigned char* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const short* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const unsigned short* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const int* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const unsigned int* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const long int* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const unsigned long int* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const long long int* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const unsigned long long int* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const float* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const double* values ) = 0; - virtual void Write( Group& group, const std::string variableName, const long double* values ) = 0; + virtual void Write( Variable<char>& variable, const char* values ) = 0; + virtual void Write( Variable<unsigned char>& variable, const unsigned char* values ) = 0; + virtual void Write( Variable<short>& variable, const short* values ) = 0; + virtual void Write( Variable<unsigned short>& variable, const unsigned short* values ) = 0; + virtual void Write( Variable<int>& variable, const int* values ) = 0; + virtual void Write( Variable<unsigned int>& variable, const unsigned int* values ) = 0; + virtual void Write( Variable<long int>& variable, const long int* values ) = 0; + virtual void Write( Variable<unsigned long int>& variable, const unsigned long int* values ) = 0; + virtual void Write( Variable<long long int>& variable, const long long int* values ) = 0; + virtual void Write( Variable<unsigned long long int>& variable, const unsigned long long int* values ) = 0; + virtual void Write( Variable<float>& variable, const float* values ) = 0; + virtual void Write( Variable<double>& variable, const double* values ) = 0; + virtual void Write( Variable<long double>& variable, const long double* values ) = 0; /** * @brief Write functions can be overridden by derived classes. Base class behavior is to: @@ -150,30 +129,18 @@ public: protected: - //std::vector< std::shared_ptr<Capsule> > m_Capsules; ///< managed Capsules might not be needed by certain engines + ADIOS& m_ADIOS; ///< reference to ADIOS object that creates this Engine at Open std::vector< std::shared_ptr<Transport> > m_Transports; ///< transports managed const bool m_DebugMode = false; ///< true: additional checks, false: by-pass checks unsigned int m_Cores = 1; const std::string m_EndMessage; ///< added to exceptions to improve debugging - const std::string m_HostLanguage = "C++"; ///< passed from ADIOS class to recognize language calling the ADIOS library - std::vector< std::pair<Group*, std::string> > m_WrittenVariables; + std::set<std::string> m_WrittenVariables; ///< contains the names of the variables that are being written virtual void Init( ); ///< Initialize m_Capsules and m_Transports, called from constructor virtual void InitCapsules( ); ///< Initialize transports from Method, called from Init in constructor. virtual void InitTransports( ); ///< Initialize transports from Method, called from Init in constructor. - /** - * Performs preliminary checks before writing a variable. Throws an exception if checks fail. - * Returns an index to variable type container in Group - * @param group variable group owner object - * @param variableName variable to be checked - * @param hint added information if exception is thrown - * @return index to variable in group type container - */ - unsigned int PreSetVariable( Group& group, const std::string variableName, - const std::string hint ); - /** * Used to verify parameters in m_Method containers * @param itParam iterator to a certain parameter @@ -186,8 +153,6 @@ protected: const std::string parameterName, const std::string hint ) const; - void CheckDefaultGroup( ) const; ///< checks if default group m_Group is nullptr, throws exception if trying to use - bool TransportNamesUniqueness( ) const; ///< checks if transport names are unique among the same types (file I/O) }; diff --git a/include/core/Group.h b/include/core/Group.h deleted file mode 100644 index 55dc46c1ec78937b0b9d6557a3839fce4bdbe8bd..0000000000000000000000000000000000000000 --- a/include/core/Group.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Group.h - * - * Created on: Oct 12, 2016 - * Author: wfg - */ - -#ifndef GROUP_H_ -#define GROUP_H_ - -/// \cond EXCLUDE_FROM_DOXYGEN -#include <map> -#include <string> -#include <memory> //shared_pointer -#include <vector> -#include <ostream> -#include <set> -#include <initializer_list> //SetDimensions -/// \endcond - -#ifdef HAVE_MPI - #include <mpi.h> -#else - #include "mpidummy.h" -#endif - - -#include "core/Variable.h" -#include "core/Attribute.h" -#include "core/Transport.h" -#include "core/Transform.h" -#include "functions/adiosTemplates.h" - - -namespace adios -{ - -using Var = std::string; ///< used for returning variables from DefineVariable -using Dims = std::string; - -/** - * Class that defines each ADIOS Group composed of Variables, Attributes and GlobalBounds (if global variables exist) - */ -class Group -{ - friend class Engine; - -public: - - const std::string m_Name; - 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 - - - - /** - * Empty constructor - */ - Group( ); - - /** - * Empty constructor - * @param debugMode true: additional checks throwing exceptions, false: skip checks - */ - Group( const std::string name, const bool debugMode = false ); - - /** - * @brief Constructor for XML config file - * @param hostLanguage reference from ADIOS class - * @param xmlGroup contains <adios-group (tag excluded)....</adios-group> single group definition from XML config file - * @param transforms passed from ADIOS.m_Transforms, single look up table for all transforms - * @param debugMode - */ - Group( const std::string name, const std::string& xmlGroup, std::vector< std::shared_ptr<Transform> >& transforms, const bool debugMode ); - - - ~Group( ); ///< Using STL containers, no deallocation - - - Dims SetDimensions( std::initializer_list<Var> variables ); ///< returns adios::Dims object from a list of existing adios::Var objects - - /** - * Define a new variable in the group object - * @param name variable name, must be unique in the group. 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 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 transforms collection of Transform objects applied to this variable, sequence matters, default is empty - * @param parameters corresponding parameter used by a Transform object in transforms (index should match), default is empty - */ - Var DefineVariable( const std::string variableName, const std::string type, - const Dims dimensionsCSV = "1", - const Dims globalDimensionsCSV = "", const Dims globalOffsetsCSV = "", - const std::vector<Transform*> transforms = std::vector<Transform*>(), - const std::vector<int> parameters = std::vector<int>() ); - - - template< class T > - Var DefineVariable( const std::string variableName, - const Dims dimensionsCSV = "1", - const Dims globalDimensionsCSV = "", const Dims globalOffsetsCSV = "", - const std::vector<Transform*> transforms = std::vector<Transform*>(), - const std::vector<int> parameters = std::vector<int>() ) - { - return DefineVariable( variableName, GetType<T>(), dimensionsCSV, globalDimensionsCSV, globalOffsetsCSV, transforms, parameters ); - } - - /** - * Sets a variable transform contained in ADIOS Transforms (single container for all groups and variables) - * @param variableName variable to be assigned a transformation - * @param transform corresponding transform object, non-const as a pointer is created and pushed to a vector - * @param parameter optional parameter interpreted by the corresponding Transform, default = -1 - */ - void AddTransform( const Var variableName, Transform& transform, const int parameter = -1 ); - - /** - * Define a new attribute - * @param attributeName attribute name, must be unique. If name exists it removes the current variable. In debug mode program will exit. - * @param type attribute type string or numeric type - * @param value information about the attribute - */ - void DefineAttribute( const std::string attributeName, const std::string type, const std::string value ); - - /** - * @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. - * @param logStream either std::cout standard output, or a std::ofstream file - */ - void Monitor( std::ostream& logStream ) const; - - /** - * Looks for variables defining a variable dimensions and return their actual values in a vector - * @param dimensionsCSV comma separated dimensions "Nx,Ny,Nz" - * @return actual vector values = { Nx, Ny, Nz } - */ - std::vector<unsigned long long int> GetDimensions( const Dims dimensionsCSV ) const; - -private: - - std::set<std::string> m_WrittenVariables; - - bool m_DebugMode = false; ///< if true will do more checks, exceptions, warnings, expect slower code, known at compile time - - std::map< std::string, std::pair< std::string, unsigned int > > m_Variables; ///< Makes variable name unique, key: variable name, value: pair.first = type, pair.second = index in corresponding vector of Variable - - /** - * @brief Contains all group attributes from SAttribute.h - * <pre> - * Key: std::string unique attribute name - * Value: SAttribute, plain-old-data struct - * </pre> - */ - std::map< std::string, Attribute > m_Attributes; - - /** - * Called from XML constructor - * @param xmlGroup contains <adios-group....</adios-group> single group definition from XML config file passing by reference as it could be big - */ - void ParseXMLGroup( const std::string& xmlGroup, std::vector< std::shared_ptr<Transform> >& transforms ); - - /** - * 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; - */ - int SetGlobalBounds( const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) noexcept; - - /** - * Retrieves the value of a variable representing another's variable dimensions. Set with Write - * Must of integer type (from short to unsigned long long int) and positive. - * used by function GetDimensions - * @param variableName variable to be searched in m_SetVariables - * @return variable value - */ - unsigned long long int GetIntVariableValue( const std::string variableName ) const; - - /** - * Looks for variables assigned for dimensions in csv entry (local dimensions, global dimensions, or global offsets), and sets the bool flag IsDimension to true - * If m_DebugMode is true throws an exception if the variable is not found - * @param csv comma separated values string containing the dimension variables to look for - * @param hint message used if exceptions are thrown in debug mode to provide more context - */ - void SetDimensionVariablesFlag( const std::string csv, const std::string hint ); - -}; - - -} //end namespace - - -#endif /* GROUP_H_ */ diff --git a/include/core/Method.h b/include/core/Method.h index 0ead5672aa8460aee3726bdd84d996248e075892..1decbd7aac2511d23145e055d78393d4fbca8403 100644 --- a/include/core/Method.h +++ b/include/core/Method.h @@ -14,7 +14,6 @@ #include <map> /// \endcond -#include "core/Group.h" #include "functions/adiosFunctions.h" namespace adios @@ -32,7 +31,6 @@ public: const bool m_DebugMode = false; ///< true: on, throws exceptions and do additional checks, false: off, faster, but unsafe std::map<std::string, std::string> m_Parameters; ///< method parameters std::vector< std::map<std::string, std::string> > m_TransportParameters; ///< each is a separate Transport containing their own parameters - Group* m_Group = nullptr; ///< Set default group /** * Constructor @@ -40,14 +38,6 @@ public: */ Method( const std::string type, const bool debugMode = false ); - /** - * Constructor that accepts a group reference for access to a default group access - * @param type - * @param group - * @param debugMode - */ - Method( const std::string type, Group& group, const bool debugMode = false ); - ~Method( ); /** @@ -73,7 +63,6 @@ public: AddTransportParameters( type, parameters ); } - void SetDefaultGroup( Group& group ); private: diff --git a/include/core/Transform.h b/include/core/Transform.h index c78c7f18aa32f644fb5e3208431de4ea73d78be8..3c8a08451c82ec845dcbc72597713e0ed7422b82 100644 --- a/include/core/Transform.h +++ b/include/core/Transform.h @@ -26,7 +26,6 @@ class Transform public: - const std::string m_Method; /** diff --git a/include/core/Variable.h b/include/core/Variable.h index cf1a0b7af59b033cdee84fc6513bbe9e38299b04..1473a59791b93657b24e8ad2cbc86606eb380851 100644 --- a/include/core/Variable.h +++ b/include/core/Variable.h @@ -11,20 +11,28 @@ /// \cond EXCLUDE_FROM_DOXYGEN #include <string> #include <vector> -#include <memory> +#include <map> +#include <ostream> //std::ostream in MonitorGroups /// \endcond #include "core/Transform.h" +#include "functions/adiosFunctions.h" +#include "functions/adiosTemplates.h" namespace adios { -class ADIOS; - using Dims = std::vector<size_t>; +struct TransformData +{ + Transform& Operation; ///< pointer to transform object + std::map<std::string, std::string> Parameters; ///< transforms parameters + std::vector<std::size_t> Size; ///< vector that carries the sizes after a transformation is applied +}; + /** * @param Base (parent) class for template derived (child) class CVariable. Required to put CVariable objects in STL containers. */ @@ -34,83 +42,84 @@ class Variable public: - const ADIOS& m_ADIOS; ///< reference to the adios class it belongs to const std::string m_Name; ///< variable name const std::string m_Type; ///< variable type - const Dims m_Dimensions; - const std::string m_DimensionsCSV; ///< comma separated list for variables to search for local dimensions + Dims m_Dimensions; + std::string m_DimensionsCSV; ///< comma separated list for variables to search for local dimensions - const Dims m_GlobalDimensions; - const std::string m_GlobalDimensionsCSV; ///< comma separated list for variables to search for global dimensions + Dims m_GlobalDimensions; + std::string m_GlobalDimensionsCSV; ///< comma separated list for variables to search for global dimensions - const Dims m_GlobalOffsets; - const std::string m_GlobalOffsetsCSV; ///< comma separated list for variables to search for global offsets + Dims m_GlobalOffsets; + std::string m_GlobalOffsetsCSV; ///< comma separated list for variables to search for global offsets const bool m_DebugMode = false; - const T* m_ValuesWrite = nullptr; ///< pointer to values passed from user in ADIOS Write, it might change in ADIOS Read - T* m_ValuesRead = nullptr; + const T* m_AppValues = nullptr; ///< pointer to values passed from user in ADIOS Write, it might change in ADIOS Read + std::vector<T> m_Values; ///< Vector variable returned to user, might be used for zero-copy? - bool IsDimension = false; ///< true: is used as a dimension in another variable (typically scalars), false: none + bool m_IsScalar = false; + const bool m_IsDimension = false; + std::vector< TransformData > m_Transforms; ///< associated transforms, sequence determines application order, e.g. first Transforms[0] then Transforms[1]. Pointer used as reference (no memory management). + Variable( const std::string name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets, const bool debugMode ): + m_Name{ name }, + m_Type{ GetType<T>() }, + m_Dimensions{ dimensions }, + m_GlobalDimensions{ globalDimensions }, + m_GlobalOffsets{ globalOffsets }, + m_DebugMode{ debugMode } + { + if( m_Dimensions == Dims{1} ) + m_IsScalar = true; + } - struct TransformData + template< class ...Args> + void AddTransform( Transform& transform, Args... args ) { - Transform* Transform = nullptr; ///< pointer to transform object - std::map<std::string, std::string> Parameters; ///< transforms parameters - std::vector<std::size_t> Size; ///< vector that carries the sizes after a transformation is applied - }; + std::vector<std::string> parameters = { args... }; + m_Transforms.emplace_back( transform, BuildParametersMap( parameters, m_DebugMode ) ); //need to check + } - std::vector< TransformData > m_Transforms; ///< associated transforms, sequence determines application order, e.g. first Transforms[0] then Transforms[1]. Pointer used as reference (no memory management). + + void Monitor( std::ostream& logInfo ) const noexcept + { + logInfo << "Hello from DataMan Write variable " << m_Name << "\n"; + logInfo << "Type: " << m_Type << "\n"; + logInfo << "Size: " << TotalSize() << " elements\n"; + logInfo << "Payload: " << PayLoadSize() << " bytes\n"; + logInfo << "Values: \n"; + + for( unsigned int i = 0; i < TotalSize(); ++i ) + { + logInfo << m_AppValues[i] << " "; + } + logInfo << "\n"; + } /** - * Constructor for dynamic config file - * @param group - * @param name - * @param dimensionsCSV - * @param globalBoundsIndex - * @param debugMode + * Returns the payload size in bytes + * @return TotalSize * sizeof(T) */ - template< class T > - Variable( const ADIOS& adios, const std::string name, const std::string dimensionsCSV, const std::string globalDimensionsCSV, - const std::string globalOffsetsCSV, const bool debugMode ): - m_ADIOS{ adios }, - m_Name{ name }, - m_DimensionsCSV{ dimensionsCSV }, - m_GlobalDimensionsCSV{ globalDimensionsCSV }, - m_GlobalOffsetsCSV{ globalOffsetsCSV }, - m_DebugMode{ debugMode } - { } + std::size_t PayLoadSize( ) const noexcept + { + return GetTotalSize( m_Dimensions ) * sizeof(T); + } /** - * Constructor for static config file - * @param group - * @param name - * @param dimensionsCSV - * @param globalBoundsIndex - * @param debugMode + * Returns the total size + * @return number of elements */ - template< class T > - Variable( const ADIOS& adios, const std::string name, const Dims dimensionsCSV, const Dims globalDimensionsCSV, - const Dims globalOffsetsCSV, const bool debugMode ): - m_ADIOS{ adios }, - m_Name{ name }, - m_DimensionsCSV{ dimensionsCSV }, - m_GlobalDimensionsCSV{ globalDimensionsCSV }, - m_GlobalOffsetsCSV{ globalOffsetsCSV }, - m_DebugMode{ debugMode } - { } - - - template< class ...Args> - void AddTransform( Transform& transform, Args... args ) + std::size_t TotalSize( ) const noexcept { - std::vector<std::string> parameters = { args... }; - m_Transforms.emplace_back( transform, BuildParametersMap( parameters, m_DebugMode ) ); //need to check + return GetTotalSize( m_Dimensions ); } }; } //end namespace + + +#endif /* VARIABLE_H_ */ diff --git a/include/engine/dataman/DataMan.h b/include/engine/dataman/DataMan.h index 94e1532f0cbe05fddd782bcfee22d7b51f420fa2..348522ec33cd2a5fc0885996f13e6dc5ed1444c1 100644 --- a/include/engine/dataman/DataMan.h +++ b/include/engine/dataman/DataMan.h @@ -8,6 +8,8 @@ #ifndef DATAMAN_H_ #define DATAMAN_H_ +#include <iostream> //must be removed +#include <unistd.h> //must be removed #include "core/Engine.h" #include "capsule/Heap.h" @@ -16,9 +18,6 @@ namespace adios { -namespace engine -{ - class DataMan : public Engine { @@ -34,25 +33,24 @@ public: * @param debugMode * @param hostLanguage */ - DataMan( const std::string name, const std::string accessMode, MPI_Comm mpiComm, - const Method& method, const bool debugMode = false, const unsigned int cores = 1, - const std::string hostLanguage = "C++" ); + DataMan( ADIOS& adios, const std::string name, const std::string accessMode, MPI_Comm mpiComm, + const Method& method, const bool debugMode = false, const unsigned int cores = 1 ); ~DataMan( ); - void Write( Group& group, const std::string variableName, const char* values ); - void Write( Group& group, const std::string variableName, const unsigned char* values ); - void Write( Group& group, const std::string variableName, const short* values ); - void Write( Group& group, const std::string variableName, const unsigned short* values ); - void Write( Group& group, const std::string variableName, const int* values ); - void Write( Group& group, const std::string variableName, const unsigned int* values ); - void Write( Group& group, const std::string variableName, const long int* values ); - void Write( Group& group, const std::string variableName, const unsigned long int* values ); - void Write( Group& group, const std::string variableName, const long long int* values ); - void Write( Group& group, const std::string variableName, const unsigned long long int* values ); - void Write( Group& group, const std::string variableName, const float* values ); - void Write( Group& group, const std::string variableName, const double* values ); - void Write( Group& group, const std::string variableName, const long double* values ); + void Write( Variable<char>& variable, const char* values ); + void Write( Variable<unsigned char>& variable, const unsigned char* values ); + void Write( Variable<short>& variable, const short* values ); + void Write( Variable<unsigned short>& variable, const unsigned short* values ); + void Write( Variable<int>& variable, const int* values ); + void Write( Variable<unsigned int>& variable, const unsigned int* values ); + void Write( Variable<long int>& variable, const long int* values ); + void Write( Variable<unsigned long int>& variable, const unsigned long int* values ); + void Write( Variable<long long int>& variable, const long long int* values ); + void Write( Variable<unsigned long long int>& variable, const unsigned long long int* values ) ; + void Write( Variable<float>& variable, const float* values ); + void Write( Variable<double>& variable, const double* values ); + void Write( Variable<long double>& variable, const long double* values ); void Write( const std::string variableName, const char* values ); void Write( const std::string variableName, const unsigned char* values ); @@ -74,6 +72,7 @@ private: format::BP1Writer m_BP1Writer; ///< format object will provide the required BP functionality to be applied on m_Buffer and m_Transports void Init( ); ///< calls InitCapsules and InitTransports based on Method, called from constructor + void InitCapsules( ); void InitTransports( ); ///< from Transports /** @@ -84,10 +83,37 @@ private: */ std::string GetMdtmParameter( const std::string parameter, const std::map<std::string,std::string>& mdtmParameters ); + + template<class T> + void WriteVariable( Variable<T>& variable, const T* values ) + { + //here comes your magic at Writting now variable.m_UserValues has the data passed by the user + //set variable + variable.m_AppValues = values; + m_WrittenVariables.insert( variable.m_Name ); + + //This part will go away, this is just to monitor variables per rank + MPI_Barrier( m_MPIComm ); + + for( int i = 0; i < m_SizeMPI; ++i ) + { + if( i == m_RankMPI ) + { + std::cout << "Rank: " << m_RankMPI << "\n"; + variable.Monitor( std::cout ); + std::cout << std::endl; + } + else + { + sleep( 0.1 ); + } + } + MPI_Barrier( m_MPIComm ); + } + }; -} //end namespace engine } //end namespace adios diff --git a/include/engine/dataman/DataManTemplates.h b/include/engine/dataman/DataManTemplates.h deleted file mode 100644 index 2051dd5dfdc2fb5a785fac76bee52903e2ed193e..0000000000000000000000000000000000000000 --- a/include/engine/dataman/DataManTemplates.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * DataManTemplates.h - * - * Created on: Jan 18, 2017 - * Author: wfg - */ - -#ifndef DATAMANTEMPLATES_H_ -#define DATAMANTEMPLATES_H_ - -#include <vector> -#include <iostream> - - -#include "core/Group.h" -#include "core/Variable.h" -#include "capsule/Heap.h" -#include "core/Transport.h" -#include "format/BP1Writer.h" - - -namespace adios -{ - -/** - * - * @param group variable owner - * @param variableName string type - * @param variable - * @param buffer heap buffer to writer variables to for disk I/O - * @param transports - * @param bp1Writer - */ -template<class T> -void DataManWriteVariable( const Group& group, const Var variableName, Variable<T>& variable, - Heap& buffer, std::vector< std::shared_ptr<Transport> >& transports, - format::BP1Writer& bp1Writer ) - -{ - //here write your magic, this template replaces C MACROS - std::cout << "Hello from DataMan, writing variable " << variableName << " of typeid(T).name() = " << typeid(T).name() << "\n"; - if( variable.IsDimension ) - { - std::cout << "Which is a dimension variable\n"; - } -} - - - -} //end namespace - - - -#endif /* DATAMANTEMPLATES_H_ */ diff --git a/include/engine/writer/Writer.h b/include/engine/writer/Writer.h index ced2f65ef5232512ec66662a3f254b40fd0cd29e..b9b1d91335f0cdf3aa6eb440b703688485274dac 100644 --- a/include/engine/writer/Writer.h +++ b/include/engine/writer/Writer.h @@ -30,26 +30,24 @@ public: * @param method * @param debugMode */ - Writer( const std::string name, const std::string accessMode, MPI_Comm mpiComm, - const Method& method, const bool debugMode = false, const unsigned int cores = 1, - const std::string hostLanguage = "C++" ); + Writer( ADIOS& adios, const std::string name, const std::string accessMode, MPI_Comm mpiComm, + const Method& method, const bool debugMode = false, const unsigned int cores = 1 ); ~Writer( ); - - void Write( Group& group, const std::string variableName, const char* values ); - void Write( Group& group, const std::string variableName, const unsigned char* values ); - void Write( Group& group, const std::string variableName, const short* values ); - void Write( Group& group, const std::string variableName, const unsigned short* values ); - void Write( Group& group, const std::string variableName, const int* values ); - void Write( Group& group, const std::string variableName, const unsigned int* values ); - void Write( Group& group, const std::string variableName, const long int* values ); - void Write( Group& group, const std::string variableName, const unsigned long int* values ); - void Write( Group& group, const std::string variableName, const long long int* values ); - void Write( Group& group, const std::string variableName, const unsigned long long int* values ); - void Write( Group& group, const std::string variableName, const float* values ); - void Write( Group& group, const std::string variableName, const double* values ); - void Write( Group& group, const std::string variableName, const long double* values ); + void Write( Variable<char>& variable, const char* values ); + void Write( Variable<unsigned char>& variable, const unsigned char* values ); + void Write( Variable<short>& variable, const short* values ); + void Write( Variable<unsigned short>& variable, const unsigned short* values ); + void Write( Variable<int>& variable, const int* values ); + void Write( Variable<unsigned int>& variable, const unsigned int* values ); + void Write( Variable<long int>& variable, const long int* values ); + void Write( Variable<unsigned long int>& variable, const unsigned long int* values ); + void Write( Variable<long long int>& variable, const long long int* values ); + void Write( Variable<unsigned long long int>& variable, const unsigned long long int* values ) ; + void Write( Variable<float>& variable, const float* values ); + void Write( Variable<double>& variable, const double* values ); + void Write( Variable<long double>& variable, const long double* values ); void Write( const std::string variableName, const char* values ); void Write( const std::string variableName, const unsigned char* values ); @@ -79,7 +77,6 @@ private: void Init( ); void InitTransports( ); - /** * Common function * @param group @@ -87,17 +84,20 @@ private: * @param variable */ template< class T > - void WriteVariable( const Group& group, const Var variableName, const Variable<T>& variable ) + void WriteVariable( Variable<T>& variable, const T* values ) { + //set variable + variable.m_AppValues = values; + m_WrittenVariables.insert( variable.m_Name ); //precalculate new metadata and payload sizes - const std::size_t indexSize = m_BP1Writer.GetVariableIndexSize( group, variableName, variable ); - const std::size_t payloadSize = GetTotalSize( group.GetDimensions( variable.DimensionsCSV ) ) * sizeof( T ); + const std::size_t indexSize = m_BP1Writer.GetVariableIndexSize( variable ); + const std::size_t payloadSize = variable.PayLoadSize(); //Buffer reallocation, expensive part - m_TransportFlush = CheckBuffersAllocation( group, variableName, indexSize, payloadSize ); + m_TransportFlush = CheckBuffersAllocation( variable.m_Name, indexSize, payloadSize ); //WRITE INDEX to data buffer and metadata structure (in memory)// - m_BP1Writer.WriteVariableIndex( group, variableName, variable, m_Buffer, m_MetadataSet ); + m_BP1Writer.WriteVariableIndex( variable, m_Buffer, m_MetadataSet ); if( m_TransportFlush == true ) //in batches { @@ -110,8 +110,8 @@ private: } else //Write data to buffer { - //Values to Buffer -> Copy of data, Expensive part might want to use threads if large. Need a model to apply threading. - MemcpyThreads( m_Buffer.m_Data.data(), variable.Values, payloadSize, m_Cores ); + //EXPENSIVE part might want to use threads if large. + MemcpyThreads( m_Buffer.m_Data.data(), variable.m_AppValues, payloadSize, m_Cores ); //update indices m_Buffer.m_DataPosition += payloadSize; m_Buffer.m_DataAbsolutePosition += payloadSize; @@ -120,13 +120,12 @@ private: /** * Check if heap buffers for data and metadata need reallocation or maximum sizes have been reached. - * @param group variable owner * @param variableName name of the variable to be written * @param indexSize precalculated index size * @param payloadSize payload size from variable total size * @return true: transport must be flush and buffers reset, false: buffer is sufficient */ - bool CheckBuffersAllocation( const Group& group, const Var variableName, const std::size_t indexSize, const std::size_t payloadSize ); + bool CheckBuffersAllocation( const std::string variableName, const std::size_t indexSize, const std::size_t payloadSize ); }; diff --git a/include/format/BP1Writer.h b/include/format/BP1Writer.h index 425738d8a69aa74738040d3c3c4e6d626243926a..db6f8e8e2d82096f994536270b5ec860871413c0 100644 --- a/include/format/BP1Writer.h +++ b/include/format/BP1Writer.h @@ -18,7 +18,6 @@ #include "BP1.h" #include "core/Variable.h" -#include "core/Group.h" #include "core/Capsule.h" #include "capsule/Heap.h" #include "functions/adiosTemplates.h" @@ -79,16 +78,14 @@ public: * @return variable index size */ template< class T > - size_t GetVariableIndexSize( const Group& group, const std::string variableName, - const Variable<T> variable ) noexcept + size_t GetVariableIndexSize( const Variable<T>& variable ) noexcept { //size_t indexSize = varEntryLength + memberID + lengthGroupName + groupName + lengthVariableName + lengthOfPath + path + datatype size_t indexSize = 23; //without characteristics - indexSize += group.m_Name.size(); - indexSize += variableName.size(); + indexSize += variable.m_Name.size(); // characteristics 3 and 4, check variable number of dimensions - const std::size_t dimensions = std::count( variable.DimensionsCSV.begin(), variable.DimensionsCSV.end(), ',' ) + 1; //number of commas in CSV + 1 + const std::size_t dimensions = variable.m_Dimensions.size(); //number of commas in CSV + 1 indexSize += 28 * dimensions; //28 bytes per dimension indexSize += 1; //id @@ -105,7 +102,7 @@ public: indexSize += sizeof(T); indexSize += 1; //id //must have an if here - indexSize += 2 + variableName.size(); + indexSize += 2 + variable.m_Name.size(); indexSize += 1; //id } @@ -130,8 +127,8 @@ public: * @param metadataSet */ template< class T > - void WriteVariableIndex( const Group& group, const Var variableName, const Variable<T>& variable, - Heap& buffer, BP1MetadataSet& metadataSet ) noexcept + void WriteVariableIndex( const Variable<T>& variable, Heap& buffer, BP1MetadataSet& metadataSet ) noexcept + { // adapt this part to local variables std::vector<char*> dataBuffers{ buffer.m_Data.data() }; @@ -142,7 +139,7 @@ public: std::vector<std::size_t> metadataPositions{ metadataSet.VarsIndexPosition }; std::vector<unsigned int> variablesCount{ metadataSet.VarsCount }; - WriteVariableCommon( group, variableName, variable, dataBuffers, dataPositions, dataAbsolutePositions, + WriteVariableCommon( variable, dataBuffers, dataPositions, dataAbsolutePositions, metadataBuffers, metadataPositions, variablesCount ); //update positions and varsCount originally passed by value @@ -162,7 +159,7 @@ public: * @param metadataSets */ template< class T > - void WriteVariableIndex( const Group& group, const Var variableName, const Variable<T>& variable, + void WriteVariableIndex( const Variable<T>& variable, std::vector< std::shared_ptr<Capsule> >& capsules, std::vector<BP1MetadataSet>& metadataSets ) noexcept { @@ -185,7 +182,7 @@ public: dataAbsolutePositions.push_back( capsule->m_DataAbsolutePosition ); } - WriteVariableCommon( group, variableName, variable, dataBuffers, dataPositions, dataAbsolutePositions, + WriteVariableCommon( variable, dataBuffers, dataPositions, dataAbsolutePositions, metadataBuffers, metadataPositions, variablesCount ); //update positions and varsCount originally passed by value @@ -207,7 +204,7 @@ private: template<class T> - void WriteVariableCommon( const Group& group, const Var variableName, const Variable<T>& variable, + void WriteVariableCommon( const Variable<T>& variable, std::vector<char*>& dataBuffers, std::vector<size_t>& dataPositions, std::vector<size_t>& dataAbsolutePositions, std::vector<char*>& metadataBuffers, std::vector<size_t>& metadataPositions, @@ -222,14 +219,13 @@ private: //memberID MemcpyToBuffers( metadataBuffers, metadataPositions, variablesCount, 4 ); - //group name, only in metadata - const std::uint16_t lengthGroupName = group.m_Name.length(); - WriteNameRecord( group.m_Name, lengthGroupName, metadataBuffers, metadataPositions ); + //skipping 2 bytes for length of group name which is zero, only in metadata + MovePositions( 2, metadataPositions ); //length of var, will come at the end from this offset //variable name to metadata and data - const std::uint16_t lengthVariableName = variableName.length(); - WriteNameRecord( variableName, lengthVariableName, metadataBuffers, metadataPositions ); - WriteNameRecord( variableName, lengthVariableName, dataBuffers, dataPositions ); + const std::uint16_t lengthVariableName = variable.m_Name.length(); + WriteNameRecord( variable.m_Name, lengthVariableName, metadataBuffers, metadataPositions ); + WriteNameRecord( variable.m_Name, lengthVariableName, dataBuffers, dataPositions ); //skip path (jump 2 bytes, already set to zero) MovePositions( 2, metadataPositions ); //length of var, will come at the end from this offset @@ -251,7 +247,7 @@ private: std::uint8_t characteristicsCounter = 0; //used for characteristics count, characteristics length will be calculated at the end //DIMENSIONS CHARACTERISTIC - const std::vector<unsigned long long int> localDimensions = group.GetDimensions( variable.DimensionsCSV ); + const std::vector<size_t>& localDimensions = variable.m_Dimensions; //write to metadata characteristic //characteristic: dimension @@ -263,13 +259,13 @@ private: MemcpyToBuffers( metadataBuffers, metadataPositions, &dimensionsLength, 2 ); //write in data if it's a dimension variable (scalar) y or n - const char dimensionYorN = ( variable.IsDimension ) ? 'y' : 'n'; + const char dimensionYorN = ( variable.m_IsDimension ) ? 'y' : 'n'; MemcpyToBuffers( dataBuffers, dataPositions, &dimensionYorN, 1 ); MemcpyToBuffers( dataBuffers, dataPositions, &dimensions, 1 ); const std::uint16_t dimensionsLengthInData = dimensions * 27; //27 is from 9 bytes for each: var y/n + local, var y/n + global dimension, var y/n + global offset MemcpyToBuffers( dataBuffers, dataPositions, &dimensionsLengthInData, 2 ); - if( variable.GlobalBoundsIndex == -1 ) //local variable + if( variable.m_GlobalDimensions.empty() ) //local variable { WriteDimensionRecord( metadataBuffers, metadataPositions, localDimensions, 16 ); WriteDimensionRecord( dataBuffers, dataPositions, localDimensions, 18, true ); //not using memberID for now @@ -287,8 +283,8 @@ private: } else //global variable { - const std::vector<unsigned long long int> globalDimensions = group.GetDimensions( group.m_GlobalBounds[variable.GlobalBoundsIndex].first ); - const std::vector<unsigned long long int> globalOffsets = group.GetDimensions( group.m_GlobalBounds[variable.GlobalBoundsIndex].second ); + const std::vector<std::size_t>& globalDimensions = variable.m_GlobalDimensions; + const std::vector<std::size_t>& globalOffsets = variable.m_GlobalOffsets; WriteDimensionRecord( metadataBuffers, metadataPositions, localDimensions, globalDimensions, globalOffsets ); WriteDimensionRecord( dataBuffers, dataPositions, localDimensions, globalDimensions, globalOffsets, true ); @@ -308,32 +304,32 @@ private: //VALUE for SCALAR or STAT min, max for ARRAY //Value for scalar - if( variable.DimensionsCSV == "1" ) //scalar //just doing string scalars for now (by name), needs to be modified when user passes value + if( variable.m_IsScalar ) //scalar //just doing string scalars for now (by name), needs to be modified when user passes value { characteristicID = characteristic_value; - const std::int16_t lengthOfName = variableName.length(); + const std::int16_t lengthOfName = variable.m_Name.length(); //metadata MemcpyToBuffers( metadataBuffers, metadataPositions, &characteristicID, 1 ); - WriteNameRecord( variableName, lengthOfName, metadataBuffers, metadataPositions ); + WriteNameRecord( variable.m_Name, lengthOfName, metadataBuffers, metadataPositions ); //data MemcpyToBuffers( dataBuffers, dataPositions, &characteristicID, 1 ); const std::int16_t lengthOfCharacteristic = 2 + lengthOfName; MemcpyToBuffers( dataBuffers, dataPositions, &lengthOfCharacteristic, 2 ); //added in data - WriteNameRecord( variableName, lengthOfName, dataBuffers, dataPositions ); + WriteNameRecord( variable.m_Name, lengthOfName, dataBuffers, dataPositions ); } else // Stat -> Min, Max for arrays, { if( m_Verbosity == 0 ) //default verbose { //Get min and max - const std::size_t valuesSize = GetTotalSize( localDimensions ); + const std::size_t valuesSize = variable.TotalSize(); T min, max; if( valuesSize >= 10000000 ) //ten million? this needs actual results //here we can make decisions for threads based on valuesSize - GetMinMax( variable.Values, valuesSize, min, max, m_Cores ); //here we can add cores from constructor + GetMinMax( variable.m_AppValues, valuesSize, min, max, m_Cores ); //here we can add cores from constructor else - GetMinMax( variable.Values, valuesSize, min, max ); + GetMinMax( variable.m_AppValues, valuesSize, min, max ); //set characteristic ids for min and max characteristicID = characteristic_stat; @@ -405,9 +401,9 @@ private: * @param addType true: for data buffers, false: for metadata buffer and data characteristic */ void WriteDimensionRecord( std::vector<char*>& buffers, std::vector<std::size_t>& positions, - const std::vector<unsigned long long int>& localDimensions, - const std::vector<unsigned long long int>& globalDimensions, - const std::vector<unsigned long long int>& globalOffsets, + const std::vector<std::size_t>& localDimensions, + const std::vector<std::size_t>& globalDimensions, + const std::vector<std::size_t>& globalOffsets, const bool addType = false ); /** @@ -419,7 +415,7 @@ private: * @param addType true: for data buffers, false: for metadata buffer and data characteristic */ void WriteDimensionRecord( std::vector<char*>& buffers, std::vector<std::size_t>& positions, - const std::vector<unsigned long long int>& localDimensions, + const std::vector<std::size_t>& localDimensions, const unsigned int skip, const bool addType = false ); diff --git a/include/functions/adiosFunctions.h b/include/functions/adiosFunctions.h index f43a7f3c9b44e027164234e3e4880acc5d3a6cd8..017816a66b0ddd3674aff3b2a00ada2cebfb1e65 100644 --- a/include/functions/adiosFunctions.h +++ b/include/functions/adiosFunctions.h @@ -13,6 +13,7 @@ #include <vector> #include <map> #include <cstring> //std::size_t +#include <memory> //std::shared_ptr /// \endcond #ifdef HAVE_MPI @@ -21,9 +22,7 @@ #include "mpidummy.h" #endif - -#include "core/Group.h" - +#include "core/Transform.h" namespace adios { @@ -84,9 +83,9 @@ void GetPairsFromTag( const std::string& fileContent, const std::string tag, * @param transforms return the modified transforms vector if there are variables with transformations * @param groups passed returns the map of groups defined in fileContent */ -void SetMembers( const std::string& fileContent, const MPI_Comm mpiComm, - std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, - std::map< std::string, Group >& groups ); +//void SetMembers( const std::string& fileContent, const MPI_Comm mpiComm, +// std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, +// std::map< std::string, Group >& groups ); /** @@ -98,9 +97,9 @@ void SetMembers( const std::string& fileContent, const MPI_Comm mpiComm, * @param transforms return the modified transforms vector if there are variables with transformations * @param groups passed returns the map of groups defined in fileContent */ -void InitXML( const std::string xmlConfigFile, const MPI_Comm mpiComm, const bool debugMode, - std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, - std::map< std::string, Group >& groups ); +//void InitXML( const std::string xmlConfigFile, const MPI_Comm mpiComm, const bool debugMode, +// std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, +// std::map< std::string, Group >& groups ); /** @@ -108,7 +107,7 @@ void InitXML( const std::string xmlConfigFile, const MPI_Comm mpiComm, const boo * @param dimensions input containing size on each dimension {Nx, Ny, Nz} * @return product of all dimensions Nx * Ny * Nz */ -unsigned long long int GetTotalSize( const std::vector<unsigned long long int>& dimensions ); +std::size_t GetTotalSize( const std::vector<size_t>& dimensions ); /** diff --git a/include/functions/adiosTemplates.h b/include/functions/adiosTemplates.h index 9c97f221523fcb182b0f0d2231089de75d2eaea4..96d0969a128adb4baf291b752f57dbb229fb1391 100644 --- a/include/functions/adiosTemplates.h +++ b/include/functions/adiosTemplates.h @@ -12,6 +12,7 @@ #include <cstring> //std::memcpy #include <vector> #include <thread> +#include <set> /// \endcond @@ -33,6 +34,8 @@ template<> inline std::string GetType<int>() noexcept { return "int"; } template<> inline std::string GetType<unsigned int>() noexcept { return "unsigned int"; } template<> inline std::string GetType<long int>() noexcept { return "long int"; } template<> inline std::string GetType<unsigned long int>() noexcept { return "unsigned long int"; } +template<> inline std::string GetType<long long int>() noexcept { return "long long int"; } +template<> inline std::string GetType<unsigned long long int>() noexcept { return "unsigned long long int"; } template<> inline std::string GetType<float>() noexcept { return "float"; } template<> inline std::string GetType<double>() noexcept { return "double"; } template<> inline std::string GetType<long double>() noexcept { return "long double"; } @@ -100,9 +103,9 @@ void MemcpyThreads( T* destination, const U* source, std::size_t count, const un return; } - const unsigned long long int stride = count/cores; - const unsigned long long int remainder = count % cores; - const unsigned long long int last = stride + remainder; + const std::size_t stride = count/cores; + const std::size_t remainder = count % cores; + const std::size_t last = stride + remainder; std::vector<std::thread> memcpyThreads; memcpyThreads.reserve( cores ); diff --git a/src/ADIOS.cpp b/src/ADIOS.cpp index 6c5f29a01022998c5838a4c4682f348b7bb6ca68..1020f05330b16aa9cd0958d6bee1a999dd72cc43 100644 --- a/src/ADIOS.cpp +++ b/src/ADIOS.cpp @@ -18,36 +18,36 @@ //Engines #include "engine/writer/Writer.h" #include "engine/dataman/DataMan.h" -#include "engine/vis/Vis.h" +//#include "engine/vis/Vis.h" namespace adios { -ADIOS::ADIOS( ) +ADIOS::ADIOS( const bool debugMode ): + m_DebugMode{ debugMode } { - MPI_Comm_rank( m_MPIComm, &m_RankMPI ); - MPI_Comm_size( m_MPIComm, &m_SizeMPI ); + InitMPI( ); } -ADIOS::ADIOS( const std::string xmlConfigFile, const bool debugMode ): - m_XMLConfigFile{ xmlConfigFile }, +ADIOS::ADIOS( const std::string configFileName, const bool debugMode ): + m_ConfigFile{ configFileName }, m_DebugMode{ debugMode } { - InitXML( m_XMLConfigFile, m_MPIComm, m_DebugMode, m_HostLanguage, m_Transforms, m_Groups ); + InitMPI( ); + // InitXML( m_ConfigFile, m_MPIComm, m_DebugMode, m_Transforms ); } ADIOS::ADIOS( const std::string xmlConfigFile, const MPI_Comm mpiComm, const bool debugMode ): m_MPIComm{ mpiComm }, - m_XMLConfigFile{ xmlConfigFile }, + m_ConfigFile{ xmlConfigFile }, m_DebugMode{ debugMode } { - MPI_Comm_rank( m_MPIComm, &m_RankMPI ); - MPI_Comm_size( m_MPIComm, &m_SizeMPI ); - InitXML( m_XMLConfigFile, m_MPIComm, m_DebugMode, m_HostLanguage, m_Transforms, m_Groups ); + InitMPI( ); + //InitXML( m_XMLConfigFile, m_MPIComm, m_DebugMode, m_HostLanguage, m_Transforms, m_Groups ); } @@ -55,8 +55,7 @@ ADIOS::ADIOS( const MPI_Comm mpiComm, const bool debugMode ): m_MPIComm{ mpiComm }, m_DebugMode{ debugMode } { - MPI_Comm_rank( m_MPIComm, &m_RankMPI ); - MPI_Comm_size( m_MPIComm, &m_SizeMPI ); + InitMPI( ); } @@ -64,16 +63,10 @@ ADIOS::~ADIOS( ) { } -Group& ADIOS::DeclareGroup( const std::string groupName ) +void ADIOS::InitMPI( ) { - if( m_DebugMode == true ) - { - if( m_Groups.count( groupName ) == 1 ) - throw std::invalid_argument( "ERROR: group " + groupName + " already exist, from call to DeclareGroup\n" ); - } - - m_Groups.emplace( groupName, Group( groupName, m_DebugMode ) ); - return m_Groups.at( groupName ); + MPI_Comm_rank( m_MPIComm, &m_RankMPI ); + MPI_Comm_size( m_MPIComm, &m_SizeMPI ); } @@ -103,7 +96,7 @@ std::shared_ptr<Engine> ADIOS::Open( const std::string name, const std::string a if( type == "Writer" || type == "writer" ) { - return std::make_shared<Writer>( name, accessMode, mpiComm, method, m_DebugMode, cores, m_HostLanguage ); + return std::make_shared<Writer>( *this, name, accessMode, mpiComm, method, m_DebugMode, cores ); } else if( type == "SIRIUS" || type == "sirius" || type == "Sirius" ) { @@ -112,11 +105,11 @@ std::shared_ptr<Engine> ADIOS::Open( const std::string name, const std::string a } else if( type == "DataMan" ) { - return std::make_shared<engine::DataMan>( name, accessMode, mpiComm, method, m_DebugMode, cores, m_HostLanguage ); + return std::make_shared<DataMan>( *this, name, accessMode, mpiComm, method, m_DebugMode, cores ); } else if( type == "Vis" ) { - return std::make_shared<engine::Vis>( name, accessMode, mpiComm, method, m_DebugMode, cores, m_HostLanguage ); + //return std::make_shared<Vis>( *this, name, accessMode, mpiComm, method, m_DebugMode, cores ); } else { @@ -156,18 +149,20 @@ std::shared_ptr<Engine> ADIOS::Open( const std::string name, const std::string a } -void ADIOS::MonitorGroups( std::ostream& logStream ) const +void ADIOS::MonitorVariables( std::ostream& logStream ) const { - for( auto& groupPair : m_Groups ) + logStream << "\tVariable \t Type\n"; + + for( auto& variablePair : m_Variables ) { - logStream << "Group:..." << groupPair.first << "\n"; - groupPair.second.Monitor( logStream ); + logStream << "Variable:..." << variablePair.first << "\n"; + //variablePair.second.Monitor( logStream ); } } //PRIVATE FUNCTIONS BELOW -void ADIOS::CheckVariable( const std::string name, const Dims& dimensions ) const +void ADIOS::CheckVariableInput( const std::string name, const Dims& dimensions ) const { if( m_DebugMode == true ) { @@ -180,6 +175,17 @@ void ADIOS::CheckVariable( const std::string name, const Dims& dimensions ) cons } +void ADIOS::CheckVariableName( std::map< std::string, std::pair< std::string, unsigned int > >::const_iterator itVariable, + const std::string name, const std::string hint ) const +{ + if( m_DebugMode == true ) + { + if( itVariable == m_Variables.end() ) + throw std::invalid_argument( "ERROR: variable " + name + " does not exist " + hint + "\n" ); + } +} + + void ADIOS::CheckMethod( std::map< std::string, Method >::const_iterator itMethod, const std::string methodName, const std::string hint ) const { diff --git a/src/core/Engine.cpp b/src/core/Engine.cpp index 3c63ac8e8e9190a9085e2e7ade98a92132807d87..8e3dcb4ac1a5fa124b3bfdc29d11a9830622468a 100644 --- a/src/core/Engine.cpp +++ b/src/core/Engine.cpp @@ -15,20 +15,18 @@ namespace adios { -Engine::Engine( const std::string engineType, const std::string name, const std::string accessMode, - const MPI_Comm mpiComm, const Method& method, - const bool debugMode, const unsigned int cores, const std::string endMessage, - const std::string hostLanguage ): +Engine::Engine( ADIOS& adios, const std::string engineType, const std::string name, const std::string accessMode, + const MPI_Comm mpiComm, const Method& method, const bool debugMode, const unsigned int cores, + const std::string endMessage ): m_MPIComm{ mpiComm }, m_EngineType{ engineType }, m_Name{ name }, m_AccessMode{ accessMode }, m_Method{ method }, - m_Group{ method.m_Group }, + m_ADIOS{ adios }, m_DebugMode{ debugMode }, m_Cores{ cores }, - m_EndMessage{ endMessage }, - m_HostLanguage{ hostLanguage } + m_EndMessage{ endMessage } { MPI_Comm_rank( m_MPIComm, &m_RankMPI ); MPI_Comm_size( m_MPIComm, &m_SizeMPI ); @@ -38,30 +36,8 @@ Engine::Engine( const std::string engineType, const std::string name, const std: Engine::~Engine( ) { } -void Engine::SetDefaultGroup( Group& group ) -{ - m_Group = &group; -} - //PROTECTED -unsigned int Engine::PreSetVariable( Group& group, const std::string variableName, - const std::string hint ) -{ - auto itVariable = group.m_Variables.find( variableName ); - - if( m_DebugMode == true ) - { - if( itVariable == group.m_Variables.end() ) - throw std::invalid_argument( "ERROR: variable " + variableName + " doesn't exist " + hint + ".\n" ); - } - - group.m_WrittenVariables.insert( variableName ); // group tracks its own written variables for dimensions - m_WrittenVariables.push_back( std::make_pair( &group, variableName ) ); - const unsigned int index = itVariable->second.second; - return index; -} - void Engine::Close( int transportIndex ) { @@ -97,17 +73,6 @@ void Engine::CheckParameter( const std::map<std::string, std::string>::const_ite } - -void Engine::CheckDefaultGroup( ) const -{ - if( m_DebugMode == true ) - { - if( m_Group == nullptr ) - throw std::invalid_argument( "ERROR: default group in engine " + m_Name + " is nullptr, check Method\n" ); - } -} - - bool Engine::TransportNamesUniqueness( ) const { auto lf_CheckTransportsType = [&]( const std::set<std::string>& specificType ) -> bool diff --git a/src/core/Group.cpp b/src/core/Group.cpp deleted file mode 100644 index 003e5aa66592f2ded980cb9572420ce9f22c3354..0000000000000000000000000000000000000000 --- a/src/core/Group.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/* - * Group.cpp - * - * Created on: Oct 12, 2016 - * Author: wfg - */ - -/// \cond EXCLUDED_FROM_DOXYGEN -#include <algorithm> // std::find -#include <sstream> // std::istringstream -/// \endcond - - -#include "core/Group.h" -#include "core/Support.h" -#include "functions/adiosFunctions.h" - - -namespace adios -{ - -Group::Group( ) -{ } - - -Group::Group( const std::string name, const bool debugMode ): - m_Name{ name }, - m_DebugMode{ debugMode } -{ } - - -Group::Group( const std::string name, const std::string& xmlGroup, std::vector< std::shared_ptr<Transform> >& transforms, - const bool debugMode ): - m_Name{ name }, - m_DebugMode{ debugMode } -{ - ParseXMLGroup( xmlGroup, transforms ); -} - - -Group::~Group( ) -{ } - - -Dims Group::SetDimensions( std::initializer_list<Var> variableList ) -{ - if( m_DebugMode == true ) - { - if( variableList.size() == 0 ) - throw std::invalid_argument( "ERROR: variableList is empty, in call to SetDimensions\n" ); - } - - Dims dimensionsCSV; - for( const auto variable : variableList ) - { - if( m_DebugMode == true ) - { - if( variable.find(",") != variable.npos ) - throw std::invalid_argument( "ERROR: variable can't contain a comma character, in call to SetDimensions\n" ); - } - dimensionsCSV += variable + ","; - } - dimensionsCSV.pop_back(); //remove last comma - return dimensionsCSV; -} - - -Var Group::DefineVariable( const std::string variableName, const std::string type, - const Dims dimensionsCSV, - const Dims globalDimensionsCSV, const Dims globalOffsetsCSV, - std::vector<Transform*> transforms, std::vector<int> parameters ) -{ - auto lf_CheckDimensionVariables = [&]( const std::string csv, const std::string dimensionType, const std::string variableName ) - { - if( csv.empty() == false && csv != "1" ) //skip scalars - SetDimensionVariablesFlag( csv, " in " + dimensionType + " of variable " + variableName ); - }; - - //BODY OF FUNCTION - if( m_DebugMode == true ) - { - if( m_Variables.count( variableName ) == 1 ) - throw std::invalid_argument( "ERROR: variable " + variableName + " already exists, in call to DefineVariable\n" ); - - if( dimensionsCSV.empty() == true ) - throw std::invalid_argument( "ERROR: variable " + variableName + " dimensions can't be empty, in call to DefineVariable\n" ); - } - - //Check for dimension variables - lf_CheckDimensionVariables( dimensionsCSV, "local dimensions", variableName ); - lf_CheckDimensionVariables( globalDimensionsCSV, "global dimensions", variableName ); - lf_CheckDimensionVariables( globalOffsetsCSV, "global offsets", variableName ); - - const int globalBoundsIndex = SetGlobalBounds( globalDimensionsCSV, globalOffsetsCSV ); - - if( IsTypeAlias<char>( type, Support::DatatypesAliases ) == true ) - { - m_Char.push_back( Variable<char>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_Char.size()-1 ); - } - else if( IsTypeAlias<unsigned char>( type, Support::DatatypesAliases ) == true ) - { - m_UChar.push_back( Variable<unsigned char>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_UChar.size()-1 ); - } - else if( IsTypeAlias<short>( type, Support::DatatypesAliases ) == true ) - { - m_Short.push_back( Variable<short>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_Short.size()-1 ); - } - else if( IsTypeAlias<unsigned short>( type, Support::DatatypesAliases ) == true ) - { - m_UShort.push_back( Variable<unsigned short>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_UShort.size()-1 ); - } - else if( IsTypeAlias<int>( type, Support::DatatypesAliases ) == true ) - { - m_Int.push_back( Variable<int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_Int.size()-1 ); - } - else if( IsTypeAlias<unsigned int>( type, Support::DatatypesAliases ) == true ) - { - m_UInt.push_back( Variable<unsigned int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_UInt.size()-1 ); - } - else if( IsTypeAlias<long int>( type, Support::DatatypesAliases ) == true ) - { - m_LInt.push_back( Variable<long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_LInt.size()-1 ); - } - else if( IsTypeAlias<unsigned long int>( type, Support::DatatypesAliases ) == true ) - { - m_ULInt.push_back( Variable<unsigned long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_ULInt.size()-1 ); - } - else if( IsTypeAlias<long long int>( type, Support::DatatypesAliases ) == true ) - { - m_LLInt.push_back( Variable<long long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_LLInt.size()-1 ); - } - else if( IsTypeAlias<unsigned long long int>( type, Support::DatatypesAliases ) == true ) - { - m_ULLInt.push_back( Variable<unsigned long long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_ULLInt.size()-1 ); - } - else if( IsTypeAlias<float>( type, Support::DatatypesAliases ) == true ) - { - m_Float.push_back( Variable<float>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_Float.size()-1 ); - } - else if( IsTypeAlias<double>( type, Support::DatatypesAliases ) == true ) - { - m_Double.push_back( Variable<double>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_Double.size()-1 ); - } - else if( IsTypeAlias<long double>( type, Support::DatatypesAliases ) == true ) - { - m_LDouble.push_back( Variable<long double>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters, false } ); - m_Variables[variableName] = std::make_pair( type, m_LDouble.size()-1 ); - } - else - { - if( m_DebugMode == true ) - throw std::invalid_argument( "ERROR: type " + type + " not supported, in call to DefineVariable.\n" ); - } - return variableName; -} - - -void Group::AddTransform( const std::string variableName, Transform& transform, const int parameter ) -{ - auto itVariable = m_Variables.find( variableName ); - - if( m_DebugMode == true ) - { - if( itVariable == m_Variables.end() ) //variable doesn't exists - throw std::invalid_argument( "ERROR: variable " + variableName + " doesn't exist, in call to SetTransform.\n" ); - } - - const std::string type( itVariable->second.first ); - const unsigned int index = itVariable->second.second; - - if( IsTypeAlias<char>( type, Support::DatatypesAliases ) == true ) - { - m_Char[index].Transforms.push_back( &transform ); - m_Char[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<unsigned char>( type, Support::DatatypesAliases ) == true ) - { - m_UChar[index].Transforms.push_back( &transform ); - m_UChar[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<short>( type, Support::DatatypesAliases ) == true ) - { - m_Short[index].Transforms.push_back( &transform ); - m_Short[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<unsigned short>( type, Support::DatatypesAliases ) == true ) - { - m_UShort[index].Transforms.push_back( &transform ); - m_UShort[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<int>( type, Support::DatatypesAliases ) == true ) - { - m_Int[index].Transforms.push_back( &transform ); - m_Int[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<unsigned int>( type, Support::DatatypesAliases ) == true ) - { - m_UInt[index].Transforms.push_back( &transform ); - m_UInt[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<long int>( type, Support::DatatypesAliases ) == true ) - { - m_LInt[index].Transforms.push_back( &transform ); - m_LInt[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<unsigned long int>( type, Support::DatatypesAliases ) == true ) - { - m_ULInt[index].Transforms.push_back( &transform ); - m_ULInt[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<unsigned long long int>( type, Support::DatatypesAliases ) == true ) - { - m_ULLInt[index].Transforms.push_back( &transform ); - m_ULLInt[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<float>( type, Support::DatatypesAliases ) == true ) - { - m_Float[index].Transforms.push_back( &transform ); - m_Float[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<double>( type, Support::DatatypesAliases ) == true ) - { - m_Double[index].Transforms.push_back( &transform ); - m_Double[index].Parameters.push_back( parameter ); - } - else if( IsTypeAlias<long double>( type, Support::DatatypesAliases ) == true ) - { - m_LDouble[index].Transforms.push_back( &transform ); - m_LDouble[index].Parameters.push_back( parameter ); - } -} - - -void Group::DefineAttribute( const std::string attributeName, const std::string type, const std::string value ) -{ - auto lf_GetTypeID = []( const std::string type, const bool debugMode ) -> const char - { - char typeID = '\0'; - - if( type == "string" ) - typeID = '0'; - else if( type == "numeric" ) - typeID = '1'; - else - { - if( debugMode == true ) - throw std::invalid_argument( "ERROR: type " + type + " must be string or numeric, " - "in call to DefineAttribute\n" ); - } - - return typeID; - }; - - - if( m_DebugMode == true ) - { - if( m_Attributes.count( attributeName ) == 0 ) //attribute doesn't exists - m_Attributes.emplace( attributeName, Attribute{ lf_GetTypeID( type, m_DebugMode ), value } ); - else //name is found - throw std::invalid_argument( "ERROR: attribute " + attributeName + " exists, NOT setting a new variable\n" ); - } - else - { - m_Attributes.emplace( attributeName, Attribute{ lf_GetTypeID( type, m_DebugMode ), value } ); - } -} - - -unsigned long long int Group::GetIntVariableValue( const std::string variableName ) const -{ - if( m_DebugMode == true ) - { - if( m_WrittenVariables.count( variableName ) == 0 ) - throw std::invalid_argument( "ERROR: variable value for " + variableName + " was not set with Write function\n" ); - } - - const std::string type( m_Variables.at( variableName ).first ); - const unsigned int index = m_Variables.at( variableName ).second; - long long int value = -1; - - if( IsTypeAlias<short>( type, Support::DatatypesAliases ) == true ) - value = *( m_Short[index].Values ); - - else if( IsTypeAlias<unsigned short>( type, Support::DatatypesAliases ) == true ) - value = *( m_UShort[index].Values ); - - else if( IsTypeAlias<int>( type, Support::DatatypesAliases ) == true ) - value = *( m_Int[index].Values ); - - else if( IsTypeAlias<unsigned int>( type, Support::DatatypesAliases ) == true ) - value = *( m_UInt[index].Values ); - - else if( IsTypeAlias<long int>( type, Support::DatatypesAliases ) == true ) - value = *( m_LInt[index].Values ); - - else if( IsTypeAlias<unsigned long int>( type, Support::DatatypesAliases ) == true ) - value = *( m_ULInt[index].Values ); - - else if( IsTypeAlias<long long int>( type, Support::DatatypesAliases ) == true ) - value = *( m_LLInt[index].Values ); - - else if( IsTypeAlias<unsigned long long int>( type, Support::DatatypesAliases ) == true ) - value = *( m_ULLInt[index].Values ); - - else - { - if( m_DebugMode == true ) - throw std::invalid_argument( "ERROR: variable " + variableName + " must be of integer type : short, int or associated type (long int, unsigned long int, etc.)\n" ); - } - - if( m_DebugMode == true ) - { - if( value <= 0 ) - throw std::invalid_argument( "ERROR: variable " + variableName + " must be >= 0 to represent a dimension\n" ); - } - - return value; -} - - -std::vector<unsigned long long int> Group::GetDimensions( const std::string dimensionsCSV ) const -{ - if( dimensionsCSV == "1" ) //scalar - { - return std::vector<unsigned long long int>{ 1 }; - } - - std::vector<unsigned long long int> dimensions; - - if( dimensionsCSV.find(',') == dimensionsCSV.npos ) //check if 1D - { - const std::string dimension( dimensionsCSV ); - dimensions.push_back( GetIntVariableValue( dimension ) ); - return dimensions; - } - - std::istringstream dimensionsSS( dimensionsCSV ); - std::string dimension; - while( std::getline( dimensionsSS, dimension, ',' ) ) //need to test - { - dimensions.push_back( GetIntVariableValue( dimension ) ); - } - - return dimensions; -} - - -void Group::Monitor( std::ostream& logStream ) const -{ - logStream << "\tVariable \t Type\n"; - for( const auto& variablePair : m_Variables ) - { - logStream << "\t" << variablePair.first << " \t " << variablePair.second.first << "\n"; - } - logStream << "\n"; - - logStream << "\tAttribute \t Type \t Value \n"; - for( const auto& attributePair : m_Attributes ) - { - logStream << "\t" << attributePair.first << " \t " << attributePair.second.TypeID << " \t " << attributePair.second.Value << "\n"; - } - logStream << "\n"; -} - - -//PRIVATE FUNCTIONS BELOW -void Group::ParseXMLGroup( const std::string& xmlGroup, std::vector< std::shared_ptr<Transform> >& transforms ) -{ - std::string::size_type currentPosition( 0 ); - 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; //end of current group - - if( tag == "</global-bounds>" ) - { - globalDimensionsCSV.clear(); //used for variables - globalOffsetsCSV.clear(); //used for variables - } - - if( m_DebugMode == true ) - { - if( tag.size() < 2 ) - throw std::invalid_argument( "ERROR: wrong tag " + tag + " when reading group \n" ); //check < or <=) - } - tag = tag.substr( 1, tag.size() - 2 ); //eliminate < > - - //Get pairs from tag - std::vector< std::pair<const std::string, const std::string> > pairs; - GetPairsFromTag( xmlGroup, tag, pairs ); - - //Check based on tagName - const std::string tagName( tag.substr( 0, tag.find_first_of(" \t\n\r") ) ); - - if( tagName == "var" ) //assign a Group variable - { - std::string name, type, dimensionsCSV("1"); - std::vector<std::string> transformNames; - - for( auto& pair : pairs ) //loop through all pairs - { - if( pair.first == "name" ) name = pair.second; - else if( pair.first == "type" ) type = pair.second; - else if( pair.first == "dimensions" ) dimensionsCSV = pair.second; - else if( pair.first == "transform" ) transformNames.push_back( pair.second ); - } - - if( transformNames.empty() == true ) //no transforms - { - DefineVariable( name, type, dimensionsCSV, globalDimensionsCSV, globalOffsetsCSV ); - } - else - { - std::vector<short> transformIndices; - std::vector<short> parameters; - SetTransformsHelper( transformNames, transforms, m_DebugMode, transformIndices, parameters ); - - for( unsigned short t = 0; t < transformIndices.size(); ++t ) - { - AddTransform( name, *transforms[t], parameters[t] ); - } - } - } - else if( tagName == "attribute" ) - { - std::string name, value, type; - for( auto& pair : pairs ) //loop through all pairs - { - if( pair.first == "name" ) name = pair.second; - else if( pair.first == "value" ) value = pair.second; - else if( pair.first == "type" ) type = pair.second; - } - DefineAttribute( name, type, value ); - } - else if( tagName == "global-bounds" ) - { - for( auto& pair : pairs ) //loop through all pairs - { - 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( globalOffsetsCSV.empty() ) - throw std::invalid_argument( "ERROR: offsets missing in global-bounds tag\n"); - } - } - } //end while loop -} - - -int Group::SetGlobalBounds( const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) noexcept -{ - if( globalDimensionsCSV.empty() || globalOffsetsCSV.empty() ) - return -1; - - int globalBoundsIndex = -1; - const auto globalBounds = std::make_pair( globalDimensionsCSV, globalOffsetsCSV ); - auto itGlobalBounds = std::find( m_GlobalBounds.begin(), m_GlobalBounds.end(), globalBounds ); - - if( itGlobalBounds != m_GlobalBounds.end() ) - { - globalBoundsIndex = std::distance( m_GlobalBounds.begin(), itGlobalBounds ); - } - else - { - m_GlobalBounds.push_back( globalBounds ); - globalBoundsIndex = m_GlobalBounds.size(); - } - - return globalBoundsIndex; -} - - -void Group::SetDimensionVariablesFlag( const std::string csv, const std::string hint ) -{ - auto lf_SetVariableFlag = [&]( const std::string variableName, const std::string hint, const bool debugMode ) - { - auto itVariable = m_Variables.find( variableName ); - if( debugMode == true ) - { - if( itVariable == m_Variables.end() ) - throw std::invalid_argument( "ERROR: dimension variable " + variableName + " not previously defined\n" ); - } - - const std::string type( itVariable->second.first ); - const unsigned int index = itVariable->second.second; - - if( IsTypeAlias<short>( type, Support::DatatypesAliases ) == true ) - m_Short[index].IsDimension = true; - - else if( IsTypeAlias<unsigned short>( type, Support::DatatypesAliases ) == true ) - m_UShort[index].IsDimension = true; - - else if( IsTypeAlias<int>( type, Support::DatatypesAliases ) == true ) - m_Int[index].IsDimension = true; - - else if( IsTypeAlias<unsigned int>( type, Support::DatatypesAliases ) == true ) - m_UInt[index].IsDimension = true; - - else if( IsTypeAlias<long int>( type, Support::DatatypesAliases ) == true ) - m_LInt[index].IsDimension = true; - - else if( IsTypeAlias<unsigned long int>( type, Support::DatatypesAliases ) == true ) - m_ULInt[index].IsDimension = true; - - else if( IsTypeAlias<long long int>( type, Support::DatatypesAliases ) == true ) - m_LLInt[index].IsDimension = true; - - else if( IsTypeAlias<unsigned long long int>( type, Support::DatatypesAliases ) == true ) - m_ULLInt[index].IsDimension = true; - - else - { - if( m_DebugMode == true ) - throw std::invalid_argument( "ERROR: dimension variable " + variableName + - " must be of integer type : short, int or associated type (long int, unsigned long int, etc.)" + hint + "\n" ); - } - }; - - //BODY of function starts here - if( m_DebugMode == true ) - { - if( csv.empty() ) - throw std::invalid_argument( "ERROR: csv dimensions string is empty " + hint + "\n"); - } - - auto pos = csv.find(","); - - if( pos == csv.npos ) //one dimensional csv is a variable - { - lf_SetVariableFlag( csv, hint, m_DebugMode ); - } - else - { - std::istringstream csvSS( csv ); - std::string dimensionVariable; - while( std::getline( csvSS, dimensionVariable, ',' ) ) //need to test - { - lf_SetVariableFlag( dimensionVariable, " from call to DeclareVariable ", m_DebugMode ); - } - } -} - - - -} //end namespace diff --git a/src/core/Method.cpp b/src/core/Method.cpp index 2b304cc63796f053fe6541b0dda8d2b20ef0ca68..de56042a0bd39581de5bc22a0c0544380f1a0091 100644 --- a/src/core/Method.cpp +++ b/src/core/Method.cpp @@ -20,13 +20,6 @@ Method::Method( const std::string type, const bool debugMode ): { } -Method::Method( const std::string type, Group& group, const bool debugMode ): - m_Type{ type }, - m_DebugMode{ debugMode }, - m_Group{ &group } -{ } - - Method::~Method( ) { } @@ -53,13 +46,6 @@ void Method::AddTransportParameters( const std::string type, const std::vector<s } -void Method::SetDefaultGroup( Group& group ) -{ - m_Group = &group; -} - - - } //end namespace diff --git a/src/engine/dataman/DataMan.cpp b/src/engine/dataman/DataMan.cpp index 844d9039e2bc2c55181ca2c6f3d84db2faf228b4..96212d60a7bc64866d1e861db7486ef03b8f99dc 100644 --- a/src/engine/dataman/DataMan.cpp +++ b/src/engine/dataman/DataMan.cpp @@ -9,7 +9,6 @@ #include "engine/dataman/DataMan.h" -#include "engine/dataman/DataManTemplates.h" #include "core/Support.h" #include "functions/adiosFunctions.h" //CSVToVector @@ -25,14 +24,10 @@ namespace adios { -namespace engine -{ -DataMan::DataMan( const std::string streamName, const std::string accessMode, const MPI_Comm mpiComm, - const Method& method, const bool debugMode, const unsigned int cores, - const std::string hostLanguage ): - Engine( "DataMan", streamName, accessMode, mpiComm, method, debugMode, cores, - " DataMan constructor (or call to ADIOS Open).\n", hostLanguage ), +DataMan::DataMan( ADIOS& adios, const std::string name, const std::string accessMode, MPI_Comm mpiComm, + const Method& method, const bool debugMode, const unsigned int cores ): + Engine( adios, "DataMan", name, accessMode, mpiComm, method, debugMode, cores, " Dataman constructor (or call to ADIOS Open).\n" ), m_Buffer( accessMode, m_RankMPI, m_DebugMode ) { Init( ); @@ -50,198 +45,88 @@ void DataMan::Init( ) } -void DataMan::Write( Group& group, const std::string variableName, const char* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write char*" ); - Variable<char>& variable = group.m_Char[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} +void DataMan::Write( Variable<char>& variable, const char* values ) +{ WriteVariable( variable, values ); } +void DataMan::Write( Variable<unsigned char>& variable, const unsigned char* values ) +{ WriteVariable( variable, values ); } -void DataMan::Write( Group& group, const std::string variableName, const unsigned char* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned char*" ); - Variable<unsigned char>& variable = group.m_UChar[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} +void DataMan::Write( Variable<short>& variable, const short* values ) +{ WriteVariable( variable, values ); } +void DataMan::Write( Variable<unsigned short>& variable, const unsigned short* values ) +{ WriteVariable( variable, values ); } -void DataMan::Write( Group& group, const std::string variableName, const short* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write short*" ); - Variable<short>& variable = group.m_Short[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} +void DataMan::Write( Variable<int>& variable, const int* values ) +{ WriteVariable( variable, values ); } +void DataMan::Write( Variable<unsigned int>& variable, const unsigned int* values ) +{ WriteVariable( variable, values ); } -void DataMan::Write( Group& group, const std::string variableName, const unsigned short* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned short*" ); - Variable<unsigned short>& variable = group.m_UShort[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} +void DataMan::Write( Variable<long int>& variable, const long int* values ) +{ WriteVariable( variable, values ); } +void DataMan::Write( Variable<unsigned long int>& variable, const unsigned long int* values ) +{ WriteVariable( variable, values ); } -void DataMan::Write( Group& group, const std::string variableName, const int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write int*" ); - Variable<int>& variable = group.m_Int[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} - - -void DataMan::Write( Group& group, const std::string variableName, const unsigned int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned int*" ); - Variable<unsigned int>& variable = group.m_UInt[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} +void DataMan::Write( Variable<long long int>& variable, const long long int* values ) +{ WriteVariable( variable, values ); } +void DataMan::Write( Variable<unsigned long long int>& variable, const unsigned long long int* values ) +{ WriteVariable( variable, values ); } -void DataMan::Write( Group& group, const std::string variableName, const long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write long int*" ); - Variable<long int>& variable = group.m_LInt[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} - - -void DataMan::Write( Group& group, const std::string variableName, const unsigned long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned long int*" ); - Variable<unsigned long int>& variable = group.m_ULInt[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} - - -void DataMan::Write( Group& group, const std::string variableName, const long long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write long long int*" ); - Variable<long long int>& variable = group.m_LLInt[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} - - -void DataMan::Write( Group& group, const std::string variableName, const unsigned long long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned long long int*" ); - Variable<unsigned long long int>& variable = group.m_ULLInt[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} - - -void DataMan::Write( Group& group, const std::string variableName, const float* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write float*" ); - Variable<float>& variable = group.m_Float[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} - -void DataMan::Write( Group& group, const std::string variableName, const double* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write double*" ); - Variable<double>& variable = group.m_Double[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} +void DataMan::Write( Variable<float>& variable, const float* values ) +{ WriteVariable( variable, values ); } +void DataMan::Write( Variable<double>& variable, const double* values ) +{ WriteVariable( variable, values ); } -void DataMan::Write( Group& group, const std::string variableName, const long double* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write long double*" ); - Variable<long double>& variable = group.m_LDouble[index]; //must be a reference - variable.Values = values; - DataManWriteVariable( group, variableName, variable, m_Buffer, m_Transports, m_BP1Writer ); -} +void DataMan::Write( Variable<long double>& variable, const long double* values ) +{ WriteVariable( variable, values ); } -//USING Preset Group void DataMan::Write( const std::string variableName, const char* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<char>( variableName ), values ); } void DataMan::Write( const std::string variableName, const unsigned char* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<unsigned char>( variableName ), values ); } void DataMan::Write( const std::string variableName, const short* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<short>( variableName ), values ); } void DataMan::Write( const std::string variableName, const unsigned short* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<unsigned short>( variableName ), values ); } void DataMan::Write( const std::string variableName, const int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<int>( variableName ), values ); } void DataMan::Write( const std::string variableName, const unsigned int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<unsigned int>( variableName ), values ); } void DataMan::Write( const std::string variableName, const long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<long int>( variableName ), values ); } void DataMan::Write( const std::string variableName, const unsigned long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<unsigned long int>( variableName ), values ); } void DataMan::Write( const std::string variableName, const long long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<long long int>( variableName ), values ); } void DataMan::Write( const std::string variableName, const unsigned long long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<unsigned long long int>( variableName ), values ); } void DataMan::Write( const std::string variableName, const float* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<float>( variableName ), values ); } void DataMan::Write( const std::string variableName, const double* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<double>( variableName ), values ); } void DataMan::Write( const std::string variableName, const long double* values ) +{ WriteVariable( m_ADIOS.GetVariable<long double>( variableName ), values ); } + + +void DataMan::InitCapsules( ) { - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); + //here init memory capsules } @@ -249,7 +134,6 @@ void DataMan::InitTransports( ) //maybe move this? { TransportNamesUniqueness( ); - for( const auto& parameters : m_Method.m_TransportParameters ) { auto itTransport = parameters.find( "transport" ); @@ -327,8 +211,6 @@ std::string DataMan::GetMdtmParameter( const std::string parameter, const std::m } - -} //end namespace engine } //end namespace adios diff --git a/src/engine/writer/Writer.cpp b/src/engine/writer/Writer.cpp index f96d2b9c13287418f595243e83023cc0ffe5f5aa..01a739c645afabebc0799f30639d027e2e5d470a 100644 --- a/src/engine/writer/Writer.cpp +++ b/src/engine/writer/Writer.cpp @@ -5,10 +5,7 @@ * Author: wfg */ -#include <iostream> - #include "engine/writer/Writer.h" -#include "core/Support.h" #include "functions/adiosFunctions.h" //GetTotalSize //supported capsules @@ -19,15 +16,15 @@ #include "transport/FStream.h" #include "transport/File.h" +#include "ADIOS.h" namespace adios { -Writer::Writer( const std::string streamName, const std::string accessMode, const MPI_Comm mpiComm, - const Method& method, const bool debugMode, const unsigned int cores, const std::string hostLanguage ): - Engine( "Writer", streamName, accessMode, mpiComm, method, debugMode, - cores, " Writer constructor (or call to ADIOS Open).\n", hostLanguage ), +Writer::Writer( ADIOS& adios, const std::string name, const std::string accessMode, const MPI_Comm mpiComm, + const Method& method, const bool debugMode, const unsigned int cores ): + Engine( adios, "Writer", name, accessMode, mpiComm, method, debugMode, cores, " Writer constructor (or call to ADIOS Open).\n" ), m_Buffer{ Heap( accessMode, m_RankMPI, m_DebugMode ) }, m_MaxBufferSize{ m_Buffer.m_Data.max_size() } { @@ -60,202 +57,86 @@ void Writer::Init( ) } -void Writer::Write( Group& group, const std::string variableName, const char* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write char*" ); - Variable<char>& variable = group.m_Char[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<char>& variable, const char* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const unsigned char* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned char*" ); - Variable<unsigned char>& variable = group.m_UChar[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<unsigned char>& variable, const unsigned char* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const short* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write short*" ); - Variable<short>& variable = group.m_Short[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<short>& variable, const short* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const unsigned short* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned short*" ); - Variable<unsigned short>& variable = group.m_UShort[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<unsigned short>& variable, const unsigned short* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write int*" ); - Variable<int>& variable = group.m_Int[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<int>& variable, const int* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const unsigned int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned int*" ); - Variable<unsigned int>& variable = group.m_UInt[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<unsigned int>& variable, const unsigned int* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write long int*" ); - Variable<long int>& variable = group.m_LInt[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<long int>& variable, const long int* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const unsigned long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned long int*" ); - Variable<unsigned long int>& variable = group.m_ULInt[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<unsigned long int>& variable, const unsigned long int* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const long long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write long long int*" ); - Variable<long long int>& variable = group.m_LLInt[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<long long int>& variable, const long long int* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const unsigned long long int* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write unsigned long long int*" ); - Variable<unsigned long long int>& variable = group.m_ULLInt[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<unsigned long long int>& variable, const unsigned long long int* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const float* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write float*" ); - Variable<float>& variable = group.m_Float[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} +void Writer::Write( Variable<float>& variable, const float* values ) +{ WriteVariable( variable, values ); } +void Writer::Write( Variable<double>& variable, const double* values ) +{ WriteVariable( variable, values ); } -void Writer::Write( Group& group, const std::string variableName, const double* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write double*" ); - Variable<double>& variable = group.m_Double[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} - - -void Writer::Write( Group& group, const std::string variableName, const long double* values ) -{ - auto index = PreSetVariable( group, variableName, " from call to Write long double*" ); - Variable<long double>& variable = group.m_LDouble[index]; //must be a reference - variable.Values = values; - WriteVariable( group, variableName, variable ); -} - +void Writer::Write( Variable<long double>& variable, const long double* values ) +{ WriteVariable( variable, values ); } +//String version void Writer::Write( const std::string variableName, const char* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<char>( variableName ), values ); } void Writer::Write( const std::string variableName, const unsigned char* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<unsigned char>( variableName ), values ); } void Writer::Write( const std::string variableName, const short* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<short>( variableName ), values ); } void Writer::Write( const std::string variableName, const unsigned short* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<unsigned short>( variableName ), values ); } void Writer::Write( const std::string variableName, const int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<int>( variableName ), values ); } void Writer::Write( const std::string variableName, const unsigned int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<unsigned int>( variableName ), values ); } void Writer::Write( const std::string variableName, const long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<long int>( variableName ), values ); } void Writer::Write( const std::string variableName, const unsigned long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<unsigned long int>( variableName ), values ); } void Writer::Write( const std::string variableName, const long long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<long long int>( variableName ), values ); } void Writer::Write( const std::string variableName, const unsigned long long int* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<unsigned long long int>( variableName ), values ); } void Writer::Write( const std::string variableName, const float* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<float>( variableName ), values ); } void Writer::Write( const std::string variableName, const double* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} - +{ WriteVariable( m_ADIOS.GetVariable<double>( variableName ), values ); } void Writer::Write( const std::string variableName, const long double* values ) -{ - CheckDefaultGroup( ); - Write( *m_Group, variableName, values ); -} +{ WriteVariable( m_ADIOS.GetVariable<long double>( variableName ), values ); } + + void Writer::Close( const int transportIndex ) @@ -336,7 +217,7 @@ void Writer::InitTransports( ) -bool Writer::CheckBuffersAllocation( const Group& group, const Var variableName, const std::size_t indexSize, +bool Writer::CheckBuffersAllocation( const std::string variableName, const std::size_t indexSize, const std::size_t payloadSize ) { //Check if data in buffer needs to be reallocated diff --git a/src/format/BP1.cpp b/src/format/BP1.cpp index 2ea0e054b3a1f69349467f93efadca90ff6fc2f7..1df1cbad649bffc3e1a168b0adb6590c797e0bfb 100644 --- a/src/format/BP1.cpp +++ b/src/format/BP1.cpp @@ -24,15 +24,14 @@ void BP1::OpenRankFiles( const std::string name, const std::string accessMode, T if( name.find(".bp") == name.size()-3 ) //need to test { baseName = name.substr( 0, name.size()-3 ); - directory = name + ".dir"; - CreateDirectory( name +".dir" ); + directory = name; } else { baseName = name; - directory = name + ".bp.dir"; - CreateDirectory( name +".bp.dir" ); + directory = name + ".bp"; } + CreateDirectory( directory ); std::string fileName( directory + "/" + baseName + ".bp." + std::to_string( file.m_MPIRank ) ); diff --git a/src/format/BP1Writer.cpp b/src/format/BP1Writer.cpp index eca2a094d375291c8384f324f9f0b0ad7e43146f..0f8697b9586a6a896d150d75c5133d0ac5da609e 100644 --- a/src/format/BP1Writer.cpp +++ b/src/format/BP1Writer.cpp @@ -92,9 +92,9 @@ void BP1Writer::WriteNameRecord( const std::string name, const std::uint16_t len void BP1Writer::WriteDimensionRecord( std::vector<char*>& buffers, std::vector<std::size_t>& positions, - const std::vector<unsigned long long int>& localDimensions, - const std::vector<unsigned long long int>& globalDimensions, - const std::vector<unsigned long long int>& globalOffsets, + const std::vector<std::size_t>& localDimensions, + const std::vector<std::size_t>& globalDimensions, + const std::vector<std::size_t>& globalOffsets, const bool addType ) { if( addType == true ) @@ -122,7 +122,7 @@ void BP1Writer::WriteDimensionRecord( std::vector<char*>& buffers, std::vector<s } void BP1Writer::WriteDimensionRecord( std::vector<char*>& buffers, std::vector<std::size_t>& positions, - const std::vector<unsigned long long int>& localDimensions, + const std::vector<std::size_t>& localDimensions, const unsigned int skip, const bool addType ) { diff --git a/src/functions/adiosFunctions.cpp b/src/functions/adiosFunctions.cpp index 8f468a92c58042c57cf6478bf09e3eaf06cee747..e0ec7ce420ff8a132bce14f589cb7336eb0d630a 100644 --- a/src/functions/adiosFunctions.cpp +++ b/src/functions/adiosFunctions.cpp @@ -189,181 +189,181 @@ void GetPairsFromTag( const std::string& fileContent, const std::string tag, } -void SetMembers( const std::string& fileContent, const MPI_Comm mpiComm, const bool debugMode, - std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, - std::map< std::string, Group >& groups ) +//void SetMembers( const std::string& fileContent, const MPI_Comm mpiComm, const bool debugMode, +// std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, +// std::map< std::string, Group >& groups ) +//{ +// //adios-config +// std::string currentContent; +// std::string::size_type currentPosition( 0 ); +// GetSubString( "<adios-config ", "</adios-config>", fileContent, currentContent, currentPosition ); +// +// //remove comment sections +// std::string::size_type startComment ( currentContent.find( "<!--" ) ); +// +// while( startComment != currentContent.npos ) +// { +// std::string::size_type endComment( currentContent.find( "-->") ); +// currentContent.erase( startComment, endComment-startComment+3 ); +// startComment = currentContent.find( "<!--" ); +// } +// +// //Tag <adios-config +// currentPosition = 0; +// +// std::string tag; //use for < > tags +// GetSubString( "<adios-config", ">", currentContent, tag, currentPosition ); +// tag = tag.substr( 1, tag.size() - 2 ); //eliminate < > +// +// std::vector< std::pair<const std::string, const std::string> > pairs; // pairs in tag +// GetPairsFromTag( currentContent, tag, pairs ); +// +// for( auto& pair : pairs ) +// if( pair.first == "host-language" ) +// hostLanguage = pair.second; +// +// if( debugMode == true ) +// { +// if( Support::HostLanguages.count( hostLanguage ) == 0 ) +// throw std::invalid_argument("ERROR: host language " + hostLanguage + " not supported.\n" ); +// +// if( hostLanguage.empty() == true ) +// throw std::invalid_argument("ERROR: host language is empty.\n" ); +// } +// +// //adios-group +// currentPosition = 0; +// +// while( currentPosition != std::string::npos ) +// { +// std::string xmlGroup; +// GetSubString("<adios-group ", "</adios-group>", currentContent, xmlGroup, currentPosition ); //Get all group contents +// +// if( xmlGroup.empty() ) //no more groups to find +// break; +// +// //get group name +// std::string::size_type groupPosition( 0 ); +// GetSubString( "<adios-group ", ">", xmlGroup, tag, groupPosition ); +// if( debugMode == true ) +// { +// if( tag.size() < 2 ) +// throw std::invalid_argument( "ERROR: wrong tag " + tag + " in adios-group\n" ); //check < or <= +// } +// +// tag = tag.substr( 1, tag.size() - 2 ); //eliminate < > +// GetPairsFromTag( xmlGroup, tag, pairs ); +// std::string groupName; +// +// for( auto& pair : pairs ) +// { +// if( pair.first == "name") +// groupName = pair.second; +// } +// +// if( debugMode == true ) +// { +// if( groupName.empty() ) +// throw std::invalid_argument( "ERROR: group name not found. \n" ); +// +// if( groups.count( groupName ) == 1 ) //group exists +// throw std::invalid_argument( "ERROR: group " + groupName + " defined twice.\n" ); +// } +// +// groups.emplace( groupName, Group( groupName, xmlGroup, transforms, debugMode ) ); +// +// currentContent.erase( currentContent.find( xmlGroup ), xmlGroup.size() ); +// currentPosition = 0; +// } +// +// //transport +// //lambda function to check priority and iteration casting to unsigned int +// auto lf_UIntCheck = []( const std::string method, const std::string fieldStr, const std::string fieldName, +// const bool debugMode, int& field ) +// { +// field = 0; +// if( fieldStr.empty() == false ) +// { +// field = std::stoi( fieldStr ); //throws invalid_argument +// +// if( debugMode == true ) +// { +// if( field < 0 ) +// throw std::invalid_argument("ERROR: " + fieldName + " in transport " + method + " can't be negative\n" ); +// } +// } +// }; +// +// //this section will have to change, doing nothing for now +// currentPosition = 0; +// while( currentPosition != std::string::npos ) +// { +// GetSubString( "<transport ", ">", currentContent, tag, currentPosition ); +// if( tag.empty() ) break; +// tag = tag.substr( 1, tag.size() - 2 ); //eliminate < > +// pairs.clear(); +// GetPairsFromTag( currentContent, tag, pairs ); +// +// std::string groupName, method, priorityStr, iterationStr; +// for( auto& pair : pairs ) +// { +// if( pair.first == "group" ) groupName = pair.second; +// else if( pair.first == "method" ) method = pair.second; +// else if( pair.first == "priority" ) priorityStr = pair.second; +// else if( pair.first == "iteration" ) iterationStr = pair.second; +// } +// +// auto itGroup = groups.find( groupName ); +// if( debugMode == true ) +// { +// if( itGroup == groups.end() ) //not found +// throw std::invalid_argument( "ERROR: in transport " + method + " group " + groupName + " not found.\n" ); +// } +// +// int priority, iteration; +// lf_UIntCheck( method, priorityStr, "priority", debugMode, priority ); +// lf_UIntCheck( method, iterationStr, "iteration", debugMode, iteration ); +// //here do something with the capsule +// } +//} + + +//void InitXML( const std::string xmlConfigFile, const MPI_Comm mpiComm, const bool debugMode, +// std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, +// std::map< std::string, Group >& groups ) +//{ +// int xmlFileContentSize; +// std::string xmlFileContent; +// +// int rank; +// MPI_Comm_rank( mpiComm, &rank ); +// +// if( rank == 0 ) //serial part +// { +// DumpFileToString( xmlConfigFile, xmlFileContent ); //in ADIOSFunctions.h dumps all XML Config File to xmlFileContent +// xmlFileContentSize = xmlFileContent.size( ) + 1; // add one for the null character +// +// MPI_Bcast( &xmlFileContentSize, 1, MPI_INT, 0, mpiComm ); //broadcast size for allocation +// MPI_Bcast( (char*)xmlFileContent.c_str(), xmlFileContentSize, MPI_CHAR, 0, mpiComm ); //broadcast contents +// } +// else +// { +// MPI_Bcast( &xmlFileContentSize, 1, MPI_INT, 0, mpiComm ); //receive size +// +// char* xmlFileContentMPI = new char[ xmlFileContentSize ]; //allocate xml C-char +// MPI_Bcast( xmlFileContentMPI, xmlFileContentSize, MPI_CHAR, 0, mpiComm ); //receive xml C-char +// xmlFileContent.assign( xmlFileContentMPI ); //copy to a string +// +// delete []( xmlFileContentMPI ); //delete char* needed for MPI, might add size is moving to C++14 for optimization, avoid memory leak +// } +// +// SetMembers( xmlFileContent, mpiComm, debugMode, hostLanguage, transforms, groups ); +//} + + +std::size_t GetTotalSize( const std::vector<std::size_t>& dimensions ) { - //adios-config - std::string currentContent; - std::string::size_type currentPosition( 0 ); - GetSubString( "<adios-config ", "</adios-config>", fileContent, currentContent, currentPosition ); - - //remove comment sections - std::string::size_type startComment ( currentContent.find( "<!--" ) ); - - while( startComment != currentContent.npos ) - { - std::string::size_type endComment( currentContent.find( "-->") ); - currentContent.erase( startComment, endComment-startComment+3 ); - startComment = currentContent.find( "<!--" ); - } - - //Tag <adios-config - currentPosition = 0; - - std::string tag; //use for < > tags - GetSubString( "<adios-config", ">", currentContent, tag, currentPosition ); - tag = tag.substr( 1, tag.size() - 2 ); //eliminate < > - - std::vector< std::pair<const std::string, const std::string> > pairs; // pairs in tag - GetPairsFromTag( currentContent, tag, pairs ); - - for( auto& pair : pairs ) - if( pair.first == "host-language" ) - hostLanguage = pair.second; - - if( debugMode == true ) - { - if( Support::HostLanguages.count( hostLanguage ) == 0 ) - throw std::invalid_argument("ERROR: host language " + hostLanguage + " not supported.\n" ); - - if( hostLanguage.empty() == true ) - throw std::invalid_argument("ERROR: host language is empty.\n" ); - } - - //adios-group - currentPosition = 0; - - while( currentPosition != std::string::npos ) - { - std::string xmlGroup; - GetSubString("<adios-group ", "</adios-group>", currentContent, xmlGroup, currentPosition ); //Get all group contents - - if( xmlGroup.empty() ) //no more groups to find - break; - - //get group name - std::string::size_type groupPosition( 0 ); - GetSubString( "<adios-group ", ">", xmlGroup, tag, groupPosition ); - if( debugMode == true ) - { - if( tag.size() < 2 ) - throw std::invalid_argument( "ERROR: wrong tag " + tag + " in adios-group\n" ); //check < or <= - } - - tag = tag.substr( 1, tag.size() - 2 ); //eliminate < > - GetPairsFromTag( xmlGroup, tag, pairs ); - std::string groupName; - - for( auto& pair : pairs ) - { - if( pair.first == "name") - groupName = pair.second; - } - - if( debugMode == true ) - { - if( groupName.empty() ) - throw std::invalid_argument( "ERROR: group name not found. \n" ); - - if( groups.count( groupName ) == 1 ) //group exists - throw std::invalid_argument( "ERROR: group " + groupName + " defined twice.\n" ); - } - - groups.emplace( groupName, Group( groupName, xmlGroup, transforms, debugMode ) ); - - currentContent.erase( currentContent.find( xmlGroup ), xmlGroup.size() ); - currentPosition = 0; - } - - //transport - //lambda function to check priority and iteration casting to unsigned int - auto lf_UIntCheck = []( const std::string method, const std::string fieldStr, const std::string fieldName, - const bool debugMode, int& field ) - { - field = 0; - if( fieldStr.empty() == false ) - { - field = std::stoi( fieldStr ); //throws invalid_argument - - if( debugMode == true ) - { - if( field < 0 ) - throw std::invalid_argument("ERROR: " + fieldName + " in transport " + method + " can't be negative\n" ); - } - } - }; - - //this section will have to change, doing nothing for now - currentPosition = 0; - while( currentPosition != std::string::npos ) - { - GetSubString( "<transport ", ">", currentContent, tag, currentPosition ); - if( tag.empty() ) break; - tag = tag.substr( 1, tag.size() - 2 ); //eliminate < > - pairs.clear(); - GetPairsFromTag( currentContent, tag, pairs ); - - std::string groupName, method, priorityStr, iterationStr; - for( auto& pair : pairs ) - { - if( pair.first == "group" ) groupName = pair.second; - else if( pair.first == "method" ) method = pair.second; - else if( pair.first == "priority" ) priorityStr = pair.second; - else if( pair.first == "iteration" ) iterationStr = pair.second; - } - - auto itGroup = groups.find( groupName ); - if( debugMode == true ) - { - if( itGroup == groups.end() ) //not found - throw std::invalid_argument( "ERROR: in transport " + method + " group " + groupName + " not found.\n" ); - } - - int priority, iteration; - lf_UIntCheck( method, priorityStr, "priority", debugMode, priority ); - lf_UIntCheck( method, iterationStr, "iteration", debugMode, iteration ); - //here do something with the capsule - } -} - - -void InitXML( const std::string xmlConfigFile, const MPI_Comm mpiComm, const bool debugMode, - std::string& hostLanguage, std::vector< std::shared_ptr<Transform> >& transforms, - std::map< std::string, Group >& groups ) -{ - int xmlFileContentSize; - std::string xmlFileContent; - - int rank; - MPI_Comm_rank( mpiComm, &rank ); - - if( rank == 0 ) //serial part - { - DumpFileToString( xmlConfigFile, xmlFileContent ); //in ADIOSFunctions.h dumps all XML Config File to xmlFileContent - xmlFileContentSize = xmlFileContent.size( ) + 1; // add one for the null character - - MPI_Bcast( &xmlFileContentSize, 1, MPI_INT, 0, mpiComm ); //broadcast size for allocation - MPI_Bcast( (char*)xmlFileContent.c_str(), xmlFileContentSize, MPI_CHAR, 0, mpiComm ); //broadcast contents - } - else - { - MPI_Bcast( &xmlFileContentSize, 1, MPI_INT, 0, mpiComm ); //receive size - - char* xmlFileContentMPI = new char[ xmlFileContentSize ]; //allocate xml C-char - MPI_Bcast( xmlFileContentMPI, xmlFileContentSize, MPI_CHAR, 0, mpiComm ); //receive xml C-char - xmlFileContent.assign( xmlFileContentMPI ); //copy to a string - - delete []( xmlFileContentMPI ); //delete char* needed for MPI, might add size is moving to C++14 for optimization, avoid memory leak - } - - SetMembers( xmlFileContent, mpiComm, debugMode, hostLanguage, transforms, groups ); -} - - -unsigned long long int GetTotalSize( const std::vector<unsigned long long int>& dimensions ) -{ - unsigned long long int product = 1; + std::size_t product = 1; for( const auto dimension : dimensions ) product *= dimension;