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