algorithm.hpp 2.4 KB

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