in_place_global_min.cpp 818 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (C) 2013 Alain Miniussi <alain.miniussi@oca.eu>
  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. // An example using Boost.MPI's all_reduce() that compute the minimum
  6. // of each process's value and broadcast the result to all the processes.
  7. #include <boost/mpi.hpp>
  8. #include <iostream>
  9. #include <cstdlib>
  10. namespace mpi = boost::mpi;
  11. int main(int argc, char* argv[])
  12. {
  13. mpi::environment env(argc, argv);
  14. mpi::communicator world;
  15. std::srand(world.rank());
  16. int my_number = std::rand();
  17. all_reduce(world, my_number, mpi::minimum<int>());
  18. if (world.rank() == 0) {
  19. std::cout << "The minimum value is " << my_number << std::endl;
  20. }
  21. return 0;
  22. }