From 449b86ce7f270e6ee92c08f07374129d34e4f9f7 Mon Sep 17 00:00:00 2001 From: wfg <wfg@pc0098504.ornl.gov> Date: Mon, 9 Jan 2017 17:33:05 -0500 Subject: [PATCH] Testing non-XML hello SingleBP Engine This version compiles. Tested with 2 write APIs: under examples/hello/singleBP helloSingleBP.cpp -> using ADIOS single manager class from ADIOS.h helloSingleBP.cpp -> using ADIOS objects from ADIOS_OO.h both generate a .bp file using a POSIX transport To do: Test compilation in other platforms/compilers Add coverage test cases Add the NULL transport (does nothing) Work on SingleBP engine to generate bp format XML config file support (to be defined) --- Makefile | 2 +- Makefile.libs | 4 +- examples/dataman/datamanNoXML.cpp | 96 -------- examples/hello/Makefile | 2 +- examples/hello/helloADIOS.cpp | 49 ---- examples/hello/helloADIOS_C.c | 36 --- examples/hello/helloADIOS_nompi.cpp | 30 --- examples/hello/helloFStream.cpp | 79 ------- examples/hello/helloFStreamNoXML.cpp | 95 -------- examples/hello/singleBP/Makefile | 35 +++ examples/hello/singleBP/helloSingleBP.cpp | 89 ++++++++ examples/hello/singleBP/helloSingleBP_OOP.cpp | 86 +++++++ include/ADIOS.h | 10 +- include/ADIOS_OOP.h | 20 ++ include/capsule/Heap.h | 13 +- include/capsule/ShmSystemV.h | 11 +- include/core/Capsule.h | 8 +- include/core/Engine.h | 79 ++++--- include/core/Group.h | 23 +- include/core/Method.h | 12 +- include/core/Transform.h | 4 +- include/core/Transport.h | 4 +- include/core/Variable.h | 12 +- include/engine/SingleBP.h | 19 +- include/functions/capsuleTemplates.h | 138 +++++------ include/transform/{BZIP2.h => BZip2.h} | 7 +- include/transport/MPIFile.h | 2 +- src/ADIOS.cpp | 55 +++-- src/capsule/Heap.cpp | 8 +- src/capsule/ShmSystemV.cpp | 55 +++-- src/core/Engine.cpp | 138 +++-------- src/core/Group.cpp | 45 ++-- src/engine/SingleBP.cpp | 214 +++++++++++++++--- src/functions/adiosFunctions.cpp | 2 +- src/transform/{BZIP2.cpp => BZip2.cpp} | 8 +- src/transport/FStream.cpp | 4 +- src/transport/File.cpp | 2 + src/transport/POSIX.cpp | 25 +- 38 files changed, 774 insertions(+), 747 deletions(-) delete mode 100644 examples/dataman/datamanNoXML.cpp delete mode 100644 examples/hello/helloADIOS.cpp delete mode 100644 examples/hello/helloADIOS_C.c delete mode 100644 examples/hello/helloADIOS_nompi.cpp delete mode 100644 examples/hello/helloFStream.cpp delete mode 100644 examples/hello/helloFStreamNoXML.cpp create mode 100644 examples/hello/singleBP/Makefile create mode 100644 examples/hello/singleBP/helloSingleBP.cpp create mode 100644 examples/hello/singleBP/helloSingleBP_OOP.cpp create mode 100644 include/ADIOS_OOP.h rename include/transform/{BZIP2.h => BZip2.h} (86%) rename src/transform/{BZIP2.cpp => BZip2.cpp} (75%) diff --git a/Makefile b/Makefile index 43b8bf1e3..74d6e6e0b 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ ARFLAGS:=rcs 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/transform ./src/transport +VPATH = ./src ./src/core ./src/functions ./src/engine ./src/capsule ./src/transform ./src/transport #SEPARATE EXTERNAL LIBRARIES HANDLING in Makefile.libs export $(HFiles) $(CPPFiles) $(CFLAGS) $(LIBS) diff --git a/Makefile.libs b/Makefile.libs index 5e075454b..22bfe3668 100644 --- a/Makefile.libs +++ b/Makefile.libs @@ -1,6 +1,6 @@ #Language API -LANGUAGE_INC:=./include/public -LANGUAGE_SRC:=./src/public +LANGUAGE_INC:=./include +LANGUAGE_SRC:=./src ifeq ($(C_API),yes) else diff --git a/examples/dataman/datamanNoXML.cpp b/examples/dataman/datamanNoXML.cpp deleted file mode 100644 index 8935049c1..000000000 --- a/examples/dataman/datamanNoXML.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * datamanNoXML.cpp: Example for DataMan Transport usage also using POSIX as additional transport - * Writes a single char array (myChars) and its size (myCharsSize) - * - * Created on: Nov 15, 2016 - * Author: wfg - */ - -#ifdef HAVE_MPI - #include <mpi.h> -#else - #include "mpidummy.h" - using adios::MPI_Init; - using adios::MPI_Comm_rank; -#endif - -#include "ADIOS.h" - - -int main( int argc, char* argv [] ) -{ - MPI_Init( &argc, &argv ); - int rank; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - - try //need to think carefully how to handle C++ exceptions with MPI to avoid deadlocking - { - //APP variables - const unsigned int myCharsSize = 10; - std::vector<char> myChars( myCharsSize, '1' ); // 10 chars each with value '1' - - //ADIOS init here, non-XML, debug mode is ON - adios::ADIOS adios( MPI_COMM_WORLD, true ); - - //Create group TCP and define variables - const std::string groupTCP( "TCP" ); - adios.DeclareGroup( groupTCP ); - adios.DefineVariable( groupTCP, "myCharsSize", "unsigned int" ); //scalar : group, name, type - adios.DefineVariable( groupTCP, "myChars", "char", "myCharsSize" ); //group, name, type, integer variables defining dimensions - - //Define method or engine - - //Open stream using two transports, DataMan is default, POSIX is an additional one - const std::string streamTCP( "TCP.bp" ); - const unsigned int tcpHandle = adios.Open( streamTCP, "w", "SingleBP" ); //here open a stream called TCPStream for writing (w or write), name is the same as stream - adios.AddTransport( , "write", "POSIX", "name=TCP.bp" ); //add POSIX transport with .bp name - adios.SetMaxBufferSize( streamTCP, 1000000000 ); // Setting max Buffer size to 1Gb - - //Writing - adios.SetCurrentGroup( streamTCP, groupTCP ); //no need to add group field in Write - adios.Write( streamTCP, "myCharsSize", &myCharsSize ); - adios.Write( streamTCP, "myChars", &myChars[0] ); //getting the underlying char* - - //Close - adios.Close( streamTCP ); // Flush to all transports, DataMan and POSIX - } - catch( std::bad_alloc& e ) - { - if( rank == 0 ) - { - std::cout << "Bad allocation exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - } - 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/Makefile b/examples/hello/Makefile index 159aa3084..62588a062 100644 --- a/examples/hello/Makefile +++ b/examples/hello/Makefile @@ -3,7 +3,7 @@ # Author: wfg -BASE_NAME=helloFStream +BASE_NAME=helloADIOSNoXML_OOP TOOL_DIR=/usr/bin diff --git a/examples/hello/helloADIOS.cpp b/examples/hello/helloADIOS.cpp deleted file mode 100644 index d17d59272..000000000 --- a/examples/hello/helloADIOS.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * helloMPI.cpp - * - * Created on: Oct 4, 2016 - * Author: wfg - */ - - - -#include <stdexcept> -#include <mpi.h> -#include <iostream> -#include <fstream> -#include <string> - -#include "../../include/ADIOS.h" - - -int main( int argc, char* argv [] ) -{ - MPI_Init( &argc, &argv ); - int rank; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - - adios::ADIOS adios; - - try - { - //testing with CPOSIXMPI - adios = adios::ADIOS( "writer.xml", MPI_COMM_WORLD, true ); //debug mode - - //Get Monitor info - std::ofstream logStream( "info_" + std::to_string(rank) + ".log" ); - adios.MonitorGroups( logStream ); - } - catch( std::exception& e ) //need to think carefully how to handle C++ exceptions with MPI to avoid deadlocking - { - if( rank == 0 ) - { - std::cout << e.what() << "\n"; - } - } - - MPI_Barrier( MPI_COMM_WORLD ); - MPI_Finalize( ); - - - return 0; -} diff --git a/examples/hello/helloADIOS_C.c b/examples/hello/helloADIOS_C.c deleted file mode 100644 index 28af80107..000000000 --- a/examples/hello/helloADIOS_C.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * helloADIOS_C.cpp - * - * Created on: Oct 31, 2016 - * Author: wfg - */ - -#ifdef HAVE_MPI - #include <mpi.h> -#else - #include "../../include/mpidummy.h" -#endif - -#include "../../include/ADIOS_C.h" - - - -int main( int argc, char* argv [] ) -{ - MPI_Init( &argc, &argv ); - int rank; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - - - - - - - - - - MPI_Finalize( ); - - - return 0; -} diff --git a/examples/hello/helloADIOS_nompi.cpp b/examples/hello/helloADIOS_nompi.cpp deleted file mode 100644 index 4109656f6..000000000 --- a/examples/hello/helloADIOS_nompi.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * helloADIOS_nompi.cpp - * - * Created on: Oct 4, 2016 - * Author: wfg - */ - - -#include <stdexcept> -#include <iostream> - -#include "../../include/ADIOS.h" - - -int main( int argc, char* argv [] ) -{ - try - { - adios::ADIOS adios( "writer2Groups.xml", true ); //testing with CPOSIXNoMPI - adios.MonitorGroups( std::cout ); - std::cout << "Finished initializing ADIOS\n"; - } - catch( std::exception& e ) - { - std::cout << e.what() << "\n"; - } - - return 0; -} - diff --git a/examples/hello/helloFStream.cpp b/examples/hello/helloFStream.cpp deleted file mode 100644 index 04d588b76..000000000 --- a/examples/hello/helloFStream.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * helloFStream.cpp - * - * Created on: Oct 24, 2016 - * Author: wfg - */ - - -#include <stdexcept> -#include <iostream> -#include <fstream> -#include <string> -#include <numeric> - -#ifdef HAVE_MPI - #include <mpi.h> -#else - #include "../../include/mpidummy.h" -#endif - -#include "../../include/ADIOS.h" - - -int main( int argc, char* argv [] ) -{ - MPI_Init( &argc, &argv ); - int rank; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - - try - { - unsigned int size = 10; - std::vector<int> numbers( size, 1 ); - - adios::ADIOS adios( "numbers.xml", MPI_COMM_WORLD, true ); //xml file, MPI Comm, debug mode - adios.Open( "numbers.bp", "write", "FStream" );// open a file stream transport for writing to file numbers.bp - adios.SetCurrentGroup( "numbers.bp", "Vector" );// Write will look for variables in the Vector group defined in numbers.xml - adios.Write( "numbers.bp", "size", &size ); //writes size - adios.Write( "numbers.bp", "numbers", &numbers[0] ); //writes vector numbers - adios.Close( "numbers.bp" ); //flush and closes numbers.bp now containing size and numbers - } - catch( std::bad_alloc& e ) - { - if( rank == 0 ) - { - std::cout << "Bad allocation exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - } - 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/helloFStreamNoXML.cpp b/examples/hello/helloFStreamNoXML.cpp deleted file mode 100644 index 70f1181fe..000000000 --- a/examples/hello/helloFStreamNoXML.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* -/* - * helloFStreamNoXML.cpp - * - * Created on: Dec 2, 2016 - * Author: wfg - */ - -#include <stdexcept> -#include <iostream> -#include <fstream> -#include <string> - -#ifdef HAVE_MPI - #include <mpi.h> -#else - #include "../../include/mpidummy.h" -#endif - -#include "../../include/ADIOS.h" - - -int main( int argc, char* argv [] ) -{ - MPI_Init( &argc, &argv ); - int rank; - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - - try - { - unsigned int size = 10; - std::vector<int> numbers( size, 1 ); - - adios::ADIOS adios( MPI_COMM_WORLD, true ); //MPI Comm, debug mode - - const std::string group( "Vector" ); - adios.DeclareGroup( group ); - adios.DefineVariable( group, "size", "unsigned int" ); - adios.DefineVariable( group, "numbers", "int", "size" ); - adios.DefineAttribute( group, "description", "string", "1 to 10" ); - - const std::string file( "numbers.bp" ); - adios.Open( file, "write", "FStream" );// open a file stream transport for writing to file numbers.bp - adios.SetCurrentGroup( file, group );// Write will look for variables in the Vector group defined in numbers.xml - adios.Write( file, "size", &size ); //writes size - adios.Write( file, "numbers", &numbers[0] ); //writes vector numbers - adios.Close( file ); //flush and closes numbers.bp now containing size and numbers - } - catch( std::bad_alloc& e ) - { - if( rank == 0 ) - { - std::cout << "Bad allocation exception, STOPPING PROGRAM\n"; - std::cout << e.what() << "\n"; - } - } - 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; -} - * helloFStreamNoXML.cpp - * - * Created on: Dec 2, 2016 - * Author: wfg - */ - - - - diff --git a/examples/hello/singleBP/Makefile b/examples/hello/singleBP/Makefile new file mode 100644 index 000000000..96edd8f1d --- /dev/null +++ b/examples/hello/singleBP/Makefile @@ -0,0 +1,35 @@ +# Makefile for testing purposes, will build libadios.a +# Created on: Oct 4, 2016 +# Author: wfg + + +BASE_NAME=helloSingleBP_OOP + +TOOL_DIR=/usr/bin + +CC=$(TOOL_DIR)/g++ # Compiling with mpicc for now +MPICC=$(TOOL_DIR)/mpic++ +AR=$(TOOL_DIR)/ar + +#ADIOS LOCATION +ADIOS_DIR=../../.. +ADIOS_LIB=$(ADIOS_DIR)/lib/libadios.a +ADIOS_NOMPI_LIB=$(ADIOS_DIR)/lib/libadios_nompi.a + +ADIOS_INCLUDE=-I$(ADIOS_DIR)/include + + +#FLAGS +CFLAGS=-Wall -O0 -g -Wpedantic -std=c++11 + +all: mpi + +mpi: $(ADIOS_LIB) $(ADIOS_HFiles) + $(MPICC) $(CFLAGS) $(ADIOS_INCLUDE) -DHAVE_MPI $(BASE_NAME).cpp -o $(BASE_NAME)_mpi $(ADIOS_LIB) + +nompi: $(ADIOS_NOMPI_LIB) $(NoMPI_HFiles) + $(CC) $(CFLAGS) $(ADIOS_INCLUDE) $(BASE_NAME).cpp -o $(BASE_NAME)_nompi $(ADIOS_NOMPI_LIB) + +clean: + rm *_mpi; rm *_nompi + diff --git a/examples/hello/singleBP/helloSingleBP.cpp b/examples/hello/singleBP/helloSingleBP.cpp new file mode 100644 index 000000000..35815996a --- /dev/null +++ b/examples/hello/singleBP/helloSingleBP.cpp @@ -0,0 +1,89 @@ +/* + * 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.h" + + +int main( int argc, char* argv [] ) +{ + MPI_Init( &argc, &argv ); + int rank; + MPI_Comm_rank( MPI_COMM_WORLD, &rank ); + const bool adiosDebug = true; + + //Application variable + std::vector<double> myInts = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int myIntsSize = 10; + + try + { + //Define group and variables + adios::ADIOS adios( MPI_COMM_WORLD, adiosDebug ); + const std::string groupName( "ints" ); + adios.DeclareGroup( groupName ); + adios.DefineVariable( groupName, "myIntsSize", "int" ); + adios.DefineVariable( groupName, "myInts", "double", "myIntsSize" ); + + //Define method + const std::string methodName( "singleBP" ); + adios.DeclareMethod( methodName, "singleBP" ); + adios.AddCapsule( methodName, "buffer=Heap" ); + adios.AddTransport( methodName, "transport=POSIX" ); + + //Create engine handler and Write + int handler = adios.Open( "myInts.bp", "w", methodName ); + adios.SetDefaultGroup( handler, groupName ); + adios.Write( handler, "myIntsSize", &myIntsSize ); + adios.Write( handler, "myInts", &myInts.front() ); + adios.Close( handler ); + } + 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/singleBP/helloSingleBP_OOP.cpp b/examples/hello/singleBP/helloSingleBP_OOP.cpp new file mode 100644 index 000000000..1e4c5ffdc --- /dev/null +++ b/examples/hello/singleBP/helloSingleBP_OOP.cpp @@ -0,0 +1,86 @@ +/* + * 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; + + //Application variable + std::vector<double> myInts = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + int myIntsSize = 10; + + try + { + //Define group and variables + adios::Group groupInts( adiosDebug ); + groupInts.DefineVariable( "myIntsSize", "int" ); //define size as scalar + groupInts.DefineVariable( "myInts", "double", "myIntsSize" ); //define variable with associate size + + //Define method + adios::Method single; + single.AddCapsule( "buffer=Heap" ); + single.AddTransport( "transport=POSIX" ); + + //Create engine and Write + adios::engine::SingleBP engine( "myInts.bp", "w", MPI_COMM_WORLD, single, adiosDebug ); + engine.SetDefaultGroup( groupInts ); + engine.Write( "myIntsSize", &myIntsSize ); + engine.Write( "myInts", &myInts.front() ); + engine.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/include/ADIOS.h b/include/ADIOS.h index b60c71b52..04c92fda0 100644 --- a/include/ADIOS.h +++ b/include/ADIOS.h @@ -24,9 +24,9 @@ #include "mpidummy.h" #endif +#include "core/Engine.h" #include "core/Group.h" #include "core/Method.h" -#include "core/Engine.h" #include "core/Support.h" @@ -129,7 +129,7 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO * @param name * @param type */ - void DeclareMethod( const std::string methodName, const std::string type ); + void DeclareMethod( const std::string methodName, const std::string type = "SingleBP" ); /** * Add a capsule type to method name defined from DeclareMethod @@ -143,7 +143,7 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO if( m_DebugMode == true ) CheckMethod( itMethod, methodName, " from call to AddBuffer\n" ); - itMethod->second.AddCapsule( args ); + itMethod->second.AddCapsule( args... ); } /** @@ -158,7 +158,7 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO if( m_DebugMode == true ) CheckMethod( itMethod, methodName, " from call to AddTransport\n" ); - itMethod->second.AddTransport( args ); + itMethod->second.AddTransport( args... ); } /** @@ -198,7 +198,7 @@ public: // PUBLIC Constructors and Functions define the User Interface with ADIO * @param streamName unique name * @param groupName default group from which variables will be used */ - void SetGroup( const unsigned int handler, const std::string groupName ); + void SetDefaultGroup( const unsigned int handler, const std::string groupName ); template<class T> diff --git a/include/ADIOS_OOP.h b/include/ADIOS_OOP.h new file mode 100644 index 000000000..988e327de --- /dev/null +++ b/include/ADIOS_OOP.h @@ -0,0 +1,20 @@ +/* + * ADIOS_OOP.h + * + * Created on: Jan 9, 2017 + * Author: wfg + */ + +#ifndef ADIOS_OOP_H_ +#define ADIOS_OOP_H_ + + +#include "core/Group.h" +#include "core/Method.h" + +//TRANSFORMS +#include "engine/SingleBP.h" +#include "transform/BZip2.h" + + +#endif /* ADIOS_OOP_H_ */ diff --git a/include/capsule/Heap.h b/include/capsule/Heap.h index b5085d125..d16d04df3 100644 --- a/include/capsule/Heap.h +++ b/include/capsule/Heap.h @@ -27,15 +27,16 @@ public: * Unique constructor * @param accessMode read, write or append * @param rankMPI MPI rank - * @param dataSize maximum data size set by user - * @param metadataSize maximum metadata size set by user + * @param debugMode true: extra checks, slower + * @param cores threaded operations */ - Heap( const std::string accessMode, const int rankMPI, const bool debugMode = false, const unsigned int cores = 1 ); + Heap( const std::string accessMode, const int rankMPI, const bool debugMode = false, + const unsigned int cores = 1 ); ~Heap( ); - char* GetData( ) const; - char* GetMetadata( ) const; + char* GetData( ); + char* GetMetadata( ); const std::size_t GetDataSize( ) const; const std::size_t GetMetadataSize( ) const; @@ -77,8 +78,6 @@ private: std::vector<char> m_Data; ///< data buffer allocated using the STL in heap memory, default size = 16 Mb std::vector<char> m_Metadata; ///< metadata buffer allocated using the STL in heap memory, default size = 100 Kb - const size_t m_MaxDataSize; ///< maximum data size set by user - const size_t m_MaxMetadataSize; ///< maximum metadata size set by user }; diff --git a/include/capsule/ShmSystemV.h b/include/capsule/ShmSystemV.h index 7b2046a8f..c7e1f2c6c 100644 --- a/include/capsule/ShmSystemV.h +++ b/include/capsule/ShmSystemV.h @@ -26,14 +26,17 @@ public: * @param pathName used to create the key as a unique identifier * @param dataSize size of allocated memory segment for data * @param metadataSize size of allocated memory segment for metadata + * @param debugMode true: extra checks, slower + * @param cores threaded operations */ ShmSystemV( const std::string accessMode, const int rankMPI, const std::string pathName, - const size_t dataSize, const size_t metadataSize, const unsigned int cores = 1 ); + const size_t dataSize, const size_t metadataSize, + const bool debugMode = false, const unsigned int cores = 1 ); ~ShmSystemV( ); - char* GetData( ) const; ///< return the pointer to the raw data buffer - char* GetMetadata( ) const; ///< return the pointer to the raw metadata buffer + char* GetData( ); ///< return the pointer to the raw data buffer + char* GetMetadata( ); ///< return the pointer to the raw metadata buffer const std::size_t GetDataSize( ) const; ///< get current data buffer size const std::size_t GetMetadataSize( ) const; ///< get current metadata buffer size @@ -78,6 +81,8 @@ private: const size_t m_MetadataSize; ///< size of the allocated shared memory segment key_t m_MetadataKey; ///< key associated with the metadata buffer, created with ftok int m_MetadataShmID; ///< metadata shared memory buffer id + + void CheckShm( ) const; ///< checks if all shared memory allocations are correct, throws std::bad_alloc, called from constructor if debug mode is true }; } //end namespace diff --git a/include/core/Capsule.h b/include/core/Capsule.h index 9f72f064a..ac3bf4b4b 100644 --- a/include/core/Capsule.h +++ b/include/core/Capsule.h @@ -40,8 +40,8 @@ public: virtual ~Capsule( ); - virtual char* GetData( ) const = 0; ///< return the pointer to the raw data buffer - virtual char* GetMetadata( ) const = 0; ///< return the pointer to the raw metadata buffer + virtual char* GetData( ) = 0; ///< return the pointer to the raw data buffer + virtual char* GetMetadata( ) = 0; ///< return the pointer to the raw metadata buffer virtual const std::size_t GetDataSize( ) const = 0; ///< get current data buffer size virtual const std::size_t GetMetadataSize( ) const = 0; ///< get current metadata buffer size @@ -84,9 +84,9 @@ public: virtual void WriteMetadata( const std::size_t first, const long double* metadata, const std::size_t size ) = 0; -private: +protected: - const int m_RankMPI; ///< current MPI rank + const int m_RankMPI = 0; ///< current MPI rank const bool m_DebugMode = false; ///< true: extra checks const unsigned int m_Cores = 1; ///< number of cores for threaded operations diff --git a/include/core/Engine.h b/include/core/Engine.h index b7e2bcd96..208736cba 100644 --- a/include/core/Engine.h +++ b/include/core/Engine.h @@ -65,10 +65,13 @@ public: * @param method */ Engine( 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 ); + MPI_Comm mpiComm, const Method& method, const bool debugMode = false, const unsigned int cores = 1, + const std::string endMessage = "" ); virtual ~Engine( ); + void SetDefaultGroup( Group& group ); + /** * @brief Write functions can be overridden by derived classes. Base class behavior is to: * 1) Write to Variable values (m_Values) in a group @@ -78,33 +81,33 @@ public: * @param variableName * @param values coming from user app */ - virtual void Write( Group& group, const std::string variableName, const char* values ); - virtual void Write( Group& group, const std::string variableName, const unsigned char* values ); - virtual void Write( Group& group, const std::string variableName, const short* values ); - virtual void Write( Group& group, const std::string variableName, const unsigned short* values ); - virtual void Write( Group& group, const std::string variableName, const int* values ); - virtual void Write( Group& group, const std::string variableName, const unsigned int* values ); - virtual void Write( Group& group, const std::string variableName, const long int* values ); - virtual void Write( Group& group, const std::string variableName, const unsigned long int* values ); - virtual void Write( Group& group, const std::string variableName, const long long int* values ); - virtual void Write( Group& group, const std::string variableName, const unsigned long long int* values ); - virtual void Write( Group& group, const std::string variableName, const float* values ); - virtual void Write( Group& group, const std::string variableName, const double* values ); - virtual void Write( Group& group, const std::string variableName, const long double* values ); - - virtual void Write( const std::string variableName, const char* values ); - virtual void Write( const std::string variableName, const unsigned char* values ); - virtual void Write( const std::string variableName, const short* values ); - virtual void Write( const std::string variableName, const unsigned short* values ); - virtual void Write( const std::string variableName, const int* values ); - virtual void Write( const std::string variableName, const unsigned int* values ); - virtual void Write( const std::string variableName, const long int* values ); - virtual void Write( const std::string variableName, const unsigned long int* values ); - virtual void Write( const std::string variableName, const long long int* values ); - virtual void Write( const std::string variableName, const unsigned long long int* values ); - virtual void Write( const std::string variableName, const float* values ); - virtual void Write( const std::string variableName, const double* values ); - virtual void Write( const std::string variableName, const long double* values ); + 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( const std::string variableName, const char* values ) = 0; + virtual void Write( const std::string variableName, const unsigned char* values ) = 0; + virtual void Write( const std::string variableName, const short* values ) = 0; + virtual void Write( const std::string variableName, const unsigned short* values ) = 0; + virtual void Write( const std::string variableName, const int* values ) = 0; + virtual void Write( const std::string variableName, const unsigned int* values ) = 0; + virtual void Write( const std::string variableName, const long int* values ) = 0; + virtual void Write( const std::string variableName, const unsigned long int* values ) = 0; + virtual void Write( const std::string variableName, const long long int* values ) = 0; + virtual void Write( const std::string variableName, const unsigned long long int* values ) = 0; + virtual void Write( const std::string variableName, const float* values ) = 0; + virtual void Write( const std::string variableName, const double* values ) = 0; + virtual void Write( const std::string variableName, const long double* values ) = 0; virtual void Close( int transportIndex = -1 ); ///< Closes a particular transport @@ -115,10 +118,11 @@ protected: 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 - 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. + virtual void Init( ) = 0; ///< Initialize m_Capsules and m_Transports, called from constructor + virtual void InitCapsules( ) = 0; ///< Initialize transports from Method, called from Init in constructor. + virtual void InitTransports( ) = 0; ///< Initialize transports from Method, called from Init in constructor. /** * Performs preliminary checks before writing a variable. Throws an exception if checks fail. @@ -133,6 +137,19 @@ protected: const std::set<std::string>& types, const std::string hint ) const; + /** + * Used to verify parameters in m_Method containers + * @param itParam iterator to a certain parameter + * @param parameters map of parameters, from m_Method + * @param parameterName used if exception is thrown to provide debugging information + * @param hint used if exception is thrown to provide debugging information + */ + void CheckParameter( const std::map<std::string, std::string>::const_iterator itParam, + const std::map<std::string, std::string>& parameters, + const std::string parameterName, + const std::string hint ) const; + + std::string GetName( const std::vector<std::string>& arguments ) const; //might move this to adiosFunctions }; diff --git a/include/core/Group.h b/include/core/Group.h index 4d470880d..72b27220f 100644 --- a/include/core/Group.h +++ b/include/core/Group.h @@ -38,9 +38,9 @@ namespace adios class Group { -public: + friend class Engine; - std::set< std::string > m_WrittenVariables; ///< set of variables whose T* values have been set with Write (no nullptr) +public: /** * Empty constructor @@ -72,21 +72,22 @@ public: * @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 transform pointer reference to a Transform object, default = nullptr - * @param parameter corresponding parameter used by Transform to do operations + * @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 */ void DefineVariable( const std::string variableName, const std::string type, const std::string dimensionsCSV = "", const std::string globalDimensionsCSV = "", const std::string globalOffsetsCSV = "", - const Transform* transform = nullptr, const short parameter = -1 ); + const std::vector<Transform*> transforms = std::vector<Transform*>(), + const std::vector<int> parameters = std::vector<int>() ); /** * 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 + * @param parameter optional parameter interpreted by the corresponding Transform, default = -1 */ - void AddTransform( const std::string variableName, Transform& transform, const short parameter = -1 ); + void AddTransform( const std::string variableName, Transform& transform, const int parameter = -1 ); /** * Define a new attribute @@ -112,9 +113,13 @@ public: unsigned long long int m_SerialSize = 0; ///< size used for potential serialization of metadata into a std::vector<char>. Counts sizes from m_Variables, m_Attributes, m_GlobalBounds + +private: + + std::set< std::string > m_WrittenVariables; ///< set of variables whose T* values have been set with Write (no nullptr) 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 CVariable + 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 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 @@ -156,7 +161,7 @@ public: * @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; */ - const short SetGlobalBounds( const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) noexcept; + const int SetGlobalBounds( const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) noexcept; /** diff --git a/include/core/Method.h b/include/core/Method.h index 1c38e3525..2a9551c1e 100644 --- a/include/core/Method.h +++ b/include/core/Method.h @@ -26,35 +26,33 @@ public: const std::string m_Type = "SingleBP"; ///< Method type const bool m_DebugMode = false; ///< true: on, throws exceptions and do additional checks, false: off, faster, but unsafe + std::vector< std::map<std::string, std::string> > m_CapsuleParameters; ///< each is a separate Transport containing their own parameters + std::vector< std::map<std::string, std::string> > m_TransportParameters; ///< each is a separate Transport containing their own parameters /** * Unique constructor, must have a type * @param type must be an engine type, default = SingleBP */ - Method( const std::string type = "SingleBP", const bool debugMode = false ); + Method( const std::string type = "", const bool debugMode = false ); ~Method( ); template< class ...Args> void AddCapsule( Args... args ) { - std::vector<std::string> parameters = { args }; + std::vector<std::string> parameters = { args... }; AddCapsuleParameters( parameters ); } template< class ...Args> void AddTransport( Args... args ) { - std::vector<std::string> parameters = { args }; + std::vector<std::string> parameters = { args... }; AddTransportParameters( parameters ); } - private: - std::vector< std::map<std::string, std::string> > m_CapsuleParameters; ///< each is a separate Transport containing their own parameters - std::vector< std::map<std::string, std::string> > m_TransportParameters; ///< each is a separate Transport containing their own parameters - void AddCapsuleParameters( const std::vector<std::string>& parameters ); void AddTransportParameters( const std::vector<std::string>& parameters ); diff --git a/include/core/Transform.h b/include/core/Transform.h index 6737a160d..e664fb574 100644 --- a/include/core/Transform.h +++ b/include/core/Transform.h @@ -11,10 +11,9 @@ /// \cond EXCLUDE_FROM_DOXYGEN #include <string> +#include <vector> /// \endcond -#include "core/Variable.h" - namespace adios { @@ -33,7 +32,6 @@ public: /** * Initialize parent method * @param method zlib, bzip2, szip - * @param variable */ Transform( const std::string method ); diff --git a/include/core/Transport.h b/include/core/Transport.h index 4a0451c7f..fa98eb15b 100644 --- a/include/core/Transport.h +++ b/include/core/Transport.h @@ -30,8 +30,8 @@ class Transport public: const std::string m_Type; ///< transport type from derived class - const std::string m_Name; ///< from Open - const std::string m_AccessMode; ///< from Open + std::string m_Name; ///< from Open + std::string m_AccessMode; ///< from Open #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 diff --git a/include/core/Variable.h b/include/core/Variable.h index fbbf72b1f..cc822d136 100644 --- a/include/core/Variable.h +++ b/include/core/Variable.h @@ -13,7 +13,7 @@ #include <vector> /// \endcond -#include "Transform.h" +#include "core/Transform.h" namespace adios { @@ -21,14 +21,14 @@ namespace adios * @param Base (parent) class for template derived (child) class CVariable. Required to put CVariable objects in STL containers. */ template< class T > -class Variable +struct Variable { - const std::string DimensionsCSV; ///< comma separated list for variables to search for local dimensions - const T* Values; ///< pointer to values passed from user in ADIOS Write - const unsigned short GlobalBoundsIndex; ///< if global > 0, index corresponds to global-bounds in m_GlobalBounds in CGroup, if local then = -1 + std::string DimensionsCSV; ///< comma separated list for variables to search for local dimensions + T* Values; ///< pointer to values passed from user in ADIOS Write + int GlobalBoundsIndex; ///< if global > 0, index corresponds to global-bounds in m_GlobalBounds in CGroup, if local then = -1 std::vector< Transform* > Transforms; ///< associated transforms, sequence determines application order, e.g. first Transforms[0] then Transforms[1]. Pointer used as reference (no memory management). - std::vector< short > Parameters; ///< additional optional parameter understood by the corresponding Transform in Transforms vector + std::vector< int > Parameters; ///< additional optional parameter understood by the corresponding Transform in Transforms vector }; diff --git a/include/engine/SingleBP.h b/include/engine/SingleBP.h index cebbed5e2..52706956b 100644 --- a/include/engine/SingleBP.h +++ b/include/engine/SingleBP.h @@ -13,6 +13,8 @@ namespace adios { +namespace engine +{ class SingleBP : public Engine @@ -47,6 +49,19 @@ public: 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( const std::string variableName, const char* values ); + void Write( const std::string variableName, const unsigned char* values ); + void Write( const std::string variableName, const short* values ); + void Write( const std::string variableName, const unsigned short* values ); + void Write( const std::string variableName, const int* values ); + void Write( const std::string variableName, const unsigned int* values ); + void Write( const std::string variableName, const long int* values ); + void Write( const std::string variableName, const unsigned long int* values ); + void Write( const std::string variableName, const long long int* values ); + void Write( const std::string variableName, const unsigned long long int* values ); + void Write( const std::string variableName, const float* values ); + void Write( const std::string variableName, const double* values ); + void Write( const std::string variableName, const long double* values ); private: @@ -62,8 +77,8 @@ private: - -} //end namespace +} //end namespace engine +} //end namespace adios #endif /* SINGLEBP_H_ */ diff --git a/include/functions/capsuleTemplates.h b/include/functions/capsuleTemplates.h index 6a29acceb..802c12244 100644 --- a/include/functions/capsuleTemplates.h +++ b/include/functions/capsuleTemplates.h @@ -30,7 +30,7 @@ namespace adios * @param max */ template<class T> -void GetMinMax( const T* values, const size_t size, T& min, T& max ) +void GetMinMax( const T* values, const size_t size, T& min, T& max, const unsigned int cores = 1 ) { min = values[0]; max = values[0]; @@ -93,74 +93,74 @@ void MemcpyThreads( T* destination, const U* source, std::size_t count, const un * @param maxBufferSize * @param buffer */ -template<class T> -void WriteToBuffer( const T* data, const size_t size, - std::vector< std::shared_ptr<Transport> >& transports, - const size_t maxBufferSize, std::vector<char>& buffer ) -{ - auto lf_TransportsWrite = []( const int transportIndex, std::vector< std::shared_ptr<Transport> >& transports, - std::vector<char>& buffer ) - { - if( transportIndex == -1 ) // all transports - { - for( auto& transport : transports ) - transport->Write( buffer ); - } - else - transports[ transportIndex ]->Write( buffer ); - }; - - //FUNCTION starts here - const size_t dataBytes = size * sizeof( T ); //size of data in bytes - - //check for DataMan transport - if( transportIndex == -1 ) // all transports - { - for( auto& transport : transports ) - { - if( transport->m_Method == "DataMan" ) //DataMan needs all the information - buffer.resize( dataBytes ); //resize buffer to fit all data - } - } - else //just one transport - { - if( transports[transportIndex]->m_Method == "DataMan" ) - buffer.resize( dataBytes ); //resize buffer to fit all data - } - - if( dataBytes <= buffer.size() ) // dataBytes < buffer.size() - { - buffer.resize( dataBytes ); //this resize shouldn't change capacity or call realloc - MemcpyThreads( &buffer[0], data, dataBytes, 1 ); //copy memory in threaded fashion, need to test with size, serial for now - lf_TransportsWrite( transportIndex, transports, buffer ); - return; - } - - if( buffer.size() < dataBytes && dataBytes <= maxBufferSize ) // buffer.size() < dataBytes < maxBufferSize - { - buffer.resize( dataBytes ); - MemcpyThreads( &buffer[0], data, dataBytes, 1 ); //copy memory in threaded fashion, need to test with size, serial for now - lf_TransportsWrite( transportIndex, transports, buffer ); - return; - } - - // dataBytes > maxBufferSize == buffer.size() split the variable in buffer buckets - buffer.resize( maxBufferSize ); //resize to maxBufferSize, this might call realloc - const size_t buckets = dataBytes / maxBufferSize + 1; - const size_t remainder = dataBytes % maxBufferSize; - - for( unsigned int bucket = 0; buckets < buckets; ++bucket ) - { - const size_t dataOffset = bucket * maxBufferSize / sizeof( T ); - - if( bucket == buckets-1 ) - MemcpyThreads( &buffer[0], data[dataOffset], remainder, 1 ); - else - MemcpyThreads( &buffer[0], data[dataOffset], maxBufferSize, 1 ); - - lf_TransportsWrite( transportIndex, transports, buffer ); - } -} +//template<class T> +//void WriteToBuffer( const T* data, const size_t size, +// std::vector< std::shared_ptr<Transport> >& transports, +// const size_t maxBufferSize, std::vector<char>& buffer ) +//{ +// auto lf_TransportsWrite = []( const int transportIndex, std::vector< std::shared_ptr<Transport> >& transports, +// std::vector<char>& buffer ) +// { +// if( transportIndex == -1 ) // all transports +// { +// for( auto& transport : transports ) +// transport->Write( buffer ); +// } +// else +// transports[ transportIndex ]->Write( buffer ); +// }; +// +// //FUNCTION starts here +// const size_t dataBytes = size * sizeof( T ); //size of data in bytes +// +// //check for DataMan transport +// if( transportIndex == -1 ) // all transports +// { +// for( auto& transport : transports ) +// { +// if( transport->m_Method == "DataMan" ) //DataMan needs all the information +// buffer.resize( dataBytes ); //resize buffer to fit all data +// } +// } +// else //just one transport +// { +// if( transports[transportIndex]->m_Method == "DataMan" ) +// buffer.resize( dataBytes ); //resize buffer to fit all data +// } +// +// if( dataBytes <= buffer.size() ) // dataBytes < buffer.size() +// { +// buffer.resize( dataBytes ); //this resize shouldn't change capacity or call realloc +// MemcpyThreads( &buffer[0], data, dataBytes, 1 ); //copy memory in threaded fashion, need to test with size, serial for now +// lf_TransportsWrite( transportIndex, transports, buffer ); +// return; +// } +// +// if( buffer.size() < dataBytes && dataBytes <= maxBufferSize ) // buffer.size() < dataBytes < maxBufferSize +// { +// buffer.resize( dataBytes ); +// MemcpyThreads( &buffer[0], data, dataBytes, 1 ); //copy memory in threaded fashion, need to test with size, serial for now +// lf_TransportsWrite( transportIndex, transports, buffer ); +// return; +// } +// +// // dataBytes > maxBufferSize == buffer.size() split the variable in buffer buckets +// buffer.resize( maxBufferSize ); //resize to maxBufferSize, this might call realloc +// const size_t buckets = dataBytes / maxBufferSize + 1; +// const size_t remainder = dataBytes % maxBufferSize; +// +// for( unsigned int bucket = 0; buckets < buckets; ++bucket ) +// { +// const size_t dataOffset = bucket * maxBufferSize / sizeof( T ); +// +// if( bucket == buckets-1 ) +// MemcpyThreads( &buffer[0], data[dataOffset], remainder, 1 ); +// else +// MemcpyThreads( &buffer[0], data[dataOffset], maxBufferSize, 1 ); +// +// lf_TransportsWrite( transportIndex, transports, buffer ); +// } +//} diff --git a/include/transform/BZIP2.h b/include/transform/BZip2.h similarity index 86% rename from include/transform/BZIP2.h rename to include/transform/BZip2.h index 43799e306..2f2daffc5 100644 --- a/include/transform/BZIP2.h +++ b/include/transform/BZip2.h @@ -1,5 +1,5 @@ /* - * BZIP2.h + * BZip2.h * * Created on: Oct 17, 2016 * Author: wfg @@ -14,6 +14,8 @@ namespace adios { +namespace transform +{ class BZIP2 : public Transform @@ -36,7 +38,8 @@ public: }; -} //end namespace +} //end namespace transform +} //end namespace adios diff --git a/include/transport/MPIFile.h b/include/transport/MPIFile.h index 89d22765c..57389b334 100644 --- a/include/transport/MPIFile.h +++ b/include/transport/MPIFile.h @@ -22,7 +22,7 @@ class MPIFile : public Transport public: - MPIFile( MPI_Comm mpiComm, const bool debugMode, const std::vector<std::string>& arguments ); + MPIFile( MPI_Comm mpiComm, const bool debugMode ); ~MPIFile( ); diff --git a/src/ADIOS.cpp b/src/ADIOS.cpp index b9b8df803..8b650933c 100644 --- a/src/ADIOS.cpp +++ b/src/ADIOS.cpp @@ -15,6 +15,8 @@ #include "ADIOS.h" #include "functions/adiosFunctions.h" +//Engine +#include "engine/SingleBP.h" namespace adios { @@ -67,22 +69,33 @@ void ADIOS::DeclareGroup( const std::string groupName ) throw std::invalid_argument( "ERROR: group " + groupName + " already exist, from call to DeclareGroup\n" ); } - m_Groups.emplace( groupName, Group( m_HostLanguage, m_DebugMode ) ); + m_Groups.emplace( groupName, Group( m_DebugMode ) ); } -void ADIOS::SetGroup( const unsigned int handler, const std::string groupName ) +void ADIOS::SetDefaultGroup( const unsigned int handler, const std::string groupName ) { auto itEngine = m_Engines.find( handler ); auto itGroup = m_Groups.find( groupName ); if( m_DebugMode == true ) { - CheckEngine( itEngine, handler, " in call to SetGroup.\n" ); - CheckGroup( itGroup, groupName, " in call to SetGroup.\n" ); + CheckEngine( itEngine, handler, " in call to SetDefaultGroup.\n" ); + CheckGroup( itGroup, groupName, " in call to SetDefaultGroup.\n" ); } - itEngine->second->m_Group = &( itGroup->second ); + itEngine->second->SetDefaultGroup( itGroup->second ); +} + + +void ADIOS::DeclareMethod( const std::string methodName, const std::string type ) +{ + if( m_DebugMode == true ) + { + if( m_Methods.count( methodName ) == 1 ) + throw std::invalid_argument( "ERROR: method " + methodName + " already declared, from DeclareMethod\n" ); + } + m_Methods.emplace( methodName, Method( type, m_DebugMode ) ); } @@ -100,24 +113,38 @@ const unsigned int ADIOS::Open( const std::string name, const std::string access } ++m_EngineCounter; + const std::string type( itMethod->second.m_Type ); - if( methodName == "SingleBP" ) + if( type == "SingleBP" || type == "singleBP" || type == "singlebp" ) { - m_Engines[ m_EngineCounter ] = std::make_shared<SingleBP>( name, accessMode, mpiComm, itMethod->second, cores ); + m_Engines.emplace( m_EngineCounter, std::make_shared<engine::SingleBP>( name, accessMode, mpiComm, itMethod->second, cores ) ); } - else if( methodName == "SIRIUS" ) +// else if( type == "SIRIUS" ) +// { +// //here must complete +// } +// else if( type == "DataMan" ) +// { +// //here must complete +// } + else { - //here must complete - } - else if( methodName == "DataMan" ) - { - //here must complete + if( m_DebugMode == true ) + throw std::invalid_argument( "ERROR: type " + type + " not supported for method " + methodName + ", in call to Open\n" ); } return m_EngineCounter; } +const unsigned int ADIOS::Open( const std::string streamName, const std::string accessMode, const std::string methodName, + const unsigned int cores ) +{ + return Open( streamName, accessMode, m_MPIComm, methodName, cores ); +} + + + void ADIOS::Close( const unsigned int handler, const int transportIndex ) //close stream { auto itEngine = m_Engines.find( handler ); @@ -203,7 +230,7 @@ void ADIOS::CheckEngine( std::unordered_map< unsigned int, std::shared_ptr<Engin const unsigned int handle, const std::string hint ) const { if( itEngine == m_Engines.end() ) - throw std::invalid_argument( "ERROR: stream (or file) from handle " + handle + " not created with Open , " + hint + "\n" ); + throw std::invalid_argument( "ERROR: stream (or file) from handle " + std::to_string( handle ) + " not created with Open , " + hint + "\n" ); } diff --git a/src/capsule/Heap.cpp b/src/capsule/Heap.cpp index c858a4c4a..7706601ad 100644 --- a/src/capsule/Heap.cpp +++ b/src/capsule/Heap.cpp @@ -26,15 +26,15 @@ Heap::~Heap( ) { } -char* Heap::GetData( ) const +char* Heap::GetData( ) { - return m_Data.front(); + return &m_Data.front(); } -char* Heap::GetMetadata( ) const +char* Heap::GetMetadata( ) { - return m_Metadata.front(); + return &m_Metadata.front(); } diff --git a/src/capsule/ShmSystemV.cpp b/src/capsule/ShmSystemV.cpp index 1b0bdfbc9..0ed5cef2b 100644 --- a/src/capsule/ShmSystemV.cpp +++ b/src/capsule/ShmSystemV.cpp @@ -7,7 +7,10 @@ #include <sys/shm.h> +#include <ios> //std::ios_base::failure + #include "capsule/ShmSystemV.h" +#include "functions/capsuleTemplates.h" namespace adios @@ -15,8 +18,9 @@ namespace adios ShmSystemV::ShmSystemV( const std::string accessMode, const int rankMPI, const std::string pathName, - const size_t dataSize, const size_t metadataSize, const unsigned int cores ): - Capsule( "ShmSystemV", accessMode, rankMPI, cores ), + const size_t dataSize, const size_t metadataSize, + const bool debugMode, const unsigned int cores ): + Capsule( "ShmSystemV", accessMode, rankMPI, debugMode, cores ), m_DataSize{ dataSize }, m_MetadataSize{ metadataSize } { @@ -24,30 +28,17 @@ ShmSystemV::ShmSystemV( const std::string accessMode, const int rankMPI, const s const std::string dataPath( pathName + "/adios.shm.data." + std::to_string( m_RankMPI ) ); m_DataKey = ftok( dataPath.c_str(), m_RankMPI+1 ); m_DataShmID = shmget( m_DataKey, m_DataSize, IPC_CREAT | 0666 ); - - if( m_DataShmID < 0) - throw std::ios_base::failure( "ERROR: Failed to create data shm segment of size " + m_DataSize + - " from call to ShmSystemV constructor\n" ); - m_Data = (char*)shmat( m_DataShmID, NULL, 0 ); - if( m_Data == nullptr ) - throw std::ios_base::failure( "ERROR: Failed to attach to data shm segment of size " + m_DataSize + - " from call to ShmSystemV constructor\n" ); // Metadata Shared memory sector const std::string metadataPath( pathName + "/adios.shm.metadata." + std::to_string( m_RankMPI ) ); m_MetadataKey = ftok( metadataPath.c_str(), m_RankMPI+1 ); //2nd field must be greater than zero and unique m_MetadataShmID = shmget( m_MetadataKey, m_MetadataSize, IPC_CREAT | 0666 ); - - if( m_DataShmID < 0) - throw std::ios_base::failure( "ERROR: Failed to create metadata shm segment of size " + m_MetadataSize + - " from call to ShmSystemV constructor\n" ); - m_Metadata = (char*)shmat( m_MetadataShmID, NULL, 0 ); - if( m_Metadata == nullptr ) - throw std::ios_base::failure( "ERROR: Failed to attach to metadata shm segment of size " + m_MetadataSize + - " from call to ShmSystemV constructor\n" ); + + if( m_DebugMode == true ) + CheckShm( ); } @@ -55,13 +46,13 @@ ShmSystemV::~ShmSystemV( ) { } -char* ShmSystemV::GetData( ) const +char* ShmSystemV::GetData( ) { return m_Data; } -char* ShmSystemV::GetMetadata( ) const +char* ShmSystemV::GetMetadata( ) { return m_Metadata; } @@ -78,7 +69,6 @@ const std::size_t ShmSystemV::GetMetadataSize( ) const return m_MetadataSize; } - //WriteData functions void ShmSystemV::WriteData( const std::size_t first, const char* data, const std::size_t size ) { @@ -212,5 +202,28 @@ void ShmSystemV::WriteMetadata( const std::size_t first, const long double* meta } +void ShmSystemV::CheckShm( ) const +{ + if( m_DataShmID < 0) + throw std::ios_base::failure( "ERROR: Failed to create data shm segment of size " + std::to_string( m_DataSize ) + + " from call to ShmSystemV constructor\n" ); + + if( m_Data == nullptr ) + throw std::ios_base::failure( "ERROR: Failed to attach to data shm segment of size " + std::to_string( m_DataSize ) + + " and id " + std::to_string( m_DataShmID ) + + ", from call to ShmSystemV constructor\n" ); + + if( m_DataShmID < 0) + throw std::ios_base::failure( "ERROR: Failed to create metadata shm segment of size " + std::to_string( m_MetadataSize ) + + " from call to ShmSystemV constructor\n" ); + + + if( m_Metadata == nullptr ) + throw std::ios_base::failure( "ERROR: Failed to attach to metadata shm segment of size " + std::to_string( m_MetadataSize ) + + " and id " + std::to_string( m_MetadataShmID ) + + " from call to ShmSystemV constructor\n" ); +} + + } //end namespace diff --git a/src/core/Engine.cpp b/src/core/Engine.cpp index fea99e02f..90d5cd98c 100644 --- a/src/core/Engine.cpp +++ b/src/core/Engine.cpp @@ -7,7 +7,8 @@ #include "core/Engine.h" -#include "functions/engineTemplates.h" +#include "core/Support.h" +#include "functions/adiosFunctions.h" namespace adios @@ -16,14 +17,15 @@ 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 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_MPIComm{ mpiComm }, + m_Method{ method }, m_DebugMode{ debugMode }, - m_Cores{ cores } + m_Cores{ cores }, + m_EndMessage{ endMessage } { MPI_Comm_rank( m_MPIComm, &m_RankMPI ); MPI_Comm_size( m_MPIComm, &m_SizeMPI ); @@ -33,104 +35,12 @@ Engine::Engine( const std::string engineType, const std::string name, const std: Engine::~Engine( ) { } - -void Engine::Init( ) -{ } - - -void Engine::InitCapsules( ) -{ } - - -void Engine::InitTransports( ) -{ } - - -//WRITE Functions -void Engine::Write( Group& group, const std::string variableName, const char* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("char"), " from call to Write char*" ); - WriteToCapsules( group, group.m_Char[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const unsigned char* values ) +void Engine::SetDefaultGroup( Group& group ) { - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("unsigned char"), " from call to Write unsigned char*" ); - WriteToCapsules( group, group.m_UChar[index], values, m_Capsules, m_Transports ); + m_Group = &group; } - -void Engine::Write( Group& group, const std::string variableName, const short* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("short"), " from call to Write short*" ); - WriteToCapsules( group, group.m_Short[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const unsigned short* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("unsigned short"), " from call to Write unsigned short*" ); - WriteToCapsules( group, group.m_UShort[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const int* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("int"), " from call to Write int*" ); - WriteToCapsules( group, group.m_Int[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const unsigned int* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("unsigned int"), " from call to Write unsigned int*" ); - WriteToCapsules( group, group.m_UInt[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const long int* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("long int"), " from call to Write long int*" ); - WriteToCapsules( group, group.m_LInt[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const unsigned long int* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("unsigned long int"), " from call to Write unsigned long int*" ); - WriteToCapsules( group, group.m_ULInt[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const long long int* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("long long int"), " from call to Write long long int*" ); - WriteToCapsules( group, group.m_LLInt[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const unsigned long long int* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("unsigned long long int"), " from call to Write unsigned long long int*" ); - WriteToCapsules( group, group.m_ULLInt[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const float* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("float"), " from call to Write float*" ); - WriteToCapsules( group, group.m_Float[index], values, m_Capsules, m_Transports ); -} - - -void Engine::Write( Group& group, const std::string variableName, const double* values ) -{ - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("double"), " from call to Write double*" ); - WriteToCapsules( group, group.m_Double[index], values, m_Capsules, m_Transports ); -} - - +//PROTECTED const unsigned int Engine::PreSetVariable( Group& group, const std::string variableName, const std::set<std::string>& types, const std::string hint ) const @@ -142,7 +52,7 @@ const unsigned int Engine::PreSetVariable( Group& group, const std::string varia if( itVariable == group.m_Variables.end() ) throw std::invalid_argument( "ERROR: variable " + variableName + " doesn't exist " + hint + ".\n" ); - if( IsTypeAlias( itVariable->first, types ) == false ) + if( IsTypeAlias( itVariable->second.first, types ) == false ) throw std::invalid_argument( "ERROR: type in variable " + variableName + " doesn't match " + hint + ".\n" ); } @@ -165,8 +75,29 @@ void Engine::Close( int transportIndex ) } } +void Engine::Init( ) +{ } + + +void Engine::InitCapsules( ) +{ } + + +void Engine::InitTransports( ) +{ } + + +void Engine::CheckParameter( const std::map<std::string, std::string>::const_iterator itParam, + const std::map<std::string, std::string>& parameters, + const std::string parameterName, + const std::string hint ) const +{ + if( itParam == parameters.end() ) + throw std::invalid_argument( "ERROR: parameter name " + parameterName + " not found " + hint ); +} + + -//PROTECTED std::string Engine::GetName( const std::vector<std::string>& arguments ) const { bool isNameFound = false; @@ -194,6 +125,3 @@ std::string Engine::GetName( const std::vector<std::string>& arguments ) const } //end namespace - - - diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 7602abb60..21164d622 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -19,11 +19,15 @@ namespace adios { - Group::Group( ) { } +Group::Group( const bool debugMode ): + m_DebugMode{ debugMode } +{ } + + Group::Group( const std::string& xmlGroup, std::vector< std::shared_ptr<Transform> >& transforms, const bool debugMode ): m_DebugMode{ debugMode } { @@ -38,7 +42,7 @@ Group::~Group( ) void Group::DefineVariable( const std::string variableName, const std::string type, const std::string dimensionsCSV, const std::string globalDimensionsCSV, const std::string globalOffsetsCSV, - const Transform* transform, const short parameter ) + std::vector<Transform*> transforms, std::vector<int> parameters ) { if( m_DebugMode == true ) { @@ -46,71 +50,71 @@ void Group::DefineVariable( const std::string variableName, const std::string ty throw std::invalid_argument( "ERROR: variable " + variableName + " already exists, in call to DefineVariable\n" ); } - short globalBoundsIndex = SetGlobalBounds( globalDimensionsCSV, globalOffsetsCSV ); + const int globalBoundsIndex = SetGlobalBounds( globalDimensionsCSV, globalOffsetsCSV ); if( IsTypeAlias( type, Support::DatatypesAliases.at("char") ) == true ) { - m_Char.push_back( Variable<char>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_Char.push_back( Variable<char>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_Char.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("unsigned char") ) == true ) { - m_UChar.push_back( Variable<unsigned char>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_UChar.push_back( Variable<unsigned char>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_UChar.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("short") ) == true ) { - m_Short.push_back( Variable<short>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_Short.push_back( Variable<short>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_Short.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("unsigned short") ) == true ) { - m_UShort.push_back( Variable<unsigned short>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_UShort.push_back( Variable<unsigned short>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_UShort.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("int") ) == true ) { - m_Int.push_back( Variable<int>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_Int.push_back( Variable<int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_Int.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("unsigned int") ) == true ) { - m_UInt.push_back( Variable<unsigned int>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_UInt.push_back( Variable<unsigned int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_UInt.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("long int") ) == true ) { - m_LInt.push_back( Variable<long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_LInt.push_back( Variable<long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_LInt.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("unsigned long int") ) == true ) { - m_ULInt.push_back( Variable<unsigned long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_ULInt.push_back( Variable<unsigned long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_ULInt.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("long long int") ) == true ) { - m_LLInt.push_back( Variable<long long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_LLInt.push_back( Variable<long long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_LLInt.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("unsigned long long int") ) == true ) { - m_ULLInt.push_back( Variable<unsigned long long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_ULLInt.push_back( Variable<unsigned long long int>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_ULLInt.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("float") ) == true ) { - m_Float.push_back( Variable<float>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_Float.push_back( Variable<float>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_Float.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("double") ) == true ) { - m_Double.push_back( Variable<double>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_Double.push_back( Variable<double>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_Double.size()-1 ); } else if( IsTypeAlias( type, Support::DatatypesAliases.at("long double") ) == true ) { - m_LDouble.push_back( Variable<long double>{ dimensionsCSV, nullptr, globalBoundsIndex, transform, parameter } ); + m_LDouble.push_back( Variable<long double>{ dimensionsCSV, nullptr, globalBoundsIndex, transforms, parameters } ); m_Variables[variableName] = std::make_pair( type, m_LDouble.size()-1 ); } else @@ -123,7 +127,7 @@ void Group::DefineVariable( const std::string variableName, const std::string ty } -void Group::AddTransform( const std::string variableName, Transform& transform, const short parameter ) +void Group::AddTransform( const std::string variableName, Transform& transform, const int parameter ) { auto itVariable = m_Variables.find( variableName ); @@ -203,7 +207,7 @@ void Group::DefineAttribute( const std::string attributeName, const std::string { auto lf_GetTypeID = []( const std::string type, const bool debugMode ) -> const char { - char typeID; + char typeID = '\0'; if( type == "string" ) typeID = '0'; else if( type == "numeric" ) @@ -211,7 +215,8 @@ void Group::DefineAttribute( const std::string attributeName, const std::string else { if( debugMode == true ) - throw std::invalid_argument( "ERROR: type " + type + " must be string or numeric, in call to DefineAttribute\n" ); + throw std::invalid_argument( "ERROR: type " + type + " must be string or numeric, " + " in call to DefineAttribute\n" ); } return typeID; @@ -423,7 +428,7 @@ void Group::ParseXMLGroup( const std::string& xmlGroup, std::vector< std::shared } -const short Group::SetGlobalBounds( const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) noexcept +const int Group::SetGlobalBounds( const std::string globalDimensionsCSV, const std::string globalOffsetsCSV ) noexcept { if( globalDimensionsCSV.empty() || globalOffsetsCSV.empty() ) return -1; diff --git a/src/engine/SingleBP.cpp b/src/engine/SingleBP.cpp index a1e750b75..fdb47ff15 100644 --- a/src/engine/SingleBP.cpp +++ b/src/engine/SingleBP.cpp @@ -4,7 +4,11 @@ * Created on: Dec 19, 2016 * Author: wfg */ + +#include <iostream> + #include "engine/SingleBP.h" +#include "core/Support.h" //supported capsules #include "capsule/Heap.h" @@ -12,15 +16,18 @@ //supported transports #include "transport/POSIX.h" #include "transport/FStream.h" +#include "transport/File.h" namespace adios { +namespace engine +{ SingleBP::SingleBP( const std::string streamName, const std::string accessMode, const MPI_Comm mpiComm, const Method& method, const bool debugMode, const unsigned int cores ): - Engine( "SingleBP", streamName, accessMode, mpiComm, method, debugMode, cores ) + Engine( "SingleBP", streamName, accessMode, mpiComm, method, debugMode, cores, " SingleBP constructor (or call to ADIOS Open).\n" ) { Init( ); } @@ -37,10 +44,138 @@ void SingleBP::Init( ) } +void SingleBP::Write( Group& group, const std::string variableName, const char* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const unsigned char* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const short* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const unsigned short* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const int* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const unsigned int* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const long int* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const unsigned long int* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const long long int* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const unsigned long long int* values ) +{ + +} + +void SingleBP::Write( Group& group, const std::string variableName, const float* values ) +{ + +} + void SingleBP::Write( Group& group, const std::string variableName, const double* values ) { - auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("double"), " from call to Write double*" ); + //auto index = PreSetVariable( group, variableName, Support::DatatypesAliases.at("double"), " from call to Write double*" ); +} + + +void SingleBP::Write( Group& group, const std::string variableName, const long double* values ) +{ + +} + + +void SingleBP::Write( const std::string variableName, const char* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const unsigned char* values ) +{ + +} +void SingleBP::Write( const std::string variableName, const short* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const unsigned short* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const int* values ) +{ + auto index = PreSetVariable( *m_Group, variableName, Support::DatatypesAliases.at("int"), " from call to Write int*" ); + std::cout << "Hello from SingleBP Write integer with index " << index << "\n"; +} + +void SingleBP::Write( const std::string variableName, const unsigned int* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const long int* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const unsigned long int* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const long long int* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const unsigned long long int* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const float* values ) +{ + +} + +void SingleBP::Write( const std::string variableName, const double* values ) +{ + auto index = PreSetVariable( *m_Group, variableName, Support::DatatypesAliases.at("double"), " from call to Write double*" ); + std::cout << "Hello from SingleBP Write double with index " << index << "\n"; +} + + +void SingleBP::Write( const std::string variableName, const long double* values ) +{ } @@ -51,14 +186,21 @@ void SingleBP::InitCapsules( ) { if( m_Method.m_CapsuleParameters.size() > 1 ) { - throw std::invalid_argument( "ERROR: SingleBP engine only allows one heap buffer, from SingleBP constructor in Open.\n" ); + throw std::invalid_argument( "ERROR: SingleBP engine only allows one heap buffer, in " + m_Name + + m_EndMessage ); } else if( m_Method.m_CapsuleParameters.size() == 1 ) { - if( m_Method.m_CapsuleParameters[0].at("type") != "Heap" ) - throw std::invalid_argument( "ERROR: SingleBP doesn't support Capsule of type " + + ", from SingleBP constructor in Open.\n" ); - } + auto itType = m_Method.m_CapsuleParameters[0].find( "buffer" ); + + if( m_DebugMode == true ) + CheckParameter( itType, m_Method.m_CapsuleParameters[0], " capsule buffer", + ", in " + m_Name + m_EndMessage ); + if( !( itType->second == "Heap" || itType->second == "HEAP" ) ) + throw std::invalid_argument( "ERROR: SingleBP doesn't support Capsule of buffer type " + + itType->second + " in " + m_Name + m_EndMessage ); + } } //Create single capsule of type heap m_Capsules.push_back( std::make_shared<Heap>( m_AccessMode, m_RankMPI, m_Cores ) ); @@ -70,50 +212,68 @@ void SingleBP::InitTransports( ) { std::set< std::string > transportStreamNames; //used to check for name conflict between transports + const unsigned int transportsSize = m_Method.m_TransportParameters.size(); for( const auto& parameters : m_Method.m_TransportParameters ) { - const std::string transport = parameters.at("type"); - const std::string name = parameters.at("name"); + auto itTransport = parameters.find( "transport" ); + if( m_DebugMode == true ) + CheckParameter( itTransport, parameters, "transport", ", in " + m_Name + m_EndMessage ); + - if( transport == "POSIX" ) + if( itTransport->second == "POSIX" ) { m_Transports.push_back( std::make_shared<POSIX>( m_MPIComm, m_DebugMode ) ); } - else if( transport == "File" ) + else if( itTransport->second == "File" ) { - m_Transports.push_back( std::make_shared<FStream>( m_MPIComm, m_DebugMode ) ); - + m_Transports.push_back( std::make_shared<File>( m_MPIComm, m_DebugMode ) ); } - else if( transport == "FStream" ) + else if( itTransport->second == "FStream" ) { m_Transports.push_back( std::make_shared<FStream>( m_MPIComm, m_DebugMode ) ); } - else if( transport == "MPIFile" ) + else if( itTransport->second == "MPIFile" ) { - m_Transports.push_back( std::make_shared<FStream>( m_MPIComm, m_DebugMode ) ); + //m_Transports.push_back( std::make_shared<MPIFile>( m_MPIComm, m_DebugMode ) ); } else { if( m_DebugMode == true ) - throw std::invalid_argument( "ERROR: transport + " + transport + " not supported, in Engine constructor (or Open).\n" ); + throw std::invalid_argument( "ERROR: transport + " + itTransport->second + " not supported, in " + + m_Name + m_EndMessage ); } + //name + if( transportsSize > 1 ) + { + auto itName = parameters.find( "name" ); //first check name + if( m_DebugMode == true ) + CheckParameter( itName, parameters, "name", " in transport " + itTransport->second + + ", in " + m_Name + m_EndMessage ); - m_Transports.back()->Open( name, m_AccessMode ); - } -} - - - - - - - + m_Transports.back()->Open( itName->second, m_AccessMode ); + } + else if( transportsSize == 1 ) + { + auto itName = parameters.find( "name" ); + if( itName == parameters.end() ) //take streamName + m_Transports.back()->Open( m_Name, m_AccessMode ); + else + m_Transports.back()->Open( m_Name, m_AccessMode ); + } + else if( transportsSize == 0 ) + { + if( m_DebugMode == true ) + throw std::invalid_argument( "ERROR: transport not defined for engine " + m_Name + m_EndMessage ); + } + } +} -} //end namespace +} //end namespace engine +} //end namespace adios diff --git a/src/functions/adiosFunctions.cpp b/src/functions/adiosFunctions.cpp index 05bcb0d6f..67e089599 100644 --- a/src/functions/adiosFunctions.cpp +++ b/src/functions/adiosFunctions.cpp @@ -269,7 +269,7 @@ void SetMembers( const std::string& fileContent, const MPI_Comm mpiComm, const b throw std::invalid_argument( "ERROR: group " + groupName + " defined twice.\n" ); } - groups.emplace( groupName, Group( hostLanguage, xmlGroup, transforms, debugMode ) ); + groups.emplace( groupName, Group( xmlGroup, transforms, debugMode ) ); currentContent.erase( currentContent.find( xmlGroup ), xmlGroup.size() ); currentPosition = 0; diff --git a/src/transform/BZIP2.cpp b/src/transform/BZip2.cpp similarity index 75% rename from src/transform/BZIP2.cpp rename to src/transform/BZip2.cpp index 2d42b7ba1..36c3bde0b 100644 --- a/src/transform/BZIP2.cpp +++ b/src/transform/BZip2.cpp @@ -7,12 +7,14 @@ -#include "transform/BZIP2.h" +#include "../../include/transform/BZip2.h" namespace adios { +namespace transform +{ BZIP2::BZIP2( ): @@ -37,7 +39,7 @@ void BZIP2::Decompress( const std::vector<char>& bufferIn, std::vector<char>& bu } - -} //end namespace +} //end namespace transform +} //end namespace adios diff --git a/src/transport/FStream.cpp b/src/transport/FStream.cpp index 08dde2e02..5c0e2ec68 100644 --- a/src/transport/FStream.cpp +++ b/src/transport/FStream.cpp @@ -18,9 +18,7 @@ namespace adios FStream::FStream( MPI_Comm mpiComm, const bool debugMode ): Transport( "FStream", mpiComm, debugMode ) -{ - Init( arguments ); -} +{ } FStream::~FStream( ) diff --git a/src/transport/File.cpp b/src/transport/File.cpp index d259e1249..ed8a4796f 100644 --- a/src/transport/File.cpp +++ b/src/transport/File.cpp @@ -5,6 +5,8 @@ * Author: wfg */ +#include <ios> //std::ios_base::failure + #include "transport/File.h" diff --git a/src/transport/POSIX.cpp b/src/transport/POSIX.cpp index 2bea6189c..78834a31d 100644 --- a/src/transport/POSIX.cpp +++ b/src/transport/POSIX.cpp @@ -1,14 +1,18 @@ /* - * POSIXMPI.cpp + * POSIX.cpp * * Created on: Oct 6, 2016 * Author: wfg */ -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> +#include <fcntl.h> //open +#include <sys/types.h> //open +#include <sys/stat.h> //open +#include <stddef.h> // write output +#include <unistd.h> // write, close + +#include <ios> //std::ios_base::failure #include "transport/POSIX.h" @@ -51,13 +55,19 @@ void POSIX::Open( const std::string name, const std::string accessMode ) void POSIX::Write( const char* buffer, std::size_t size ) { - int status = write( m_FileDescriptor, buffer, size ); + auto writtenSize = write( m_FileDescriptor, buffer, size ); if( m_DebugMode == true ) { - if( status == -1 ) + if( writtenSize == -1 ) throw std::ios_base::failure( "ERROR: couldn't write to file " + m_Name + ", in call to POSIX write\n" ); + + if( static_cast<std::size_t>( writtenSize ) != size ) + throw std::ios_base::failure( "ERROR: written size + " + std::to_string( writtenSize ) + + " is not equal to intended size " + + std::to_string( size ) + " in file " + m_Name + + ", in call to POSIX write\n" ); } } @@ -75,7 +85,4 @@ void POSIX::Close( ) } - - - }//end namespace -- GitLab