]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/test/sendrecv_test.cpp
1 // Copyright Alain Miniussi 20014.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // A test of the sendrecv() operation.
7 #include <boost/mpi/communicator.hpp>
8 #include <boost/mpi/environment.hpp>
11 #include <boost/serialization/string.hpp>
12 #include <boost/iterator/counting_iterator.hpp>
13 #include <boost/lexical_cast.hpp>
16 #define BOOST_TEST_MODULE mpi_sendrecv
17 #include <boost/test/included/unit_test.hpp>
19 namespace mpi
= boost::mpi
;
22 blob(int i
) : value(i
) {}
24 template<class Archive
>
25 void serialize(Archive
& s
, const unsigned int version
) {
30 std::ostream
& operator<<(std::ostream
& out
, blob
const& b
) {
31 out
<< "blob(" << b
.value
<< ")";
35 bool operator==(blob
const& b1
, blob
const& b2
) {
36 return b1
.value
== b2
.value
;
40 void test_sendrecv(mpi::communicator
& com
) {
41 int const wrank
= com
.rank();
42 int const wsize
= com
.size();
43 int const wnext((wrank
+ 1) % wsize
);
44 int const wprev((wrank
+ wsize
- 1) % wsize
);
46 com
.sendrecv(wnext
, 1, T(wrank
), wprev
, 1, recv
);
47 for(int r
= 0; r
< wsize
; ++r
) {
50 std::cout
<< "rank " << wrank
<< " received " << recv
<< " from " << wprev
<< '\n';
53 BOOST_CHECK(recv
== T(wprev
));
56 BOOST_AUTO_TEST_CASE(sendrecv
)
59 mpi::communicator world
;
60 test_sendrecv
<int>(world
);
61 test_sendrecv
<blob
>(world
);