diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index 2aa4e17f6d8e1032beda661c90de6f657bde796e..1299ac39495e9edbbaee9f5f877a15e9253fa718 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -1,6 +1,3 @@ if(ADIOS_USE_Python) - if(NOT BUILD_SHARED_LIBS) - message(ERROR "Python bindings are only supported for shared libraries") - endif() add_subdirectory(python) endif() diff --git a/bindings/python/ADIOSPy.cpp b/bindings/python/ADIOSPy.cpp index 6cdf457b0c517551161a954910f5f0e9a621d722..2e16a24fcdf71194cb40b8a3e26ae27f29a060fd 100644 --- a/bindings/python/ADIOSPy.cpp +++ b/bindings/python/ADIOSPy.cpp @@ -20,7 +20,11 @@ ADIOSPy::ADIOSPy(MPI_Comm mpiComm, const bool debug) { } -ADIOSPy::ADIOSPy(const bool debug) : ADIOSPy(MPI_COMM_SELF, debug) {} +ADIOSPy::ADIOSPy(const bool debug) +: m_DebugMode(debug), m_ADIOS(debug) +{ +} + IOPy ADIOSPy::DeclareIO(const std::string name) { diff --git a/bindings/python/ADIOSPy.h b/bindings/python/ADIOSPy.h index d8c7d22818213c1638f1c33d3fb1da82e4d7d35e..d8cc68c9e453ebd5d840c07b369c75e3cf98107a 100644 --- a/bindings/python/ADIOSPy.h +++ b/bindings/python/ADIOSPy.h @@ -15,6 +15,8 @@ #include <string> /// \endcond +#include <adios2.h> + #include "IOPy.h" namespace adios diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 1c0627fb0d0eb97f941dfefc2cca774684f4894f..491ca271484f398fd2c22cd3ee2959c8ca9ada7d 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -1,5 +1,6 @@ -find_package(PythonInterp REQUIRED) -find_package(PythonModule REQUIRED COMPONENTS mpi4py mpi4py/mpi4py.h) +if(NOT BUILD_SHARED_LIBS) + message(ERROR "Python bindings are only supported for shared libraries") +endif() pybind11_add_module(adios2py MODULE ADIOSPy.h @@ -16,12 +17,18 @@ pybind11_add_module(adios2py MODULE VariablePy.h VariablePy.cpp ) -target_link_libraries(adios2py PUBLIC adios2 PythonModule::mpi4py) +target_link_libraries(adios2py PRIVATE adios2) +if(ADIOS_USE_MPI) + find_package(PythonModule REQUIRED COMPONENTS mpi4py mpi4py/mpi4py.h) + target_link_libraries(adios2py PRIVATE PythonModule::mpi4py) +endif() +find_package(PythonInterp REQUIRED) set(python_package_dir ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}/site-packages) set_target_properties(adios2py PROPERTIES - PREFIX "" OUTPUT_NAME adios2 + PREFIX "${PYTHON_MODULE_PREFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}" LIBRARY_OUTPUT_DIRECTORY ${ADIOS_BINARY_DIR}/${python_package_dir} RUNTIME_OUTPUT_DIRECTORY ${ADIOS_BINARY_DIR}/${python_package_dir} ) diff --git a/bindings/python/gluePyBind11.cpp b/bindings/python/gluePyBind11.cpp index c7fff7f6a6f23b75bf7533b6f166daf2ac91e616..6a22c6529ff963886a88885bed1f6a6392c43736 100644 --- a/bindings/python/gluePyBind11.cpp +++ b/bindings/python/gluePyBind11.cpp @@ -11,9 +11,12 @@ #include <stdexcept> #include <adios2.h> -#include <mpi4py/mpi4py.h> #include <pybind11/pybind11.h> +#ifdef ADIOS2_HAVE_MPI +#include <mpi4py/mpi4py.h> +#endif + #include "ADIOSPy.h" #include "EnginePy.h" #include "IOPy.h" @@ -21,6 +24,7 @@ #include "adiosPyFunctions.h" #include "adiosPyTypes.h" +#ifdef ADIOS2_HAVE_MPI adios::ADIOSPy ADIOSPyInit(adios::pyObject &object, const bool debugMode) { MPI_Comm *mpiCommPtr = PyMPIComm_Get(object.ptr()); @@ -39,14 +43,22 @@ adios::ADIOSPy ADIOSPyInit(adios::pyObject &object, const bool debugMode) } return adios::ADIOSPy(*mpiCommPtr, debugMode); } +#else +adios::ADIOSPy ADIOSPyInit(const bool debugMode) +{ + return adios::ADIOSPy(debugMode); +} +#endif PYBIND11_PLUGIN(adios2) { +#ifdef ADIOS2_HAVE_MPI if (import_mpi4py() < 0) { throw std::runtime_error( "ERROR: mpi4py not loaded correctly\n"); /* Python 2.X */ } +#endif pybind11::module m("adios2", "ADIOS2 Python bindings using pybind11"); m.attr("DebugON") = true; @@ -73,10 +85,6 @@ PYBIND11_PLUGIN(adios2) pybind11::arg("isConstantDims") = false) .def("GetVariable", &adios::IOPy::GetVariable, pybind11::return_value_policy::reference_internal) - // .def("Open", (adios::EnginePy (adios::IOPy::*)( - // const std::string &, const int, - // adios::pyObject &)) & - // adios::IOPy::Open) doesn't work .def("Open", (adios::EnginePy (adios::IOPy::*)(const std::string &, const int)) & adios::IOPy::Open); diff --git a/bindings/python/gluePyBind11_nompi.cpp b/bindings/python/gluePyBind11_nompi.cpp deleted file mode 100644 index a519a441c8ec2df7dd065aa025a865d9623e503e..0000000000000000000000000000000000000000 --- a/bindings/python/gluePyBind11_nompi.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Distributed under the OSI-approved Apache License, Version 2.0. See - * accompanying file Copyright.txt for details. - * - * gluePyBind11_nompi.cpp - * - * Created on: Jun 12, 2017 - * Author: William F Godoy godoywf@ornl.gov - */ - -#include <stdexcept> - -#include <adios2.h> -#include <pybind11/pybind11.h> - -#include "ADIOSPy.h" -#include "EnginePy.h" -#include "IOPy.h" -#include "VariablePy.h" -#include "adiosPyFunctions.h" -#include "adiosPyTypes.h" - -adios::ADIOSPy ADIOSPyInit(const bool debugMode) -{ - return adios::ADIOSPy(debugMode); -} - -PYBIND11_PLUGIN(adios2) -{ - pybind11::module m("adios2", "ADIOS2 Python bindings using pybind11"); - m.attr("DebugON") = true; - m.attr("DebugOFF") = false; - m.attr("ConstantDims") = true; - m.attr("OpenModeWrite") = static_cast<int>(adios::OpenMode::Write); - m.attr("OpenModeRead") = static_cast<int>(adios::OpenMode::Read); - m.attr("OpenModeAppend") = static_cast<int>(adios::OpenMode::Append); - m.attr("OpenModeReadWrite") = static_cast<int>(adios::OpenMode::ReadWrite); - m.def("ADIOS", &ADIOSPyInit, "Function that creates an ADIOS class object"); - - pybind11::class_<adios::ADIOSPy>(m, "ADIOSPy") - .def("DeclareIO", &adios::ADIOSPy::DeclareIO); - - pybind11::class_<adios::IOPy>(m, "IOPy") - .def("SetEngine", &adios::IOPy::SetEngine) - .def("SetParameters", &adios::IOPy::SetParameters) - .def("AddTransport", &adios::IOPy::AddTransport) - .def("DefineVariable", &adios::IOPy::DefineVariable, - pybind11::return_value_policy::reference_internal, - pybind11::arg("name"), pybind11::arg("shape") = adios::pyList(), - pybind11::arg("start") = adios::pyList(), - pybind11::arg("count") = adios::pyList(), - pybind11::arg("isConstantDims") = false) - .def("GetVariable", &adios::IOPy::GetVariable, - pybind11::return_value_policy::reference_internal) - .def("Open", (adios::EnginePy (adios::IOPy::*)(const std::string &, - const int)) & - adios::IOPy::Open); - - pybind11::class_<adios::VariablePy>(m, "VariablePy") - .def("SetDimensions", &adios::VariablePy::SetDimensions); - - pybind11::class_<adios::EnginePy>(m, "EnginePy") - .def("Write", &adios::EnginePy::Write) - .def("Advance", &adios::EnginePy::Advance, - pybind11::arg("timeoutSeconds") = 0.) - .def("Close", &adios::EnginePy::Close, - pybind11::arg("transportIndex") = -1); - - return m.ptr(); -}