hello_world_broadcast.cpp 768 B

12345678910111213141516171819202122232425262728
  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 broadcast()
  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. std::string value;
  15. if (world.rank() == 0) {
  16. value = "Hello, World!";
  17. }
  18. broadcast(world, value, 0);
  19. std::cout << "Process #" << world.rank() << " says " << value << std::endl;
  20. return 0;
  21. }