• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2004 The Trustees of Indiana University.
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 //  Authors: Douglas Gregor
8 //           Andrew Lumsdaine
9 #ifndef BOOST_PARALLEL_ALGORITHM_HPP
10 #define BOOST_PARALLEL_ALGORITHM_HPP
11 
12 #ifndef BOOST_GRAPH_USE_MPI
13 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
14 #endif
15 
16 #include <boost/optional.hpp>
17 #include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
18 #include <vector>
19 #include <functional>
20 
21 namespace boost { namespace parallel {
22   template<typename BinaryOp>
23   struct is_commutative
24   {
25     BOOST_STATIC_CONSTANT(bool, value = false);
26   };
27 
28   template<typename T>
29   struct minimum : std::binary_function<T, T, T>
30   {
operator ()boost::parallel::minimum31     const T& operator()(const T& x, const T& y) const { return x < y? x : y; }
32   };
33 
34   template<typename T>
35   struct maximum : std::binary_function<T, T, T>
36   {
operator ()boost::parallel::maximum37     const T& operator()(const T& x, const T& y) const { return x < y? y : x; }
38   };
39 
40   template<typename T>
41   struct sum : std::binary_function<T, T, T>
42   {
operator ()boost::parallel::sum43     const T operator()(const T& x, const T& y) const { return x + y; }
44   };
45 
46   template<typename ProcessGroup, typename InputIterator,
47            typename OutputIterator, typename BinaryOperation>
48   OutputIterator
49   reduce(ProcessGroup pg, typename ProcessGroup::process_id_type root,
50          InputIterator first, InputIterator last, OutputIterator out,
51          BinaryOperation bin_op);
52 
53   template<typename ProcessGroup, typename T, typename BinaryOperation>
54   inline T
all_reduce(ProcessGroup pg,const T & value,BinaryOperation bin_op)55   all_reduce(ProcessGroup pg, const T& value, BinaryOperation bin_op)
56   {
57     T result;
58     all_reduce(pg,
59                const_cast<T*>(&value), const_cast<T*>(&value+1),
60                &result, bin_op);
61     return result;
62   }
63 
64   template<typename ProcessGroup, typename T, typename BinaryOperation>
65   inline T
scan(ProcessGroup pg,const T & value,BinaryOperation bin_op)66   scan(ProcessGroup pg, const T& value, BinaryOperation bin_op)
67   {
68     T result;
69     scan(pg,
70          const_cast<T*>(&value), const_cast<T*>(&value+1),
71          &result, bin_op);
72     return result;
73   }
74 
75 
76   template<typename ProcessGroup, typename InputIterator, typename T>
77   void
78   all_gather(ProcessGroup pg, InputIterator first, InputIterator last,
79              std::vector<T>& out);
80 } } // end namespace boost::parallel
81 
82 #include <boost/graph/parallel/detail/inplace_all_to_all.hpp>
83 
84 #endif // BOOST_PARALLEL_ALGORITHM_HPP
85