1 // Copyright (C) 2018 Steffen Hirschmann
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Test any_source on serialized data
11 #include <boost/mpi.hpp>
12 #include <boost/serialization/vector.hpp>
14 #define BOOST_TEST_MODULE mpi_non_blockin_any_source
15 #include <boost/test/included/unit_test.hpp>
17 namespace mpi = boost::mpi;
19 std::string ok(bool b) {
20 return b ? "ok" : "ko";
23 BOOST_AUTO_TEST_CASE(non_blocking_any)
26 mpi::communicator world;
27 int rank = world.rank();
28 #if BOOST_MPI_VERSION < 3
30 std::cout << "\nExpected failure with MPI standard < 3 ("
31 << BOOST_MPI_VERSION << "." << BOOST_MPI_SUBVERSION
37 std::vector<boost::mpi::request> req;
38 std::vector<std::vector<int> > data(world.size() - 1);
39 for (int i = 1; i < world.size(); ++i) {
40 req.push_back(world.irecv(mpi::any_source, 0, data[i - 1]));
42 boost::mpi::wait_all(req.begin(), req.end());
43 std::vector<bool> check(world.size()-1, false);
44 for (int i = 0; i < world.size() - 1; ++i) {
45 std::cout << "Process 0 received:" << std::endl;
46 std::copy(data[i].begin(), data[i].end(), std::ostream_iterator<int>(std::cout, " "));
47 std::cout << std::endl;
48 int idx = data[i].size();
49 BOOST_CHECK(std::equal_range(data[i].begin(), data[i].end(), idx)
50 == std::make_pair(data[i].begin(), data[i].end()));
53 for(int i = 0; i < world.size() - 1; ++i) {
54 std::cout << "Received from " << i+1 << " is " << ok(check[i]) << '\n';
56 BOOST_CHECK(std::equal_range(check.begin(), check.end(), true)
57 == std::make_pair(check.begin(), check.end()));
59 std::vector<int> vec(rank, rank);
60 mpi::request req = world.isend(0, 0, vec);