algorithm.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. namespace boost { namespace parallel {
  16. template<typename BinaryOp>
  17. struct is_commutative
  18. {
  19. BOOST_STATIC_CONSTANT(bool, value = false);
  20. };
  21. template<typename T>
  22. struct minimum
  23. {
  24. typedef T first_argument_type;
  25. typedef T second_argument_type;
  26. typedef T result_type;
  27. const T& operator()(const T& x, const T& y) const { return x < y? x : y; }
  28. };
  29. template<typename T>
  30. struct maximum
  31. {
  32. typedef T first_argument_type;
  33. typedef T second_argument_type;
  34. typedef T result_type;
  35. const T& operator()(const T& x, const T& y) const { return x < y? y : x; }
  36. };
  37. template<typename T>
  38. struct sum
  39. {
  40. typedef T first_argument_type;
  41. typedef T second_argument_type;
  42. typedef T result_type;
  43. const T operator()(const T& x, const T& y) const { return x + y; }
  44. };
  45. template<typename ProcessGroup, typename InputIterator,
  46. typename OutputIterator, typename BinaryOperation>
  47. OutputIterator
  48. reduce(ProcessGroup pg, typename ProcessGroup::process_id_type root,
  49. InputIterator first, InputIterator last, OutputIterator out,
  50. BinaryOperation bin_op);
  51. template<typename ProcessGroup, typename T, typename BinaryOperation>
  52. inline T
  53. all_reduce(ProcessGroup pg, const T& value, BinaryOperation bin_op)
  54. {
  55. T result;
  56. all_reduce(pg,
  57. const_cast<T*>(&value), const_cast<T*>(&value+1),
  58. &result, bin_op);
  59. return result;
  60. }
  61. template<typename ProcessGroup, typename T, typename BinaryOperation>
  62. inline T
  63. scan(ProcessGroup pg, const T& value, BinaryOperation bin_op)
  64. {
  65. T result;
  66. scan(pg,
  67. const_cast<T*>(&value), const_cast<T*>(&value+1),
  68. &result, bin_op);
  69. return result;
  70. }
  71. template<typename ProcessGroup, typename InputIterator, typename T>
  72. void
  73. all_gather(ProcessGroup pg, InputIterator first, InputIterator last,
  74. std::vector<T>& out);
  75. } } // end namespace boost::parallel
  76. #include <boost/graph/parallel/detail/inplace_all_to_all.hpp>
  77. #endif // BOOST_PARALLEL_ALGORITHM_HPP