]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/test/block_nonblock_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / mpi / test / block_nonblock_test.cpp
1 #include <vector>
2 #include <iostream>
3 #include <iterator>
4 #include <typeinfo>
5
6 #include <boost/mpi.hpp>
7 #include <boost/serialization/vector.hpp>
8 #include <boost/core/demangle.hpp>
9
10 //#include "debugger.cpp"
11
12 #define BOOST_TEST_MODULE mpi_nonblocking
13 #include <boost/test/included/unit_test.hpp>
14
15 namespace mpi = boost::mpi;
16
17 template<typename T>
18 bool test(mpi::communicator const& comm, std::vector<T> const& ref, bool iswap, bool alloc)
19 {
20
21 int rank = comm.rank();
22 if (rank == 0) {
23 std::cout << "Testing with type " << boost::core::demangle(typeid(T).name()) << '\n';
24 if (iswap) {
25 std::cout << "Blockin send, non blocking receive.\n";
26 } else {
27 std::cout << "Non blockin send, blocking receive.\n";
28 }
29 if (alloc) {
30 std::cout << "Explicitly allocate space for the receiver.\n";
31 } else {
32 std::cout << "Do not explicitly allocate space for the receiver.\n";
33 }
34 }
35 if (rank == 0) {
36 std::vector<T> data;
37 if (alloc) {
38 data.resize(ref.size());
39 }
40 if (iswap) {
41 mpi::request req = comm.irecv(1, 0, data);
42 req.wait();
43 } else {
44 comm.recv(1, 0, data);
45 }
46 std::cout << "Process 0 received " << data.size() << " elements :" << std::endl;
47 std::copy(data.begin(), data.end(), std::ostream_iterator<T>(std::cout, " "));
48 std::cout << std::endl;
49 std::cout << "While expecting " << ref.size() << " elements :" << std::endl;
50 std::copy(ref.begin(), ref.end(), std::ostream_iterator<T>(std::cout, " "));
51 std::cout << std::endl;
52 return (data == ref);
53 } else {
54 if (rank == 1) {
55 std::vector<T> vec = ref;
56 if (iswap) {
57 comm.send(0, 0, vec);
58 } else {
59 mpi::request req = comm.isend(0, 0, vec);
60 req.wait();
61 }
62 }
63 return true;
64 }
65 }
66
67 BOOST_AUTO_TEST_CASE(non_blocking)
68 {
69 mpi::environment env;
70 mpi::communicator world;
71
72 BOOST_TEST_REQUIRE(world.size() > 1);
73
74 std::vector<int> integers(13); // don't assume we're lucky
75 for(int i = 0; i < int(integers.size()); ++i) {
76 integers[i] = i;
77 }
78
79 std::vector<std::string> strings(13); // don't assume we're lucky
80 for(int i = 0; i < int(strings.size()); ++i) {
81 std::ostringstream fmt;
82 fmt << "S" << i;
83 strings[i] = fmt.str();
84 }
85
86 BOOST_CHECK(test(world, integers, true, true));
87 BOOST_CHECK(test(world, integers, true, false));
88 BOOST_CHECK(test(world, strings, true, true));
89 BOOST_CHECK(test(world, strings, true, false));
90
91 BOOST_CHECK(test(world, integers, false, true));
92 BOOST_CHECK(test(world, integers, false, false));
93 BOOST_CHECK(test(world, strings, false, true));
94 BOOST_CHECK(test(world, strings, false, false));
95 }