• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2006 Douglas Gregor <doug.gregor@gmail.com>
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 reduce() to compute a minimum value.
8 #include <boost/mpi.hpp>
9 #include <iostream>
10 #include <cstdlib>
11 namespace mpi = boost::mpi;
12 
main(int argc,char * argv[])13 int main(int argc, char* argv[])
14 {
15   mpi::environment env(argc, argv);
16   mpi::communicator world;
17 
18   std::srand(time(0) + world.rank());
19   int my_number = std::rand();
20 
21   if (world.rank() == 0) {
22     int minimum;
23     reduce(world, my_number, minimum, mpi::minimum<int>(), 0);
24     std::cout << "The minimum value is " << minimum << std::endl;
25   } else {
26     reduce(world, my_number, mpi::minimum<int>(), 0);
27   }
28 
29   return 0;
30 }
31