From 3884466f5ccdbe72b90cf637655fc99936ad24ce Mon Sep 17 00:00:00 2001 From: Alain Miniussi Date: Wed, 29 Oct 2014 00:47:37 +0100 Subject: [PATCH] Forgot to test the non mpi primitive type. --- include/boost/mpi/communicator.hpp | 5 ++-- test/sendrecv_test.cpp | 46 ++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/include/boost/mpi/communicator.hpp b/include/boost/mpi/communicator.hpp index edc5a5e..fcef086 100644 --- a/include/boost/mpi/communicator.hpp +++ b/include/boost/mpi/communicator.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include // for std::range_error @@ -1299,8 +1300,8 @@ status communicator::sendrecv_impl(int dest, int stag, const T& sval, int src, i int const SEND = 0; int const RECV = 1; request srrequests[2]; - srrequests[SEND] = this->isend_impl(dest, stag, sval, mpl::false_); - srrequests[RECV] = this->irecv_impl(src, rtag, rval, mpl::false_); + srrequests[SEND] = this->isend_impl(dest, stag, sval, mpl::false_()); + srrequests[RECV] = this->irecv_impl(src, rtag, rval, mpl::false_()); status srstatuses[2]; wait_all(srrequests, srrequests + 2, srstatuses); return srstatuses[RECV]; diff --git a/test/sendrecv_test.cpp b/test/sendrecv_test.cpp index 14fd74c..8fd4233 100644 --- a/test/sendrecv_test.cpp +++ b/test/sendrecv_test.cpp @@ -16,24 +16,46 @@ namespace mpi = boost::mpi; -int test_main(int argc, char* argv[]) -{ +struct blob { + blob(int i) : value(i) {} + int value; + template + void serialize(Archive& s, const unsigned int version) { + s & value; + } +}; - mpi::environment env(argc, argv); - mpi::communicator world; +std::ostream& operator<<(std::ostream& out, blob const& b) { + out << "blob(" << b.value << ")"; + return out; +} - int const wrank = world.rank(); - int const wsize = world.size(); - int const wnext = (wrank + 1) % wsize; - int const wprev = (wrank + wsize - 1) % wsize; - int recv = -1; - world.sendrecv(wnext, 1, wrank, wprev, 1, recv); +bool operator==(blob const& b1, blob const& b2) { + return b1.value == b2.value; +} + +template +void test_sendrecv(mpi::communicator& com) { + int const wrank = com.rank(); + int const wsize = com.size(); + int const wnext((wrank + 1) % wsize); + int const wprev((wrank + wsize - 1) % wsize); + T recv(-1); + com.sendrecv(wnext, 1, T(wrank), wprev, 1, recv); for(int r = 0; r < wsize; ++r) { - world.barrier(); + com.barrier(); if (r == wrank) { std::cout << "rank " << wrank << " received " << recv << " from " << wprev << '\n'; } } - BOOST_CHECK(recv == wprev); + BOOST_CHECK(recv == T(wprev)); +} + +int test_main(int argc, char* argv[]) +{ + mpi::environment env(argc, argv); + mpi::communicator world; + test_sendrecv(world); + test_sendrecv(world); return 0; }