mirror of
https://github.com/boostorg/mpi.git
synced 2026-01-28 19:32:09 +00:00
Support for non-blocking MPI operations in Python, from Andreas Kloeckner
[SVN r43165]
This commit is contained in:
@@ -13,52 +13,90 @@
|
||||
*/
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/mpi.hpp>
|
||||
#include "request_with_value.hpp"
|
||||
|
||||
using namespace boost::python;
|
||||
using namespace boost::mpi;
|
||||
|
||||
namespace boost { namespace mpi { namespace python {
|
||||
|
||||
extern const char* request_docstring;
|
||||
extern const char* request_wait_docstring;
|
||||
extern const char* request_test_docstring;
|
||||
extern const char* request_cancel_docstring;
|
||||
|
||||
object request_wait(object req_obj)
|
||||
const object python::request_with_value::get_value() const
|
||||
{
|
||||
request& req = extract<request&>(req_obj)();
|
||||
status stat = req.wait();
|
||||
if (PyObject_HasAttrString(req_obj.ptr(), "value"))
|
||||
return boost::python::make_tuple(stat, req_obj.attr("value"));
|
||||
if (m_internal_value.get())
|
||||
return *m_internal_value;
|
||||
else if (m_external_value)
|
||||
return *m_external_value;
|
||||
else
|
||||
return object(stat);
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "request value not available");
|
||||
throw boost::python::error_already_set();
|
||||
}
|
||||
}
|
||||
|
||||
object request_test(object req_obj)
|
||||
const object python::request_with_value::get_value_or_none() const
|
||||
{
|
||||
request& req = extract<request&>(req_obj)();
|
||||
|
||||
if (optional<status> stat = req.test())
|
||||
{
|
||||
if (PyObject_HasAttrString(req_obj.ptr(), "value"))
|
||||
return boost::python::make_tuple(stat, req_obj.attr("value"));
|
||||
else
|
||||
return object(stat);
|
||||
}
|
||||
if (m_internal_value.get())
|
||||
return *m_internal_value;
|
||||
else if (m_external_value)
|
||||
return *m_external_value;
|
||||
else
|
||||
return object();
|
||||
}
|
||||
|
||||
const object python::request_with_value::wrap_wait()
|
||||
{
|
||||
status stat = request::wait();
|
||||
if (m_internal_value.get() || m_external_value)
|
||||
return boost::python::make_tuple(get_value(), stat);
|
||||
else
|
||||
return object(stat);
|
||||
}
|
||||
|
||||
const object python::request_with_value::wrap_test()
|
||||
{
|
||||
::boost::optional<status> stat = request::test();
|
||||
if (stat)
|
||||
{
|
||||
if (m_internal_value.get() || m_external_value)
|
||||
return boost::python::make_tuple(get_value(), *stat);
|
||||
else
|
||||
return object(*stat);
|
||||
}
|
||||
else
|
||||
return object();
|
||||
}
|
||||
|
||||
|
||||
namespace boost { namespace mpi { namespace python {
|
||||
|
||||
extern const char* request_docstring;
|
||||
extern const char* request_with_value_docstring;
|
||||
extern const char* request_wait_docstring;
|
||||
extern const char* request_test_docstring;
|
||||
extern const char* request_cancel_docstring;
|
||||
extern const char* request_value_docstring;
|
||||
|
||||
void export_request()
|
||||
{
|
||||
using boost::python::arg;
|
||||
using boost::python::object;
|
||||
|
||||
class_<request>("request", request_docstring, no_init)
|
||||
.def("wait", &request_wait, request_wait_docstring)
|
||||
.def("test", &request_test, request_test_docstring)
|
||||
.def("cancel", &request::cancel, request_cancel_docstring)
|
||||
;
|
||||
{
|
||||
typedef request cl;
|
||||
class_<cl>("Request", request_docstring, no_init)
|
||||
.def("wait", &cl::wait, request_wait_docstring)
|
||||
.def("test", &cl::test, request_test_docstring)
|
||||
.def("cancel", &cl::cancel, request_cancel_docstring)
|
||||
;
|
||||
}
|
||||
{
|
||||
typedef request_with_value cl;
|
||||
class_<cl, bases<request> >(
|
||||
"RequestWithValue", request_with_value_docstring, no_init)
|
||||
.def("wait", &cl::wrap_wait, request_wait_docstring)
|
||||
.def("test", &cl::wrap_test, request_test_docstring)
|
||||
;
|
||||
}
|
||||
|
||||
implicitly_convertible<request, request_with_value>();
|
||||
}
|
||||
|
||||
} } } // end namespace boost::mpi::python
|
||||
|
||||
Reference in New Issue
Block a user