Loading bindings/Python/CMakeLists.txt +3 −0 Original line number Diff line number Diff line pybind11_add_module(adios2py MODULE py11ADIOS.cpp py11IO.cpp py11Variable.cpp py11Attribute.cpp py11Engine.cpp py11Operator.cpp py11File.cpp py11glue.cpp ) Loading bindings/Python/py11ADIOS.cpp +41 −8 Original line number Diff line number Diff line Loading @@ -18,10 +18,10 @@ namespace py11 { #ifdef ADIOS2_HAVE_MPI ADIOS::ADIOS(const std::string configFile, MPI_Comm mpiComm, ADIOS::ADIOS(const std::string &configFile, MPI_Comm mpiComm, const bool debugMode) : m_DebugMode(debugMode), m_ADIOS(std::make_shared<adios2::core::ADIOS>( configFile, mpiComm, debugMode, "Python")) : m_ADIOS(std::make_shared<adios2::core::ADIOS>(configFile, mpiComm, debugMode, "Python")) { } Loading @@ -30,8 +30,9 @@ ADIOS::ADIOS(MPI_Comm mpiComm, const bool debugMode) { } #else ADIOS::ADIOS(const std::string configFile, const bool debugMode) : ADIOS(configFile, debugMode) ADIOS::ADIOS(const std::string &configFile, const bool debugMode) : m_ADIOS( std::make_shared<adios2::core::ADIOS>(configFile, debugMode, "Python")) { } Loading @@ -42,15 +43,47 @@ ADIOS::operator bool() const noexcept { return m_ADIOS ? true : false; } IO ADIOS::DeclareIO(const std::string name) { return IO(m_ADIOS->DeclareIO(name), m_DebugMode); CheckPointer("for io name " + name + ", in call to ADIOS::DeclareIO"); return IO(&m_ADIOS->DeclareIO(name)); } IO ADIOS::AtIO(const std::string name) { return IO(m_ADIOS->AtIO(name), m_DebugMode); CheckPointer("for io name " + name + ", in call to ADIOS::AtIO"); return IO(&m_ADIOS->AtIO(name)); } void ADIOS::FlushAll() { m_ADIOS->FlushAll(); } Operator ADIOS::DefineOperator(const std::string name, const std::string type, const Params ¶meters) { CheckPointer("for operator name " + name + ", in call to ADIOS::DefineOperator"); return Operator(&m_ADIOS->DefineOperator(name, type, parameters)); } Operator ADIOS::InquireOperator(const std::string name) { CheckPointer("for operator name " + name + ", in call to InquireOperator"); return Operator(m_ADIOS->InquireOperator(name)); } void ADIOS::FlushAll() { CheckPointer("in call to ADIOS::FlushAll"); m_ADIOS->FlushAll(); } // PRIVATE void ADIOS::CheckPointer(const std::string hint) { if (!m_ADIOS) { throw std::invalid_argument("ERROR: invalid ADIOS object, did you call " "any of the ADIOS explicit " "constructors?, " + hint + "\n"); } } } // end namespace py11 } // end namespace adios2 bindings/Python/py11ADIOS.h +12 −4 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #define ADIOS2_BINDINGS_PYTHON_ADIOS_H_ #include "py11IO.h" #include "py11Operator.h" #include <memory> //std::shared_ptr #include <string> Loading @@ -29,10 +30,11 @@ class ADIOS public: #ifdef ADIOS2_HAVE_MPI ADIOS(const std::string configFile, MPI_Comm mpiComm, const bool debugMode); ADIOS(MPI_Comm mpiComm, const bool debugMode); ADIOS(const std::string &configFile, MPI_Comm comm, const bool debugMode = true); ADIOS(MPI_Comm comm, const bool debugMode = true); #else ADIOS(const std::string configFile, const bool debugMode); ADIOS(const std::string &configFile, const bool debugMode = true); ADIOS(const bool debugMode); #endif ~ADIOS() = default; Loading @@ -43,11 +45,17 @@ public: IO DeclareIO(const std::string name); IO AtIO(const std::string name); Operator DefineOperator(const std::string name, const std::string type, const Params ¶meters = Params()); Operator InquireOperator(const std::string name); void FlushAll(); private: const bool m_DebugMode = true; std::shared_ptr<adios2::core::ADIOS> m_ADIOS; void CheckPointer(const std::string hint); }; } // end namespace py11 Loading bindings/Python/py11Attribute.cpp +33 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ */ #include "py11Attribute.h" #include "py11types.h" #include <string.h> //std::memcpy #include "adios2/helper/adiosFunctions.h" Loading Loading @@ -39,8 +42,36 @@ std::string Attribute::Type() const pybind11::array Attribute::Data() { helper::CheckForNullptr(m_Attribute, "in call to Attribute::Data"); // TODO return m_Attribute->m_Name; const std::string type = m_Attribute->m_Type; if (type == "compound") { // not supported } #define declare_type(T) \ else if (type == helper::GetType<T>()) \ { \ pybind11::array pyArray(pybind11::dtype::of<T>(), \ m_Attribute->m_Elements); \ if (m_Attribute->m_IsSingleValue) \ { \ const T value = dynamic_cast<core::Attribute<T> *>(m_Attribute) \ ->m_DataSingleValue; \ std::memcpy(const_cast<void *>(pyArray.data()), &value, \ sizeof(T)); \ } \ else \ { \ const std::vector<T> &values = \ dynamic_cast<core::Attribute<T> *>(m_Attribute)->m_DataArray; \ std::memcpy(const_cast<void *>(pyArray.data()), values.data(), \ sizeof(T) * m_Attribute->m_Elements); \ } \ return pyArray; \ } ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(declare_type) #undef declare_type return pybind11::array(); } } // end namespace py11 Loading bindings/Python/py11Engine.cpp +17 −29 Original line number Diff line number Diff line Loading @@ -21,10 +21,7 @@ namespace adios2 namespace py11 { Engine::Engine(core::Engine *engine, const bool debugMode) : m_Engine(engine), m_DebugMode(debugMode) { } Engine::Engine(core::Engine *engine) : m_Engine(engine) {} Engine::operator bool() const noexcept { Loading Loading @@ -71,16 +68,12 @@ void Engine::Put(Variable variable, const pybind11::array &array, #undef declare_type else { if (m_DebugMode) { throw std::invalid_argument("ERROR: for variable " + variable.Name() + throw std::invalid_argument("ERROR: for variable " + variable.Name() + " numpy array type is not supported or " "is not memory contiguous " ", in call to Put\n"); } } } void Engine::Put(Variable variable, const std::string &string) { Loading @@ -96,7 +89,8 @@ void Engine::Put(Variable variable, const std::string &string) " is not of string type, in call to Engine::Put"); } m_Engine->Put(*dynamic_cast<core::Variable<std::string> *>(variable), m_Engine->Put( *dynamic_cast<core::Variable<std::string> *>(variable.m_Variable), string); } Loading Loading @@ -131,8 +125,6 @@ void Engine::Get(Variable variable, pybind11::array &array, const Mode launch) ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type else { if (m_DebugMode) { throw std::invalid_argument( "ERROR: in variable " + variable.Name() + " of type " + Loading @@ -142,7 +134,6 @@ void Engine::Get(Variable variable, pybind11::array &array, const Mode launch) ", in call to Get\n"); } } } void Engine::Get(Variable variable, std::string &string, const Mode launch) { Loading @@ -162,12 +153,9 @@ void Engine::Get(Variable variable, std::string &string, const Mode launch) } else { if (m_DebugMode) { throw std::invalid_argument( "ERROR: variable " + variable.Name() + " of type " + variable.Type() + " is not string, in call to Engine::Get"); } throw std::invalid_argument("ERROR: variable " + variable.Name() + " of type " + variable.Type() + " is not string, in call to Engine::Get"); } } Loading Loading
bindings/Python/CMakeLists.txt +3 −0 Original line number Diff line number Diff line pybind11_add_module(adios2py MODULE py11ADIOS.cpp py11IO.cpp py11Variable.cpp py11Attribute.cpp py11Engine.cpp py11Operator.cpp py11File.cpp py11glue.cpp ) Loading
bindings/Python/py11ADIOS.cpp +41 −8 Original line number Diff line number Diff line Loading @@ -18,10 +18,10 @@ namespace py11 { #ifdef ADIOS2_HAVE_MPI ADIOS::ADIOS(const std::string configFile, MPI_Comm mpiComm, ADIOS::ADIOS(const std::string &configFile, MPI_Comm mpiComm, const bool debugMode) : m_DebugMode(debugMode), m_ADIOS(std::make_shared<adios2::core::ADIOS>( configFile, mpiComm, debugMode, "Python")) : m_ADIOS(std::make_shared<adios2::core::ADIOS>(configFile, mpiComm, debugMode, "Python")) { } Loading @@ -30,8 +30,9 @@ ADIOS::ADIOS(MPI_Comm mpiComm, const bool debugMode) { } #else ADIOS::ADIOS(const std::string configFile, const bool debugMode) : ADIOS(configFile, debugMode) ADIOS::ADIOS(const std::string &configFile, const bool debugMode) : m_ADIOS( std::make_shared<adios2::core::ADIOS>(configFile, debugMode, "Python")) { } Loading @@ -42,15 +43,47 @@ ADIOS::operator bool() const noexcept { return m_ADIOS ? true : false; } IO ADIOS::DeclareIO(const std::string name) { return IO(m_ADIOS->DeclareIO(name), m_DebugMode); CheckPointer("for io name " + name + ", in call to ADIOS::DeclareIO"); return IO(&m_ADIOS->DeclareIO(name)); } IO ADIOS::AtIO(const std::string name) { return IO(m_ADIOS->AtIO(name), m_DebugMode); CheckPointer("for io name " + name + ", in call to ADIOS::AtIO"); return IO(&m_ADIOS->AtIO(name)); } void ADIOS::FlushAll() { m_ADIOS->FlushAll(); } Operator ADIOS::DefineOperator(const std::string name, const std::string type, const Params ¶meters) { CheckPointer("for operator name " + name + ", in call to ADIOS::DefineOperator"); return Operator(&m_ADIOS->DefineOperator(name, type, parameters)); } Operator ADIOS::InquireOperator(const std::string name) { CheckPointer("for operator name " + name + ", in call to InquireOperator"); return Operator(m_ADIOS->InquireOperator(name)); } void ADIOS::FlushAll() { CheckPointer("in call to ADIOS::FlushAll"); m_ADIOS->FlushAll(); } // PRIVATE void ADIOS::CheckPointer(const std::string hint) { if (!m_ADIOS) { throw std::invalid_argument("ERROR: invalid ADIOS object, did you call " "any of the ADIOS explicit " "constructors?, " + hint + "\n"); } } } // end namespace py11 } // end namespace adios2
bindings/Python/py11ADIOS.h +12 −4 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ #define ADIOS2_BINDINGS_PYTHON_ADIOS_H_ #include "py11IO.h" #include "py11Operator.h" #include <memory> //std::shared_ptr #include <string> Loading @@ -29,10 +30,11 @@ class ADIOS public: #ifdef ADIOS2_HAVE_MPI ADIOS(const std::string configFile, MPI_Comm mpiComm, const bool debugMode); ADIOS(MPI_Comm mpiComm, const bool debugMode); ADIOS(const std::string &configFile, MPI_Comm comm, const bool debugMode = true); ADIOS(MPI_Comm comm, const bool debugMode = true); #else ADIOS(const std::string configFile, const bool debugMode); ADIOS(const std::string &configFile, const bool debugMode = true); ADIOS(const bool debugMode); #endif ~ADIOS() = default; Loading @@ -43,11 +45,17 @@ public: IO DeclareIO(const std::string name); IO AtIO(const std::string name); Operator DefineOperator(const std::string name, const std::string type, const Params ¶meters = Params()); Operator InquireOperator(const std::string name); void FlushAll(); private: const bool m_DebugMode = true; std::shared_ptr<adios2::core::ADIOS> m_ADIOS; void CheckPointer(const std::string hint); }; } // end namespace py11 Loading
bindings/Python/py11Attribute.cpp +33 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ */ #include "py11Attribute.h" #include "py11types.h" #include <string.h> //std::memcpy #include "adios2/helper/adiosFunctions.h" Loading Loading @@ -39,8 +42,36 @@ std::string Attribute::Type() const pybind11::array Attribute::Data() { helper::CheckForNullptr(m_Attribute, "in call to Attribute::Data"); // TODO return m_Attribute->m_Name; const std::string type = m_Attribute->m_Type; if (type == "compound") { // not supported } #define declare_type(T) \ else if (type == helper::GetType<T>()) \ { \ pybind11::array pyArray(pybind11::dtype::of<T>(), \ m_Attribute->m_Elements); \ if (m_Attribute->m_IsSingleValue) \ { \ const T value = dynamic_cast<core::Attribute<T> *>(m_Attribute) \ ->m_DataSingleValue; \ std::memcpy(const_cast<void *>(pyArray.data()), &value, \ sizeof(T)); \ } \ else \ { \ const std::vector<T> &values = \ dynamic_cast<core::Attribute<T> *>(m_Attribute)->m_DataArray; \ std::memcpy(const_cast<void *>(pyArray.data()), values.data(), \ sizeof(T) * m_Attribute->m_Elements); \ } \ return pyArray; \ } ADIOS2_FOREACH_NUMPY_ATTRIBUTE_TYPE_1ARG(declare_type) #undef declare_type return pybind11::array(); } } // end namespace py11 Loading
bindings/Python/py11Engine.cpp +17 −29 Original line number Diff line number Diff line Loading @@ -21,10 +21,7 @@ namespace adios2 namespace py11 { Engine::Engine(core::Engine *engine, const bool debugMode) : m_Engine(engine), m_DebugMode(debugMode) { } Engine::Engine(core::Engine *engine) : m_Engine(engine) {} Engine::operator bool() const noexcept { Loading Loading @@ -71,16 +68,12 @@ void Engine::Put(Variable variable, const pybind11::array &array, #undef declare_type else { if (m_DebugMode) { throw std::invalid_argument("ERROR: for variable " + variable.Name() + throw std::invalid_argument("ERROR: for variable " + variable.Name() + " numpy array type is not supported or " "is not memory contiguous " ", in call to Put\n"); } } } void Engine::Put(Variable variable, const std::string &string) { Loading @@ -96,7 +89,8 @@ void Engine::Put(Variable variable, const std::string &string) " is not of string type, in call to Engine::Put"); } m_Engine->Put(*dynamic_cast<core::Variable<std::string> *>(variable), m_Engine->Put( *dynamic_cast<core::Variable<std::string> *>(variable.m_Variable), string); } Loading Loading @@ -131,8 +125,6 @@ void Engine::Get(Variable variable, pybind11::array &array, const Mode launch) ADIOS2_FOREACH_NUMPY_TYPE_1ARG(declare_type) #undef declare_type else { if (m_DebugMode) { throw std::invalid_argument( "ERROR: in variable " + variable.Name() + " of type " + Loading @@ -142,7 +134,6 @@ void Engine::Get(Variable variable, pybind11::array &array, const Mode launch) ", in call to Get\n"); } } } void Engine::Get(Variable variable, std::string &string, const Mode launch) { Loading @@ -162,12 +153,9 @@ void Engine::Get(Variable variable, std::string &string, const Mode launch) } else { if (m_DebugMode) { throw std::invalid_argument( "ERROR: variable " + variable.Name() + " of type " + variable.Type() + " is not string, in call to Engine::Get"); } throw std::invalid_argument("ERROR: variable " + variable.Name() + " of type " + variable.Type() + " is not string, in call to Engine::Get"); } } Loading