diff --git a/bindings/python/Makefile b/bindings/python/Makefile index 68eca071f66ba39272f85655765c98ee9a68747f..13d9aa397d358872c63e2d55a20065175753144c 100644 --- a/bindings/python/Makefile +++ b/bindings/python/Makefile @@ -12,8 +12,8 @@ BOOST_INC:= /usr/include/boost BOOST_LIBLOC:= /lib/x86_64-linux-gnu/ # location of ADIOS include and lib -ADIOS_INC:= /home/wfg/workspace/ADIOSPP/include -ADIOS_LIB:= /home/wfg/workspace/ADIOSPP/lib +ADIOS_INC:= /home/wgodoy/workspace/ADIOSPP/include +ADIOS_LIB:= /home/wgodoy/workspace/ADIOSPP/lib ADIOSPy_INC:=./include CFLAGS:=-c -Wall -fPIC -O0 -g -std=c++11 diff --git a/bindings/python/include/ADIOSPy.h b/bindings/python/include/ADIOSPy.h index ad802f4fff503f49b5486c8b27903356417d6a5b..575bd1e1c509a800575a6e6d51c12637fca51e2f 100644 --- a/bindings/python/include/ADIOSPy.h +++ b/bindings/python/include/ADIOSPy.h @@ -14,6 +14,7 @@ #include "ADIOS.h" #include "adiosPyFunctions.h" //ListToVector, VectorToList +#include "VariablePy.h" namespace adios @@ -30,7 +31,7 @@ public: void HelloMPI( ); ///< says hello from rank/size for testing - std::string DefineVariableDouble( const std::string name, + 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() ); @@ -42,7 +43,7 @@ public: void SetVariableLocalDimensions( const std::string name, const boost::python::list list ); - boost::python::list GetVariableLocalDimensions( const std::string name ); + std::vector<std::size_t> GetVariableLocalDimensions( const std::string name ); private: diff --git a/bindings/python/include/VariablePy.h b/bindings/python/include/VariablePy.h new file mode 100644 index 0000000000000000000000000000000000000000..f43619f7db49ed7c3eb19746ff6a6243df972e65 --- /dev/null +++ b/bindings/python/include/VariablePy.h @@ -0,0 +1,51 @@ +/* + * VariablePy.h + * + * Created on: Mar 13, 2017 + * Author: wgodoy + */ + +#ifndef VARIABLEPY_H_ +#define VARIABLEPY_H_ + +#include "core/Variable.h" +#include "adiosPyFunctions.h" + +namespace adios +{ + +template< class T> +class VariablePy : public Variable<T> +{ + +public: + + VariablePy<T>( const std::string name, const Dims dimensions, const Dims globalDimensions, const Dims globalOffsets, + const bool debugMode ): + Variable<T>( name, dimensions, globalDimensions, globalOffsets, debugMode ) + { } + + ~VariablePy( ) + { } + + void SetLocalDimensions( const boost::python::list list ) + { + this->m_Dimensions = ListToVector( list ); + } + + std::vector<std::size_t> GetLocalDimensions( ) + { + return this->m_Dimensions; + } + +}; + + + + +} + + + + +#endif /* BINDINGS_PYTHON_INCLUDE_VARIABLEPY_H_ */ diff --git a/bindings/python/src/ADIOSPy.cpp b/bindings/python/src/ADIOSPy.cpp index 9b3845f213c0e1ae0768038abf80394d45661014..13be730eea7b0f6695ced146c3afb00f0bb8a9da 100644 --- a/bindings/python/src/ADIOSPy.cpp +++ b/bindings/python/src/ADIOSPy.cpp @@ -35,10 +35,13 @@ std::string ADIOSPy::DefineVariableFloat( const std::string name, const boost::p } -std::string ADIOSPy::DefineVariableDouble( const std::string name, const boost::python::list localDimensionsPy, - const boost::python::list globalDimensionsPy, const boost::python::list globalOffsetsPy ) +VariablePy<double>& ADIOSPy::DefineVariableDouble( const std::string name, const boost::python::list localDimensionsPy, + const boost::python::list globalDimensionsPy, const boost::python::list globalOffsetsPy ) { - return DefineVariablePy<double>( name, localDimensionsPy, globalDimensionsPy, globalOffsetsPy ); + + Variable<double>& var = DefineVariable<double>( name, ListToVector( localDimensionsPy ), ListToVector( globalDimensionsPy ), ListToVector( globalOffsetsPy ) ); + VariablePy<double>& varPy = *reinterpret_cast<VariablePy<double>*>( &var ); + return varPy; } @@ -100,7 +103,8 @@ void ADIOSPy::SetVariableLocalDimensions( const std::string name, const boost::p } -boost::python::list ADIOSPy::GetVariableLocalDimensions( const std::string name ) +//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" ); @@ -157,8 +161,8 @@ boost::python::list ADIOSPy::GetVariableLocalDimensions( const std::string name else if( type == GetType<std::complex<long double>>() ) dims = GetVariable<std::complex<long double>>( name ).m_Dimensions; - //return dims; - return VectorToList( dims ); + return dims; + //return VectorToList( dims ); } diff --git a/bindings/python/src/glue.cpp b/bindings/python/src/glue.cpp index 93ebb9434939628f0e1aa52389e9501a2b44b3aa..499e1dcf9f4a2a81357480c33dcbec3634d616bd 100644 --- a/bindings/python/src/glue.cpp +++ b/bindings/python/src/glue.cpp @@ -38,11 +38,18 @@ BOOST_PYTHON_MODULE( ADIOSPy ) //classes boost::python::class_<adios::ADIOSPy>("ADIOS", boost::python::no_init ) .def("HelloMPI", &adios::ADIOSPy::HelloMPI ) - .def("DefineVariableDouble", &adios::ADIOSPy::DefineVariableDouble, d_overloads() ) + .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 ) ; + //classes + boost::python::class_<adios::VariablePy<double>>("VariableDouble", boost::python::no_init ) + .def("SetLocalDimensions", &adios::VariablePy<double>::SetLocalDimensions ) + .def("GetLocalDimensions", &adios::VariablePy<double>::GetLocalDimensions ) + ; + } diff --git a/bindings/python/test_hello.py b/bindings/python/test_hello.py index 0b9cd13ce75637e645124119e9626941b0642d1c..b6cdf9cc8c87200c565df0bc3601edfeccb532b5 100644 --- a/bindings/python/test_hello.py +++ b/bindings/python/test_hello.py @@ -11,24 +11,30 @@ adios.HelloMPI( ) lDims = [10, 11, 12] Nx = 1 -print lDims -print lDims[0] -ioMyDoubles = adios.DefineVariableDouble( "ioMyDoubles", lDims ) -ioMyFloats = adios.DefineVariableFloat( "ioMyFloats", [Nx] ) +ioMyDoubles = adios.DefineVariableDouble( "ioMyDoubles", lDims, [], [] ) -print "My ADIOS Variable Double " + ioMyDoubles -print "My ADIOS Variable Float " + ioMyFloats +dims = ioMyDoubles.GetLocalDimensions( ) +print "Old Dimensions" +for dim in dims: + print dim -dims = adios.GetVariableLocalDimensions( ioMyDoubles ) -print "Old Dimensions " -print dims +ioMyDoubles.SetLocalDimensions( [20,20,20] ) -lDims = [20,20,20] -adios.SetVariableLocalDimensions( ioMyDoubles, lDims ) - -dims = adios.GetVariableLocalDimensions( ioMyDoubles ) +dims = ioMyDoubles.GetLocalDimensions( ) print "New Dimensions " -print dims +for dim in dims: + print dim + + +# 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( )