1 // Copyright (C) 2006 Douglas Gregor <doug.gregor@gmail.com>
2
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)
6
7 // A simple Hello, world! example using Boost.MPI message passing.
8
9 #include <boost/mpi.hpp>
10 #include <iostream>
11 #include <boost/serialization/string.hpp> // Needed to send/receive strings!
12 namespace mpi = boost::mpi;
13
main(int argc,char * argv[])14 int main(int argc, char* argv[])
15 {
16 mpi::environment env(argc, argv);
17 mpi::communicator world;
18
19 if (world.rank() == 0) {
20 mpi::request reqs[2];
21 std::string msg, out_msg = "Hello";
22 reqs[0] = world.isend(1, 0, out_msg);
23 reqs[1] = world.irecv(1, 1, msg);
24 mpi::wait_all(reqs, reqs + 2);
25 std::cout << msg << "!" << std::endl;
26 } else {
27 mpi::request reqs[2];
28 std::string msg, out_msg = "world";
29 reqs[0] = world.isend(0, 1, out_msg);
30 reqs[1] = world.irecv(0, 0, msg);
31 mpi::wait_all(reqs, reqs + 2);
32 std::cout << msg << ", ";
33 }
34
35 return 0;
36 }
37