From 141add97e932209288c12e55c10e6d2a9fd86374 Mon Sep 17 00:00:00 2001 From: Alain Miniussi Date: Tue, 18 Dec 2018 17:16:25 +0100 Subject: [PATCH] use BOSST_MPI_USE_IMPROBE to choose to use MPI_probe when reading complex messages --- include/boost/mpi/communicator.hpp | 16 ++++--- include/boost/mpi/config.hpp | 4 +- include/boost/mpi/detail/request_handlers.hpp | 42 ++++++++++--------- include/boost/mpi/request.hpp | 7 ++-- src/point_to_point.cpp | 16 +++++-- src/request.cpp | 29 ++++--------- test/version_test.cpp | 7 +++- 7 files changed, 64 insertions(+), 57 deletions(-) diff --git a/include/boost/mpi/communicator.hpp b/include/boost/mpi/communicator.hpp index 9b08cf9..ff889d0 100644 --- a/include/boost/mpi/communicator.hpp +++ b/include/boost/mpi/communicator.hpp @@ -1353,9 +1353,10 @@ template void communicator::send_vector(int dest, int tag, const std::vector& 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 @@ -1453,7 +1455,8 @@ template status communicator::recv_vector(int source, int tag, std::vector& 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(), &msg, &stat.m_status)); return stat; - } else { + } +#else + { // receive the vector size typename std::vector::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 diff --git a/include/boost/mpi/config.hpp b/include/boost/mpi/config.hpp index 97a87e6..48c0a9f 100644 --- a/include/boost/mpi/config.hpp +++ b/include/boost/mpi/config.hpp @@ -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 /***************************************************************************** diff --git a/include/boost/mpi/detail/request_handlers.hpp b/include/boost/mpi/detail/request_handlers.hpp index 5ca0503..7f3882b 100644 --- a/include/boost/mpi/detail/request_handlers.hpp +++ b/include/boost/mpi/detail/request_handlers.hpp @@ -123,6 +123,7 @@ struct serialized_irecv_data > }; } +#if BOOST_MPI_VERSION >= 3 template 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 @@ -527,30 +529,30 @@ private: template request request::make_serialized(communicator const& comm, int source, int tag, T& value) { - if (probe_messages()) { - return request(new probe_handler >(comm, source, tag, value)); - } else { - return request(new legacy_serialized_handler(comm, source, tag, value)); - } +#if defined(BOOST_MPI_USE_IMPROBE) + return request(new probe_handler >(comm, source, tag, value)); +#else + return request(new legacy_serialized_handler(comm, source, tag, value)); +#endif } template request request::make_serialized_array(communicator const& comm, int source, int tag, T* values, int n) { - if (probe_messages()) { - return request(new probe_handler >(comm, source, tag, values, n)); - } else { - return request(new legacy_serialized_array_handler(comm, source, tag, values, n)); - } +#if defined(BOOST_MPI_USE_IMPROBE) + return request(new probe_handler >(comm, source, tag, values, n)); +#else + return request(new legacy_serialized_array_handler(comm, source, tag, values, n)); +#endif } template request request::make_dynamic_primitive_array_recv(communicator const& comm, int source, int tag, std::vector& values) { - if (probe_messages()) { - return request(new probe_handler > >(comm,source,tag,values)); - } else { - return request(new legacy_dynamic_primitive_array_handler(comm, source, tag, values)); - } +#if defined(BOOST_MPI_USE_IMPROBE) + return request(new probe_handler > >(comm,source,tag,values)); +#else + return request(new legacy_dynamic_primitive_array_handler(comm, source, tag, values)); +#endif } template @@ -590,9 +592,10 @@ request::make_trivial_recv(communicator const& comm, int dest, int tag, T& value template request request::make_dynamic_primitive_array_send(communicator const& comm, int dest, int tag, std::vector 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 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(), dest, tag, comm, handler->m_requests+1)); return req; - } + } +#endif } inline diff --git a/include/boost/mpi/request.hpp b/include/boost/mpi/request.hpp index 5f66176..8732cd2 100644 --- a/include/boost/mpi/request.hpp +++ b/include/boost/mpi/request.hpp @@ -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 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 probe_handler; class trivial_handler; class dynamic_handler; template class legacy_serialized_handler; template class legacy_serialized_array_handler; template class legacy_dynamic_primitive_array_handler; - +#if BOOST_MPI_VERSION >= 3 + template class probe_handler; +#endif private: shared_ptr m_handler; shared_ptr m_preserved; diff --git a/src/point_to_point.cpp b/src/point_to_point.cpp index 23b7877..6fc0ad1 100644 --- a/src/point_to_point.cpp +++ b/src/point_to_point.cpp @@ -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 diff --git a/src/request.cpp b/src/request.cpp index 6157190..3ba5695 100644 --- a/src/request.cpp +++ b/src/request.cpp @@ -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(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 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(buffer), *size, MPI_PACKED, dest, tag, comm, handler->m_requests+1)); return req; } +#endif } /*************************************************************************** diff --git a/test/version_test.cpp b/test/version_test.cpp index 2e5c2e8..3163c5e 100644 --- a/test/version_test.cpp +++ b/test/version_test.cpp @@ -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 } }