hello_world_nonblocking.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2006 Douglas Gregor <doug.gregor@gmail.com>
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // A simple Hello, world! example using Boost.MPI message passing.
  6. #include <boost/mpi.hpp>
  7. #include <iostream>
  8. #include <boost/serialization/string.hpp> // Needed to send/receive strings!
  9. namespace mpi = boost::mpi;
  10. int main(int argc, char* argv[])
  11. {
  12. mpi::environment env(argc, argv);
  13. mpi::communicator world;
  14. if (world.rank() == 0) {
  15. mpi::request reqs[2];
  16. std::string msg, out_msg = "Hello";
  17. reqs[0] = world.isend(1, 0, out_msg);
  18. reqs[1] = world.irecv(1, 1, msg);
  19. mpi::wait_all(reqs, reqs + 2);
  20. std::cout << msg << "!" << std::endl;
  21. } else {
  22. mpi::request reqs[2];
  23. std::string msg, out_msg = "world";
  24. reqs[0] = world.isend(0, 1, out_msg);
  25. reqs[1] = world.irecv(0, 0, msg);
  26. mpi::wait_all(reqs, reqs + 2);
  27. std::cout << msg << ", ";
  28. }
  29. return 0;
  30. }