// Copyright (C) 2017 Alain Miniussi & Steffen Hirschmann // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include #include #define BOOST_TEST_MODULE mpi_wait_any #include namespace mpi = boost::mpi; BOOST_AUTO_TEST_CASE(wait_any) { mpi::environment env; mpi::communicator world; std::vector ss(world.size()); typedef std::vector requests; requests rreqs; std::set pending_senders; for (int i = 0; i < world.size(); ++i) { rreqs.push_back(world.irecv(i, i, ss[i])); pending_senders.insert(i); } std::ostringstream fmt; std::string msg = "Hello, World! this is "; fmt << msg << world.rank(); requests sreqs; for (int i = 0; i < world.size(); ++i) { sreqs.push_back(world.isend(i, world.rank(), fmt.str())); } for (int i = 0; i < world.size(); ++i) { std::pair completed = mpi::wait_any(rreqs.begin(), rreqs.end()); std::ostringstream out; out << "Proc " << world.rank() << " got message from " << completed.first.source() << '\n'; std::cout << out.str(); } for (int i = 0; i < world.size(); ++i) { std::ostringstream fmt; fmt << msg << i; std::vector::iterator found = std::find(ss.begin(), ss.end(), fmt.str()); BOOST_CHECK(found != ss.end()); fmt.str(""); fmt << "Proc " << world.rank() << " Got msg from " << i << '\n'; std::cout << fmt.str(); } mpi::wait_all(sreqs.begin(), sreqs.end()); }