| 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 |
|
|---|
| 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 | world.send(1, 0, std::wstring(L"Hello"));
|
|---|
| 21 | std::wstring msg;
|
|---|
| 22 | world.recv(1, 1, msg);
|
|---|
| 23 | std::wcout << msg << L"!" << std::endl;
|
|---|
| 24 | } else {
|
|---|
| 25 | std::wstring msg;
|
|---|
| 26 | world.recv(0, 0, msg);
|
|---|
| 27 | std::wcout << msg << L", ";
|
|---|
| 28 | std::wcout.flush();
|
|---|
| 29 | world.send(0, 1, std::wstring(L"world"));
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | return 0;
|
|---|
| 33 | }
|
|---|