Skip to content
Snippets Groups Projects
Commit c2720f30 authored by William F Godoy's avatar William F Godoy
Browse files

Functional Python bindings MPI and nonMPI modes

Removed stl containers that pybind11 takes care of
parent 1bb6cd30
No related branches found
No related tags found
1 merge request!294Bp1read : Initial Reading Capabilities and latest API
...@@ -30,7 +30,7 @@ void EnginePy::PutSync(VariableBase *variable, const pybind11::array &array) ...@@ -30,7 +30,7 @@ void EnginePy::PutSync(VariableBase *variable, const pybind11::array &array)
{ {
auto &io = m_Engine.GetIO(); auto &io = m_Engine.GetIO();
if (array == pybind11::array()) if (array.is(pybind11::array()))
{ {
if (m_DebugMode) if (m_DebugMode)
{ {
...@@ -60,7 +60,7 @@ void EnginePy::PutSync(VariableBase *variable, const pybind11::array &array) ...@@ -60,7 +60,7 @@ void EnginePy::PutSync(VariableBase *variable, const pybind11::array &array)
#define declare_type(T) \ #define declare_type(T) \
else if (variable->m_Type == GetType<T>()) \ else if (variable->m_Type == GetType<T>()) \
{ \ { \
m_Engine.PutSync(dynamic_cast<adios2::Variable<T> &>(variable), \ m_Engine.PutSync(*dynamic_cast<adios2::Variable<T> *>(variable), \
reinterpret_cast<const T *>(array.data())); \ reinterpret_cast<const T *>(array.data())); \
} }
ADIOS2_FOREACH_TYPE_1ARG(declare_type) ADIOS2_FOREACH_TYPE_1ARG(declare_type)
...@@ -69,7 +69,7 @@ void EnginePy::PutSync(VariableBase *variable, const pybind11::array &array) ...@@ -69,7 +69,7 @@ void EnginePy::PutSync(VariableBase *variable, const pybind11::array &array)
{ {
if (m_DebugMode) if (m_DebugMode)
{ {
throw std::invalid_argument("ERROR: variable " + variable.m_Name + throw std::invalid_argument("ERROR: variable " + variable->m_Name +
" numpy array type is not supported or " " numpy array type is not supported or "
"is not memory contiguous " "is not memory contiguous "
", in call to PutSync\n"); ", in call to PutSync\n");
......
...@@ -42,7 +42,7 @@ VariableBase &IOPy::DefineVariable(const std::string &name, const Dims &shape, ...@@ -42,7 +42,7 @@ VariableBase &IOPy::DefineVariable(const std::string &name, const Dims &shape,
VariableBase *variable = nullptr; VariableBase *variable = nullptr;
if (array == pybind11::array()) if (array.is(pybind11::array()))
{ {
// put in placeholder // put in placeholder
auto itVariableEmplace = m_VariablesPlaceholder.emplace( auto itVariableEmplace = m_VariablesPlaceholder.emplace(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <adios2.h> #include <adios2.h>
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#ifdef ADIOS2_HAVE_MPI #ifdef ADIOS2_HAVE_MPI
#include <mpi4py/mpi4py.h> #include <mpi4py/mpi4py.h>
...@@ -74,7 +75,7 @@ adios2::ADIOSPy ADIOSPyInit(const bool debugMode) ...@@ -74,7 +75,7 @@ adios2::ADIOSPy ADIOSPyInit(const bool debugMode)
} }
#endif #endif
PYBIND11_PLUGIN(adios2) PYBIND11_MODULE(adios2, m)
{ {
#ifdef ADIOS2_HAVE_MPI #ifdef ADIOS2_HAVE_MPI
if (import_mpi4py() < 0) if (import_mpi4py() < 0)
...@@ -84,7 +85,9 @@ PYBIND11_PLUGIN(adios2) ...@@ -84,7 +85,9 @@ PYBIND11_PLUGIN(adios2)
} }
#endif #endif
pybind11::module m("adios2", "ADIOS2 Python bindings using pybind11"); // pybind11::module m("adios2", "ADIOS2 Python bindings using pybind11");
m.doc() = "ADIOS2 Python bindings powered by pybind11";
m.attr("DebugON") = true; m.attr("DebugON") = true;
m.attr("DebugOFF") = false; m.attr("DebugOFF") = false;
m.attr("ConstantDims") = true; m.attr("ConstantDims") = true;
...@@ -108,10 +111,24 @@ PYBIND11_PLUGIN(adios2) ...@@ -108,10 +111,24 @@ PYBIND11_PLUGIN(adios2)
.value("EndOfStream", adios2::StepStatus::EndOfStream) .value("EndOfStream", adios2::StepStatus::EndOfStream)
.value("OtherError", adios2::StepStatus::OtherError) .value("OtherError", adios2::StepStatus::OtherError)
.export_values(); .export_values();
#ifdef ADIOS2_HAVE_MPI
m.def("ADIOS", &ADIOSPyInit, "Function that creates an ADIOS class object",
pybind11::arg("object") = nullptr, pybind11::arg("debugMode") = true);
m.def("ADIOS", &ADIOSPyInitConfig, "Function that creates an ADIOS class "
"object using a config file",
pybind11::arg("configFile") = "", pybind11::arg("object") = nullptr,
pybind11::arg("debugMode") = true);
#else
m.def("ADIOS", &ADIOSPyInit,
"Function that creates an ADIOS class object in non MPI mode",
pybind11::arg("debugMode") = true);
m.def("ADIOS", &ADIOSPyInit, "Function that creates an ADIOS class object");
m.def("ADIOS", &ADIOSPyInitConfig, m.def("ADIOS", &ADIOSPyInitConfig,
"Function that creates an ADIOS class object using a config file"); "Function that creates an ADIOS class "
"object using a config file in non MPI mode",
pybind11::arg("configFile") = "", pybind11::arg("debugMode") = true);
#endif
pybind11::class_<adios2::ADIOSPy>(m, "ADIOSPy") pybind11::class_<adios2::ADIOSPy>(m, "ADIOSPy")
.def("DeclareIO", &adios2::ADIOSPy::DeclareIO); .def("DeclareIO", &adios2::ADIOSPy::DeclareIO);
...@@ -141,6 +158,4 @@ PYBIND11_PLUGIN(adios2) ...@@ -141,6 +158,4 @@ PYBIND11_PLUGIN(adios2)
.def("EndStep", &adios2::EnginePy::EndStep) .def("EndStep", &adios2::EnginePy::EndStep)
.def("Close", &adios2::EnginePy::Close, .def("Close", &adios2::EnginePy::Close,
pybind11::arg("transportIndex") = -1); pybind11::arg("transportIndex") = -1);
return m.ptr();
} }
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
# Distributed under the OSI-approved Apache License, Version 2.0. See # Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details. # accompanying file Copyright.txt for details.
# #
# helloBPWriter.py # helloBPWriter_nompi.py : only works with non MPI version
# Created on: Feb 2, 2017 # Created on: Feb 2, 2017
# Author: William F Godoy godoywf@ornl.gov # Author: William F Godoy godoywf@ornl.gov
from mpi4py import MPI from mpi4py import MPI
import numpy import numpy
import adios2 import adios2
...@@ -30,7 +29,6 @@ ioArray = bpIO.DefineVariable( ...@@ -30,7 +29,6 @@ ioArray = bpIO.DefineVariable(
"bpArray", [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims) "bpArray", [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims)
# ADIOS Engine # ADIOS Engine
bpFileWriter = bpIO.Open("npArray.bp", adios2.OpenModeWrite) bpFileWriter = bpIO.Open("npArray.bp", adios2.Mode.Write)
# doesn't work: bpFileWriter = bpIO.Open("npArray.bp", adios2.OpenModeWrite, newcomm)
bpFileWriter.PutSync(ioArray, myArray) bpFileWriter.PutSync(ioArray, myArray)
bpFileWriter.Close() bpFileWriter.Close()
#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#
# helloBPWriter.py : only works with MPI version
# Created on: Feb 2, 2017
# Author: William F Godoy godoywf@ornl.gov
import numpy
import adios2
# User data
myArray = numpy.array([0, 1., 2., 3., 4., 5., 6., 7., 8., 9.])
Nx = myArray.size
# debug mode
adios = adios2.ADIOS(adios2.DebugON)
# ADIOS IO
bpIO = adios.DeclareIO("BPFile_N2N")
# ADIOS Variable name, shape, start, offset, constant dims
ioArray = bpIO.DefineVariable(
"bpArray", [], [], [Nx], adios2.ConstantDims)
# ADIOS Engine
bpFileWriter = bpIO.Open("npArray.bp", adios2.Mode.Write)
bpFileWriter.PutSync(ioArray, myArray)
bpFileWriter.Close()
...@@ -18,7 +18,7 @@ import adios2 ...@@ -18,7 +18,7 @@ import adios2
data = SmallTestData() data = SmallTestData()
comm = MPI.COMM_WORLD comm = MPI.COMM_WORLD
adios = adios2.ADIOS(comm, adios2.DebugON) adios = adios2.ADIOS(comm)
bpIO = adios.DeclareIO("NPTypes") bpIO = adios.DeclareIO("NPTypes")
...@@ -50,19 +50,19 @@ varR64 = bpIO.DefineVariable( ...@@ -50,19 +50,19 @@ varR64 = bpIO.DefineVariable(
# ADIOS Engine # ADIOS Engine
bpFileWriter = bpIO.Open("npTypes.bp", adios2.ModeWrite) bpFileWriter = bpIO.Open("npTypes.bp", adios2.Mode.Write)
bpFileWriter.Write(varI8, data.I8) bpFileWriter.PutSync(varI8, data.I8)
bpFileWriter.Write(varI16, data.I16) bpFileWriter.PutSync(varI16, data.I16)
bpFileWriter.Write(varI32, data.I32) bpFileWriter.PutSync(varI32, data.I32)
bpFileWriter.Write(varI64, data.I64) bpFileWriter.PutSync(varI64, data.I64)
bpFileWriter.Write(varU8, data.U8) bpFileWriter.PutSync(varU8, data.U8)
bpFileWriter.Write(varU16, data.U16) bpFileWriter.PutSync(varU16, data.U16)
bpFileWriter.Write(varU32, data.U32) bpFileWriter.PutSync(varU32, data.U32)
bpFileWriter.Write(varU64, data.U64) bpFileWriter.PutSync(varU64, data.U64)
bpFileWriter.Write(varR32, data.R32) bpFileWriter.PutSync(varR32, data.R32)
bpFileWriter.Write(varR64, data.R64) bpFileWriter.PutSync(varR64, data.R64)
bpFileWriter.Close() bpFileWriter.Close()
...@@ -48,19 +48,19 @@ varR64 = bpIO.DefineVariable( ...@@ -48,19 +48,19 @@ varR64 = bpIO.DefineVariable(
# ADIOS Engine # ADIOS Engine
bpFileWriter = bpIO.Open("npTypes.bp", adios2.ModeWrite) bpFileWriter = bpIO.Open("npTypes.bp", adios2.Mode.Write)
bpFileWriter.Write(varI8, data.I8) bpFileWriter.PutSync(varI8, data.I8)
bpFileWriter.Write(varI16, data.I16) bpFileWriter.PutSync(varI16, data.I16)
bpFileWriter.Write(varI32, data.I32) bpFileWriter.PutSync(varI32, data.I32)
bpFileWriter.Write(varI64, data.I64) bpFileWriter.PutSync(varI64, data.I64)
bpFileWriter.Write(varU8, data.U8) bpFileWriter.PutSync(varU8, data.U8)
bpFileWriter.Write(varU16, data.U16) bpFileWriter.PutSync(varU16, data.U16)
bpFileWriter.Write(varU32, data.U32) bpFileWriter.PutSync(varU32, data.U32)
bpFileWriter.Write(varU64, data.U64) bpFileWriter.PutSync(varU64, data.U64)
bpFileWriter.Write(varR32, data.R32) bpFileWriter.PutSync(varR32, data.R32)
bpFileWriter.Write(varR64, data.R64) bpFileWriter.PutSync(varR64, data.R64)
bpFileWriter.Close() bpFileWriter.Close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment