]>
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>
9 #include <boost/test/minimal.hpp>
12 #include <boost/serialization/string.hpp>
13 #include <boost/iterator/counting_iterator.hpp>
14 #include <boost/lexical_cast.hpp>
17 namespace mpi
= boost::mpi
;
20 blob(int i
) : value(i
) {}
22 template<class Archive
>
23 void serialize(Archive
& s
, const unsigned int version
) {
28 std::ostream
& operator<<(std::ostream
& out
, blob
const& b
) {
29 out
<< "blob(" << b
.value
<< ")";
33 bool operator==(blob
const& b1
, blob
const& b2
) {
34 return b1
.value
== b2
.value
;
38 void test_sendrecv(mpi::communicator
& com
) {
39 int const wrank
= com
.rank();
40 int const wsize
= com
.size();
41 int const wnext((wrank
+ 1) % wsize
);
42 int const wprev((wrank
+ wsize
- 1) % wsize
);
44 com
.sendrecv(wnext
, 1, T(wrank
), wprev
, 1, recv
);
45 for(int r
= 0; r
< wsize
; ++r
) {
48 std::cout
<< "rank " << wrank
<< " received " << recv
<< " from " << wprev
<< '\n';
51 BOOST_CHECK(recv
== T(wprev
));
54 int test_main(int argc
, char* argv
[])
56 mpi::environment
env(argc
, argv
);
57 mpi::communicator world
;
58 test_sendrecv
<int>(world
);
59 test_sendrecv
<blob
>(world
);