| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #pragma once |
|
|
| #include <thrust/detail/config.h> |
|
|
| #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) |
| # pragma GCC system_header |
| #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) |
| # pragma clang system_header |
| #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) |
| # pragma system_header |
| #endif |
| #include <thrust/iterator/iterator_traits.h> |
| #include <thrust/system/omp/detail/reduce.h> |
| #include <thrust/system/omp/detail/default_decomposition.h> |
| #include <thrust/system/omp/detail/reduce_intervals.h> |
|
|
| THRUST_NAMESPACE_BEGIN |
| namespace system |
| { |
| namespace omp |
| { |
| namespace detail |
| { |
|
|
|
|
| template<typename DerivedPolicy, |
| typename InputIterator, |
| typename OutputType, |
| typename BinaryFunction> |
| OutputType reduce(execution_policy<DerivedPolicy> &exec, |
| InputIterator first, |
| InputIterator last, |
| OutputType init, |
| BinaryFunction binary_op) |
| { |
| typedef typename thrust::iterator_difference<InputIterator>::type difference_type; |
|
|
| const difference_type n = thrust::distance(first,last); |
|
|
| |
| thrust::system::detail::internal::uniform_decomposition<difference_type> decomp1 = thrust::system::omp::detail::default_decomposition(n); |
| thrust::system::detail::internal::uniform_decomposition<difference_type> decomp2(decomp1.size() + 1, 1, 1); |
|
|
| |
| |
| thrust::detail::temporary_array<OutputType,DerivedPolicy> partial_sums(exec, decomp1.size() + 1); |
|
|
| |
| partial_sums[0] = init; |
|
|
| |
| thrust::system::omp::detail::reduce_intervals(exec, first, partial_sums.begin() + 1, binary_op, decomp1); |
|
|
| |
| thrust::system::omp::detail::reduce_intervals(exec, partial_sums.begin(), partial_sums.begin(), binary_op, decomp2); |
|
|
| return partial_sums[0]; |
| } |
|
|
|
|
| } |
| } |
| } |
| THRUST_NAMESPACE_END |
|
|
|
|