2
0
mirror of https://github.com/boostorg/mpi.git synced 2026-01-19 04:22:10 +00:00

use BOSST_MPI_USE_IMPROBE to choose to use MPI_<x>probe when reading complex messages

This commit is contained in:
Alain Miniussi
2018-12-18 17:16:25 +01:00
parent 16b6fc2c38
commit 141add97e9
7 changed files with 64 additions and 57 deletions

View File

@@ -1353,9 +1353,10 @@ template<typename T, typename A>
void communicator::send_vector(int dest, int tag,
const std::vector<T,A>& values, mpl::true_ primitive) const
{
if (request::probe_messages()) {
array_send_impl(dest, tag, values.data(), values.size(), primitive);
} else {
#if defined(BOOST_MPI_USE_IMPROBE)
array_send_impl(dest, tag, values.data(), values.size(), primitive);
#else
{
// non blocking recv by legacy_dynamic_primitive_array_handler
// blocking recv by recv_vector(source,tag,value,primitive)
// send the vector size
@@ -1364,6 +1365,7 @@ void communicator::send_vector(int dest, int tag,
// send the data
this->array_send_impl(dest, tag, values.data(), size, primitive);
}
#endif
}
template<typename T, typename A>
@@ -1453,7 +1455,8 @@ template<typename T, typename A>
status communicator::recv_vector(int source, int tag,
std::vector<T,A>& values, mpl::true_ primitive) const
{
if (request::probe_messages()) {
#if defined(BOOST_MPI_USE_IMPROBE)
{
MPI_Message msg;
status stat;
BOOST_MPI_CHECK_RESULT(MPI_Mprobe, (source,tag,*this,&msg,&stat.m_status));
@@ -1462,7 +1465,9 @@ status communicator::recv_vector(int source, int tag,
values.resize(count);
BOOST_MPI_CHECK_RESULT(MPI_Mrecv, (values.data(), count, get_mpi_datatype<T>(), &msg, &stat.m_status));
return stat;
} else {
}
#else
{
// receive the vector size
typename std::vector<T,A>::size_type size = 0;
recv(source, tag, size);
@@ -1471,6 +1476,7 @@ status communicator::recv_vector(int source, int tag,
// receive the data
return this->array_recv_impl(source, tag, values.data(), size, primitive);
}
#endif
}
template<typename T, typename A>

View File

@@ -120,9 +120,9 @@
// Configuration for MPICH
#endif
#if defined(I_MPI_NUMVERSION)
#if BOOST_MPI_VERSION >= 3 && (!defined(I_MPI_NUMVERSION))
// This is intel
#define BOOST_MPI_NO_IMPROBE
#define BOOST_MPI_USE_IMPROBE 1
#endif
/*****************************************************************************

View File

@@ -123,6 +123,7 @@ struct serialized_irecv_data<skeleton_proxy<T> >
};
}
#if BOOST_MPI_VERSION >= 3
template<class Data>
class request::probe_handler
: public request::handler,
@@ -186,6 +187,7 @@ protected:
int m_source;
int m_tag;
};
#endif // BOOST_MPI_VERSION >= 3
namespace detail {
template<class A>
@@ -527,30 +529,30 @@ private:
template<typename T>
request request::make_serialized(communicator const& comm, int source, int tag, T& value) {
if (probe_messages()) {
return request(new probe_handler<detail::serialized_data<T> >(comm, source, tag, value));
} else {
return request(new legacy_serialized_handler<T>(comm, source, tag, value));
}
#if defined(BOOST_MPI_USE_IMPROBE)
return request(new probe_handler<detail::serialized_data<T> >(comm, source, tag, value));
#else
return request(new legacy_serialized_handler<T>(comm, source, tag, value));
#endif
}
template<typename T>
request request::make_serialized_array(communicator const& comm, int source, int tag, T* values, int n) {
if (probe_messages()) {
return request(new probe_handler<detail::serialized_array_data<T> >(comm, source, tag, values, n));
} else {
return request(new legacy_serialized_array_handler<T>(comm, source, tag, values, n));
}
#if defined(BOOST_MPI_USE_IMPROBE)
return request(new probe_handler<detail::serialized_array_data<T> >(comm, source, tag, values, n));
#else
return request(new legacy_serialized_array_handler<T>(comm, source, tag, values, n));
#endif
}
template<typename T, class A>
request request::make_dynamic_primitive_array_recv(communicator const& comm, int source, int tag,
std::vector<T,A>& values) {
if (probe_messages()) {
return request(new probe_handler<detail::dynamic_primitive_array_data<std::vector<T,A> > >(comm,source,tag,values));
} else {
return request(new legacy_dynamic_primitive_array_handler<T,A>(comm, source, tag, values));
}
#if defined(BOOST_MPI_USE_IMPROBE)
return request(new probe_handler<detail::dynamic_primitive_array_data<std::vector<T,A> > >(comm,source,tag,values));
#else
return request(new legacy_dynamic_primitive_array_handler<T,A>(comm, source, tag, values));
#endif
}
template<typename T>
@@ -590,9 +592,10 @@ request::make_trivial_recv(communicator const& comm, int dest, int tag, T& value
template<typename T, class A>
request request::make_dynamic_primitive_array_send(communicator const& comm, int dest, int tag,
std::vector<T,A> const& values) {
if (request::probe_messages()) {
return make_trivial_send(comm, dest, tag, values.data(), values.size());
} else {
#if defined(BOOST_MPI_USE_IMPROBE)
return make_trivial_send(comm, dest, tag, values.data(), values.size());
#else
{
// non blocking recv by legacy_dynamic_primitive_array_handler
// blocking recv by status recv_vector(source,tag,value,primitive)
boost::shared_ptr<std::size_t> size(new std::size_t(values.size()));
@@ -609,7 +612,8 @@ request request::make_dynamic_primitive_array_send(communicator const& comm, int
get_mpi_datatype<T>(),
dest, tag, comm, handler->m_requests+1));
return req;
}
}
#endif
}
inline

View File

@@ -87,8 +87,6 @@ class BOOST_MPI_DECL request
static request
make_dynamic_primitive_array_send(communicator const& comm, int source, int tag,
std::vector<T,A> const& values);
static bool probe_messages();
/**
* Wait until the communication associated with this request has
* completed, then return a @c status object describing the
@@ -145,13 +143,14 @@ class BOOST_MPI_DECL request
// specific implementations
class legacy_handler;
template<class Data> class probe_handler;
class trivial_handler;
class dynamic_handler;
template<typename T> class legacy_serialized_handler;
template<typename T> class legacy_serialized_array_handler;
template<typename T, class A> class legacy_dynamic_primitive_array_handler;
#if BOOST_MPI_VERSION >= 3
template<class Data> class probe_handler;
#endif
private:
shared_ptr<handler> m_handler;
shared_ptr<void> m_preserved;

View File

@@ -31,12 +31,15 @@ void
packed_archive_send(communicator const& comm, int dest, int tag,
const packed_oarchive& ar)
{
if (request::probe_messages()) {
#if defined(BOOST_MPI_USE_IMPROBE)
{
void *buf = detail::unconst(ar.address());
BOOST_MPI_CHECK_RESULT(MPI_Send,
(buf, ar.size(), MPI_PACKED,
dest, tag, comm));
} else {
}
#else
{
std::size_t const& size = ar.size();
BOOST_MPI_CHECK_RESULT(MPI_Send,
(detail::unconst(&size), 1,
@@ -47,6 +50,7 @@ packed_archive_send(communicator const& comm, int dest, int tag,
MPI_PACKED,
dest, tag, comm));
}
#endif
}
request
@@ -69,14 +73,17 @@ void
packed_archive_recv(communicator const& comm, int source, int tag, packed_iarchive& ar,
MPI_Status& status)
{
if (request::probe_messages()) {
#if defined(BOOST_MPI_USE_IMPROBE)
{
MPI_Message msg;
BOOST_MPI_CHECK_RESULT(MPI_Mprobe, (source, tag, comm, &msg, &status));
int count;
BOOST_MPI_CHECK_RESULT(MPI_Get_count, (&status, MPI_PACKED, &count));
ar.resize(count);
BOOST_MPI_CHECK_RESULT(MPI_Mrecv, (ar.address(), count, MPI_PACKED, &msg, &status));
} else {
}
#else
{
std::size_t count;
BOOST_MPI_CHECK_RESULT(MPI_Recv,
(&count, 1, get_mpi_datatype(count),
@@ -89,6 +96,7 @@ packed_archive_recv(communicator const& comm, int source, int tag, packed_iarchi
status.MPI_SOURCE, status.MPI_TAG,
comm, &status));
}
#endif
}
} } } // end namespace boost::mpi::detail

View File

@@ -10,25 +10,6 @@
namespace boost { namespace mpi {
namespace detail {
bool
choose_probe_usage() {
#ifdef BOOST_MPI_NO_IMPROBE
return false;
#else
return true;
#endif
}
} // detail
bool
request::probe_messages() {
static bool enabled = detail::choose_probe_usage();
return enabled;
}
request::request()
: m_handler() {}
@@ -83,13 +64,16 @@ request::make_empty_recv(communicator const& comm, int dest, int tag) {
request
request::make_packed_send(communicator const& comm, int dest, int tag, void const* buffer, std::size_t n) {
if (probe_messages()) {
#if defined(BOOST_MPI_USE_IMPROBE)
{
trivial_handler* handler = new trivial_handler;
BOOST_MPI_CHECK_RESULT(MPI_Isend,
(const_cast<void*>(buffer), n, MPI_PACKED,
dest, tag, comm, &handler->m_request));
return request(handler);
} else {
}
#else
{
dynamic_handler *handler = new dynamic_handler;
request req(handler);
shared_ptr<std::size_t> size(new std::size_t(n));
@@ -99,11 +83,12 @@ request::make_packed_send(communicator const& comm, int dest, int tag, void cons
get_mpi_datatype(*size),
dest, tag, comm, handler->m_requests));
BOOST_MPI_CHECK_RESULT(MPI_Isend,
(buffer, *size,
(const_cast<void*>(buffer), *size,
MPI_PACKED,
dest, tag, comm, handler->m_requests+1));
return req;
}
#endif
}
/***************************************************************************

View File

@@ -39,7 +39,12 @@ yesno(bool b) {
void
report_features(mpi::communicator const& comm) {
if (comm.rank() == 0) {
std::cout << "Assuming working MPI_Improbe:" << yesno(mpi::request::probe_messages()) << '\n';
std::cout << "Assuming working MPI_Improbe:" <<
#if defined(BOOST_MPI_USE_IMPROBE)
"yes" << '\n';
#else
"no" << '\n';
#endif
}
}