diff --git a/bindings/python/include/ADIOSPy.h b/bindings/python/include/ADIOSPy.h index 575bd1e1c509a800575a6e6d51c12637fca51e2f..f615c980e2b31ecd00c22010bbb6658a861fc068 100644 --- a/bindings/python/include/ADIOSPy.h +++ b/bindings/python/include/ADIOSPy.h @@ -15,11 +15,14 @@ #include "ADIOS.h" #include "adiosPyFunctions.h" //ListToVector, VectorToList #include "VariablePy.h" +#include "MethodPy.h" namespace adios { +using pyList = boost::python::list; + class ADIOSPy : public ADIOS { @@ -31,35 +34,29 @@ public: void HelloMPI( ); ///< says hello from rank/size for testing - VariablePy<double>& DefineVariableDouble( const std::string name, - const boost::python::list localDimensionsPy = boost::python::list(), - const boost::python::list globalDimensionsPy = boost::python::list(), - const boost::python::list globalOffsetsPy = boost::python::list() ); - std::string DefineVariableFloat( const std::string name, - const boost::python::list localDimensionsPy = boost::python::list(), - const boost::python::list globalDimensionsPy = boost::python::list(), - const boost::python::list globalOffsetsPy = boost::python::list() ); + template<class T> inline + VariablePy<T>& DefineVariablePy( const std::string name, + const pyList localDimensionsPy = pyList(), + const pyList globalDimensionsPy = pyList(), + const pyList globalOffsetsPy = pyList() ) + { + Variable<T>& var = DefineVariable<T>( name, ListToVector( localDimensionsPy ), ListToVector( globalDimensionsPy ), ListToVector( globalOffsetsPy ) ); + return *reinterpret_cast<VariablePy<T>*>( &var ); + } - void SetVariableLocalDimensions( const std::string name, const boost::python::list list ); - std::vector<std::size_t> GetVariableLocalDimensions( const std::string name ); + MethodPy& DeclareMethodPy( const std::string methodName, const std::string type = "" ); -private: - template< class T > - std::string DefineVariablePy( const std::string name, const boost::python::list& localDimensionsPy, - const boost::python::list& globalDimensionsPy, const boost::python::list& globalOffsetsPy ) - { - DefineVariable<T>( name, ListToVector( localDimensionsPy ), ListToVector( globalDimensionsPy ), ListToVector( globalOffsetsPy ) ); - return name; - } }; + + } //end namespace diff --git a/bindings/python/include/MethodPy.h b/bindings/python/include/MethodPy.h new file mode 100644 index 0000000000000000000000000000000000000000..e2d8046e803cf4f4f616b30b0e089c14306a96d5 --- /dev/null +++ b/bindings/python/include/MethodPy.h @@ -0,0 +1,51 @@ +/* + * MethodPy.h + * + * Created on: Mar 14, 2017 + * Author: wfg + */ + +#ifndef METHODPY_H_ +#define METHODPY_H_ + +#include <boost/python.hpp> + +#include "core/Method.h" + +namespace adios +{ + +using pyList = boost::python::list; + +class MethodPy : public Method +{ + +public: + + MethodPy( const std::string type, const bool debugMode ); + + ~MethodPy( ); + + /** + * static needed to support raw function + * @param dictionary + * @return + */ + static boost::python::object SetParametersPy( boost::python::tuple args, boost::python::dict kwargs ); + + static boost::python::object AddTransportPy( boost::python::tuple args, boost::python::dict kwargs ); + + void PrintAll( ) const; + +}; + + + + + + + +} + + +#endif /* METHODPY_H_ */ diff --git a/bindings/python/include/VariablePy.h b/bindings/python/include/VariablePy.h index f43619f7db49ed7c3eb19746ff6a6243df972e65..85798c8626e63942e3f2e140f31403538e6214c0 100644 --- a/bindings/python/include/VariablePy.h +++ b/bindings/python/include/VariablePy.h @@ -21,7 +21,7 @@ class VariablePy : public Variable<T> public: VariablePy<T>( const std::string name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets, - const bool debugMode ): + const bool debugMode ): Variable<T>( name, dimensions, globalDimensions, globalOffsets, debugMode ) { } @@ -33,7 +33,14 @@ public: this->m_Dimensions = ListToVector( list ); } - std::vector<std::size_t> GetLocalDimensions( ) + void SetGlobalDimensionsAndOffsets( const boost::python::list globalDimensions, const boost::python::list globalOffsets ) + { + this->m_GlobalDimensions = ListToVector( globalDimensions ); + this->m_GlobalOffsets = ListToVector( globalOffsets ); + } + + + Dims GetLocalDimensions( ) { return this->m_Dimensions; } @@ -43,7 +50,7 @@ public: -} +} //end namespace diff --git a/bindings/python/include/adiosPyFunctions.h b/bindings/python/include/adiosPyFunctions.h index 99935b2a6de1823bcf7186af1dc11e89ae6dd007..cd940ade09f1ff9e6467c7933c74484d6be896c6 100644 --- a/bindings/python/include/adiosPyFunctions.h +++ b/bindings/python/include/adiosPyFunctions.h @@ -9,6 +9,7 @@ #define ADIOSPYFUNCTIONS_H_ #include <vector> +#include <map> #include <string> #include <boost/python.hpp> @@ -16,9 +17,15 @@ namespace adios { -std::vector<std::size_t> ListToVector( const boost::python::list& list ); +using Dims = std::vector<std::size_t>; +/** + * Transforms a boost python list to a Dims (std::vector<std::size_t>) object + * @param list input boost python list from python program + * @return Dims (std::vector<std::size_t>) object than can be passed to python + */ +Dims ListToVector( const boost::python::list& list ); -boost::python::list VectorToList( const std::vector<std::size_t>& list ); +std::map<std::string, std::string> DictToMap( const boost::python::dict& dictionary ); } diff --git a/bindings/python/src/ADIOSPy.cpp b/bindings/python/src/ADIOSPy.cpp index 13be730eea7b0f6695ced146c3afb00f0bb8a9da..d3b6e8526e60308ea57b08c485b9ae57b804431a 100644 --- a/bindings/python/src/ADIOSPy.cpp +++ b/bindings/python/src/ADIOSPy.cpp @@ -28,143 +28,13 @@ void ADIOSPy::HelloMPI( ) } -std::string ADIOSPy::DefineVariableFloat( const std::string name, const boost::python::list localDimensionsPy, - const boost::python::list globalDimensionsPy, const boost::python::list globalOffsetsPy ) +MethodPy& ADIOSPy::DeclareMethodPy( const std::string methodName, const std::string type ) { - return DefineVariablePy<float>( name, localDimensionsPy, globalDimensionsPy, globalOffsetsPy ); + Method& method = DeclareMethod( methodName, type ); + return *reinterpret_cast<MethodPy*>( &method ); } -VariablePy<double>& ADIOSPy::DefineVariableDouble( const std::string name, const boost::python::list localDimensionsPy, - const boost::python::list globalDimensionsPy, const boost::python::list globalOffsetsPy ) -{ - - Variable<double>& var = DefineVariable<double>( name, ListToVector( localDimensionsPy ), ListToVector( globalDimensionsPy ), ListToVector( globalOffsetsPy ) ); - VariablePy<double>& varPy = *reinterpret_cast<VariablePy<double>*>( &var ); - return varPy; -} - - -void ADIOSPy::SetVariableLocalDimensions( const std::string name, const boost::python::list list ) -{ - - auto itVar = m_Variables.find( name ); - CheckVariableName( itVar, name, " in SetVariableLocalDimensions\n" ); - - const std::string type = itVar->second.first; - - if( type == GetType<char>() ) - GetVariable<char>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<unsigned char>() ) - GetVariable<unsigned char>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<short>() ) - GetVariable<short>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<unsigned short>() ) - GetVariable<unsigned short>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<int>() ) - GetVariable<int>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<unsigned int>() ) - GetVariable<unsigned int>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<long int>() ) - GetVariable<long int>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<unsigned long int>() ) - GetVariable<unsigned long int>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<long long int>() ) - GetVariable<long long int>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<unsigned long long int>() ) - GetVariable<unsigned long long int>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<float>() ) - GetVariable<float>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<double>() ) - GetVariable<double>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<long double>() ) - GetVariable<long double>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<std::complex<float>>() ) - GetVariable<std::complex<float>>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<std::complex<double>>() ) - GetVariable<std::complex<double>>( name ).m_Dimensions = ListToVector( list ); - - else if( type == GetType<std::complex<long double>>() ) - GetVariable<std::complex<long double>>( name ).m_Dimensions = ListToVector( list ); -} - - -//boost::python::list ADIOSPy::GetVariableLocalDimensions( const std::string name ) -std::vector<std::size_t> ADIOSPy::GetVariableLocalDimensions( const std::string name ) -{ - auto itVar = m_Variables.find( name ); - CheckVariableName( itVar, name, " in SetVariableLocalDimensions\n" ); - - const std::string type = itVar->second.first; - - std::vector<std::size_t> dims; - - if( type == GetType<char>() ) - dims = GetVariable<char>( name ).m_Dimensions; - - else if( type == GetType<unsigned char>() ) - dims = GetVariable<unsigned char>( name ).m_Dimensions; - - else if( type == GetType<short>() ) - dims = GetVariable<short>( name ).m_Dimensions; - - else if( type == GetType<unsigned short>() ) - dims = GetVariable<unsigned short>( name ).m_Dimensions; - - else if( type == GetType<int>() ) - dims = GetVariable<int>( name ).m_Dimensions; - - else if( type == GetType<unsigned int>() ) - dims = GetVariable<unsigned int>( name ).m_Dimensions; - - else if( type == GetType<long int>() ) - dims = GetVariable<long int>( name ).m_Dimensions; - - else if( type == GetType<unsigned long int>() ) - dims = GetVariable<unsigned long int>( name ).m_Dimensions; - - else if( type == GetType<long long int>() ) - dims = GetVariable<long long int>( name ).m_Dimensions; - - else if( type == GetType<unsigned long long int>() ) - dims = GetVariable<unsigned long long int>( name ).m_Dimensions; - - else if( type == GetType<float>() ) - dims = GetVariable<float>( name ).m_Dimensions; - - else if( type == GetType<double>() ) - dims = GetVariable<double>( name ).m_Dimensions; - - else if( type == GetType<long double>() ) - dims = GetVariable<long double>( name ).m_Dimensions; - - else if( type == GetType<std::complex<float>>() ) - dims = GetVariable<std::complex<float>>( name ).m_Dimensions; - - else if( type == GetType<std::complex<double>>() ) - dims = GetVariable<std::complex<double>>( name ).m_Dimensions; - - else if( type == GetType<std::complex<long double>>() ) - dims = GetVariable<std::complex<long double>>( name ).m_Dimensions; - - return dims; - //return VectorToList( dims ); -} - diff --git a/bindings/python/src/MethodPy.cpp b/bindings/python/src/MethodPy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1eedcc531142ea59287d79d4df6b35a22037fa35 --- /dev/null +++ b/bindings/python/src/MethodPy.cpp @@ -0,0 +1,72 @@ +/* + * MethodPy.cpp + * + * Created on: Mar 14, 2017 + * Author: wfg + */ + + +#include "MethodPy.h" +#include "adiosPyFunctions.h" + +namespace adios +{ + +MethodPy::MethodPy( const std::string type, const bool debugMode ): + Method( type, debugMode ) +{ } + + +MethodPy::~MethodPy( ) +{ } + + +boost::python::object MethodPy::SetParametersPy( boost::python::tuple args, boost::python::dict kwargs ) +{ + if( boost::python::len( args ) > 1 ) + throw std::invalid_argument( "ERROR: syntax of Method SetParameters function is incorrect, only use dictionary\n" ); + + MethodPy& self = boost::python::extract<MethodPy&>( args[0] ); + self.m_Parameters = DictToMap( kwargs ); + return args[0]; +} + + +boost::python::object MethodPy::AddTransportPy( boost::python::tuple args, boost::python::dict kwargs ) +{ + if( boost::python::len( args ) != 2 ) + throw std::invalid_argument( "ERROR: syntax of Method AddTransport function is incorrect, only use one string for transport followed by a dictionary for parameters\n" ); + + MethodPy& self = boost::python::extract<MethodPy&>( args[0] ); + std::string type = boost::python::extract<std::string>( args[1] ); + + auto parameters = DictToMap( kwargs ); + parameters.insert( std::make_pair( "transport", type ) ); + self.m_TransportParameters.push_back( parameters ); + return args[0]; +} + + +void MethodPy::PrintAll( ) const +{ + std::cout << "Method parameters\n"; + for( const auto& param : m_Parameters ) + std::cout << "Key: " << param.first << "\t Value: " << param.second << "\n"; + + std::cout << "\n"; + std::cout << "Method transports\n"; + std::cout << "\n"; + for( const auto& transportParameters : m_TransportParameters ) + { + for( const auto& param : transportParameters ) + std::cout << "Key: " << param.first << "\t Value: " << param.second << "\n"; + + std::cout << "\n"; + } +} + + + + +} //end namespace + diff --git a/bindings/python/src/adiosPyFunctions.cpp b/bindings/python/src/adiosPyFunctions.cpp index df8b41439eb3aba5e326b0e1e81f05a4840c5c88..ed130c9746856f467fa99751e5b7f8e7b7ecf56b 100644 --- a/bindings/python/src/adiosPyFunctions.cpp +++ b/bindings/python/src/adiosPyFunctions.cpp @@ -12,10 +12,10 @@ namespace adios { -std::vector<std::size_t> ListToVector( const boost::python::list& list ) +Dims ListToVector( const boost::python::list& list ) { const boost::python::ssize_t length = boost::python::len( list ); - std::vector<std::size_t> vec; + Dims vec; vec.reserve( length ); for( unsigned int i=0; i<length;i++ ) @@ -24,22 +24,24 @@ std::vector<std::size_t> ListToVector( const boost::python::list& list ) return vec; } - -boost::python::list VectorToList( const std::vector<std::size_t>& vec ) +std::map<std::string, std::string> DictToMap( const boost::python::dict& dictionary ) { - boost::python::list list; + boost::python::list keys = dictionary.keys(); + unsigned int length = boost::python::len( keys ); + + std::map<std::string, std::string> parameters; - for( auto vecElement : vec ) + for( unsigned int k = 0; k < length; ++k ) { - list.append( vecElement ); + const std::string key( boost::python::extract<std::string>( keys[k] ) ); + const std::string value( boost::python::extract<std::string>( dictionary[ keys[k] ] ) ); + parameters.insert( std::make_pair( key, value ) ); } - return list; + return parameters; } - - -} +} //end namespace diff --git a/bindings/python/src/glue.cpp b/bindings/python/src/glue.cpp index 499e1dcf9f4a2a81357480c33dcbec3634d616bd..ba380128e2c2e4e5da76d4054b3640666a70234a 100644 --- a/bindings/python/src/glue.cpp +++ b/bindings/python/src/glue.cpp @@ -8,6 +8,7 @@ #include <mpi4py/mpi4py.h> #include <boost/python.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp> +#include <boost/python/raw_function.hpp> #include "ADIOSPy.h" #include "adiosPyFunctions.h" @@ -21,8 +22,9 @@ adios::ADIOSPy ADIOSPy( boost::python::object py_comm, const bool debug ) } -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( d_overloads, DefineVariableDouble, 1, 4 ) -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( f_overloads, DefineVariableFloat, 1, 4 ) + +using ReturnInternalReference = boost::python::return_internal_reference<>; + BOOST_PYTHON_MODULE( ADIOSPy ) @@ -30,19 +32,17 @@ BOOST_PYTHON_MODULE( ADIOSPy ) if (import_mpi4py() < 0) return; /* Python 2.X */ - boost::python::class_<std::vector<std::size_t> >("Dims") - .def(boost::python::vector_indexing_suite< std::vector<std::size_t> >() ); + boost::python::class_< adios::Dims >("Dims") + .def(boost::python::vector_indexing_suite< adios::Dims >() ); //functions boost::python::def("ADIOSPy", ADIOSPy ); //classes boost::python::class_<adios::ADIOSPy>("ADIOS", boost::python::no_init ) .def("HelloMPI", &adios::ADIOSPy::HelloMPI ) - .def("DefineVariableDouble", &adios::ADIOSPy::DefineVariableDouble, - boost::python::return_value_policy<boost::python::reference_existing_object>(), d_overloads() ) - .def("DefineVariableFloat", &adios::ADIOSPy::DefineVariableFloat, f_overloads() ) - .def("SetVariableLocalDimensions", &adios::ADIOSPy::SetVariableLocalDimensions ) - .def("GetVariableLocalDimensions", &adios::ADIOSPy::GetVariableLocalDimensions ) + .def("DefineVariableDouble", &adios::ADIOSPy::DefineVariablePy<double>, ReturnInternalReference() ) + .def("DefineVariableFloat", &adios::ADIOSPy::DefineVariablePy<float>, ReturnInternalReference() ) + .def("DeclareMethod", &adios::ADIOSPy::DeclareMethodPy, ReturnInternalReference() ) ; //classes @@ -51,5 +51,11 @@ BOOST_PYTHON_MODULE( ADIOSPy ) .def("GetLocalDimensions", &adios::VariablePy<double>::GetLocalDimensions ) ; + boost::python::class_<adios::MethodPy>("Method", boost::python::no_init ) + .def("SetParameters", boost::python::raw_function( &adios::MethodPy::SetParametersPy, 1 ) ) + .def("AddTransport", boost::python::raw_function( &adios::MethodPy::AddTransportPy, 1 ) ) + .def("PrintAll", &adios::MethodPy::PrintAll ) + ; + } diff --git a/bindings/python/test_hello.py b/bindings/python/test_hello.py index b6cdf9cc8c87200c565df0bc3601edfeccb532b5..80e805f57869b5f92d3cdb25e0eab3149417bd16 100644 --- a/bindings/python/test_hello.py +++ b/bindings/python/test_hello.py @@ -8,7 +8,8 @@ from ADIOSPy import * adios = ADIOSPy( MPI.COMM_WORLD, True) adios.HelloMPI( ) -lDims = [10, 11, 12] +rank = MPI.COMM_WORLD.Get_rank() +lDims = [rank+1, rank+2, rank+3] Nx = 1 ioMyDoubles = adios.DefineVariableDouble( "ioMyDoubles", lDims, [], [] ) @@ -24,18 +25,15 @@ dims = ioMyDoubles.GetLocalDimensions( ) print "New Dimensions " for dim in dims: print dim + +method = adios.DeclareMethod("myMethod", "BPFileWriter") +method.SetParameters( max_buffer_size = '10000000' ) +method.AddTransport( 'File', have_metadata_file = 'yes', library = 'FStream' ) +method.AddTransport( "Mdtm", localIP='128.0.0.0.1', remoteIP='128.0.0.0.2', tolerances='1,2,3' ) +print +method.PrintAll( ) -# dims = adios.GetVariableLocalDimensions( ioMyDoubles ) -# -# lDims = [20,20,20] -# adios.SetVariableLocalDimensions( ioMyDoubles, lDims ) -# -# dims = adios.GetVariableLocalDimensions( ioMyDoubles ) -# print "New Dimensions " -# for dim in dims: -# print dim - # bpWriter = adios.Open( ) # ADIOS.SetEngineComm( bpWriter, comm ) diff --git a/include/engine/bp/BPFileWriter.h b/include/engine/bp/BPFileWriter.h index 7c4f637c76302c3761b011ee1af35ff2af7ae023..89f9396d9593d4277003a12a5fb61db256662136 100644 --- a/include/engine/bp/BPFileWriter.h +++ b/include/engine/bp/BPFileWriter.h @@ -115,10 +115,10 @@ private: m_WrittenVariables.insert( variable.m_Name ); //pre-calculate new metadata and payload sizes - const std::size_t indexSize = m_BP1Writer.GetVariableIndexSize( variable ); - const std::size_t payloadSize = variable.PayLoadSize(); //will change if compression is applied - //Buffer reallocation, expensive part - m_TransportFlush = CheckBuffersAllocation( indexSize, payloadSize ); + m_TransportFlush = CheckBuffersAllocation( m_BP1Writer.GetVariableIndexSize( variable ), variable.PayLoadSize(), + m_GrowthFactor, m_MaxBufferSize, + m_MetadataSet.VarsIndexPosition, m_MetadataSet.VarsIndex, + m_Buffer.m_DataPosition, m_Buffer.m_Data ); //WRITE INDEX to data buffer and metadata structure (in memory)// m_BP1Writer.WriteVariableIndex( variable, m_Buffer, m_MetadataSet ); @@ -129,7 +129,7 @@ private: //flush to transports - //reset positions to zero, update absolute position + //reset relative positions to zero, update absolute position } else //Write data to buffer @@ -140,14 +140,6 @@ private: variable.m_AppValues = nullptr; //setting pointer to null as not needed after write } - /** - * Check if heap buffers for data and metadata need reallocation or maximum sizes have been reached. - * @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 std::size_t indexSize, const std::size_t payloadSize ); - }; diff --git a/include/functions/adiosFunctions.h b/include/functions/adiosFunctions.h index d3e2b6bf56ac36ef24f4182444dc08645f8c950a..2225edec74a30ab63cab06954f0844dc3d95d6c6 100644 --- a/include/functions/adiosFunctions.h +++ b/include/functions/adiosFunctions.h @@ -159,6 +159,22 @@ std::map<std::string, std::string> BuildParametersMap( const std::vector<std::st std::vector<int> CSVToVectorInt( const std::string csv ); +/** + * Common strategy to check for heap buffer allocation for data and metadata typically calculated in Write + * @param indexSize metadata index size for a variable + * @param payloadSize variable payload size from application + * @param growthFactor user provided growth factor for index and data memory buffers ( default = 1.5 ) + * @param maxBufferSize user provided maximum buffer size + * @param indexPosition + * @param indexBuffer + * @param buffer heap capsule containing data buffer for payload + * @return true: must do a transport flush, false: buffer sizes are enough to contain incoming data, no need for transport flush + */ +bool CheckBuffersAllocation( const std::size_t indexSize, const std::size_t payloadSize, + const float growthFactor, const std::size_t maxBufferSize, + const std::size_t indexPosition, std::vector<char>& indexBuffer, + const std::size_t dataPosition, std::vector<char>& dataBuffer ); + /** * Grows a buffer by a factor of n . growthFactor . currentCapacity to accommodate for incomingDataSize * @param incomingDataSize size of new data required to be stored in buffer diff --git a/src/engine/bp/BPFileWriter.cpp b/src/engine/bp/BPFileWriter.cpp index a22d286c03277f8ba2a75549f465105321d37593..72a5066ff5b7f6bd0fda180c9989190410d51920 100644 --- a/src/engine/bp/BPFileWriter.cpp +++ b/src/engine/bp/BPFileWriter.cpp @@ -359,20 +359,5 @@ void BPFileWriter::WriteProcessGroupIndex( ) } -bool BPFileWriter::CheckBuffersAllocation( const std::size_t indexSize, const std::size_t payloadSize ) -{ - //Check if data in buffer needs to be reallocated - const std::size_t neededSize = m_Buffer.m_DataPosition + payloadSize + indexSize + 100; //adding some bytes tolerance - // might need to write payload in batches - bool doTransportsFlush = ( neededSize > m_MaxBufferSize )? true : false; - - if( GrowBuffer( neededSize, m_GrowthFactor, m_Buffer.m_DataPosition, m_Buffer.m_Data ) == -1 ) - doTransportsFlush = true; - - GrowBuffer( indexSize, m_GrowthFactor, m_MetadataSet.VarsIndexPosition, m_MetadataSet.VarsIndex ); - return doTransportsFlush; -} - - } //end namespace adios diff --git a/src/functions/adiosFunctions.cpp b/src/functions/adiosFunctions.cpp index 07461bfb362317a052394e4e66dd06b7707ad76a..2abe0c7c4ff22dddc680b660eb6654b1bdda0866 100644 --- a/src/functions/adiosFunctions.cpp +++ b/src/functions/adiosFunctions.cpp @@ -539,6 +539,24 @@ std::vector<int> CSVToVectorInt( const std::string csv ) } +bool CheckBuffersAllocation( const std::size_t indexSize, const std::size_t payloadSize, + const float growthFactor, const std::size_t maxBufferSize, + const std::size_t indexPosition, std::vector<char>& indexBuffer, + const std::size_t dataPosition, std::vector<char>& dataBuffer ) +{ + //Check if data in buffer needs to be reallocated + const std::size_t requiredDataSize = dataPosition + payloadSize + indexSize + 100; //adding some bytes tolerance + // might need to write payload in batches + bool doTransportsFlush = ( requiredDataSize > maxBufferSize )? true : false; + + if( GrowBuffer( requiredDataSize, growthFactor, dataPosition, dataBuffer ) == -1 ) + doTransportsFlush = true; + + GrowBuffer( indexSize, growthFactor, indexPosition, indexBuffer ); + return doTransportsFlush; +} + + int GrowBuffer( const std::size_t incomingDataSize, const float growthFactor, const std::size_t currentPosition, std::vector<char>& buffer )