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 10 #include <boost/mpi.hpp> 11 #include <iostream> 12 #include <cstdlib> 13 namespace mpi = boost::mpi; 14 main(int argc,char * argv[])15int main(int argc, char* argv[]) 16 { 17 mpi::environment env(argc, argv); 18 mpi::communicator world; 19 20 std::srand(world.rank()); 21 int my_number = std::rand(); 22 int minimum; 23 24 all_reduce(world, my_number, minimum, mpi::minimum<int>()); 25 26 if (world.rank() == 0) { 27 std::cout << "The minimum value is " << minimum << std::endl; 28 } 29 30 return 0; 31 } 32