20 #ifndef RAJA_scan_openmp_HPP
21 #define RAJA_scan_openmp_HPP
23 #include "RAJA/config.hpp"
28 #include <type_traits>
48 template<
typename Policy,
typename Iter,
typename BinFn>
49 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
59 using Value = typename ::std::iterator_traits<Iter>::value_type;
60 const auto n = distance(begin, end);
61 using DistanceT =
typename std::remove_const<decltype(n)>::type;
62 const int p0 =
std::min(n,
static_cast<DistanceT
>(omp_get_max_threads()));
63 ::std::vector<Value> sums(p0, Value());
64 #pragma omp parallel num_threads(p0)
66 const int p = omp_get_num_threads();
67 const int pid = omp_get_thread_num();
68 const DistanceT idx_begin =
firstIndex(n, p, pid);
69 const DistanceT idx_end =
firstIndex(n, p, pid + 1);
70 if (idx_begin != idx_end)
74 sums[pid] = begin[idx_end - 1];
79 sums.data() + p, f, BinFn::identity());
80 for (
auto i = idx_begin; i < idx_end; ++i)
82 begin[i] = f(begin[i], sums[pid]);
86 return resources::EventProxy<resources::Host>(host_res);
93 template<
typename Policy,
typename Iter,
typename BinFn,
typename ValueT>
94 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
105 using Value = typename ::std::iterator_traits<Iter>::value_type;
106 const auto n = distance(begin, end);
107 using DistanceT =
typename std::remove_const<decltype(n)>::type;
108 const int p0 =
std::min(n,
static_cast<DistanceT
>(omp_get_max_threads()));
109 ::std::vector<Value> sums(p0, v);
110 #pragma omp parallel num_threads(p0)
112 const int p = omp_get_num_threads();
113 const int pid = omp_get_thread_num();
114 const DistanceT idx_begin =
firstIndex(n, p, pid);
115 const DistanceT idx_end =
firstIndex(n, p, pid + 1);
116 const Value init = ((pid == 0) ? v : *(begin + idx_begin - 1));
118 if (idx_begin != idx_end)
121 begin + idx_end, f, init);
122 sums[pid] = begin[idx_end - 1];
128 for (
auto i = idx_begin; i < idx_end; ++i)
130 begin[i] = f(begin[i], sums[pid]);
134 return resources::EventProxy<resources::Host>(host_res);
141 template<
typename Policy,
typename Iter,
typename OutIter,
typename BinFn>
142 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
152 ::std::copy(begin, end, out);
165 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
176 ::std::copy(begin, end, out);
Header file for RAJA algorithm definitions.
RAJA_INLINE DiffType firstIndex(DiffType n, CountType num_threads, CountType thread_id)
Definition: algorithm.hpp:62
RAJA_INLINE concepts::enable_if_t< resources::EventProxy< resources::Host >, type_traits::is_openmp_policy< Policy > > inclusive(resources::Host host_res, const Policy &exec, Iter begin, Iter end, OutIter out, BinFn f)
Definition: scan.hpp:144
RAJA_INLINE concepts::enable_if_t< resources::EventProxy< resources::Host >, type_traits::is_openmp_policy< Policy > > exclusive(resources::Host host_res, const Policy &exec, Iter begin, Iter end, OutIter out, BinFn f, ValueT v)
Definition: scan.hpp:167
RAJA_INLINE concepts::enable_if_t< resources::EventProxy< resources::Host >, type_traits::is_openmp_policy< Policy > > inclusive_inplace(resources::Host host_res, const Policy &, Iter begin, Iter end, BinFn f)
Definition: scan.hpp:51
RAJA_INLINE concepts::enable_if_t< resources::EventProxy< resources::Host >, type_traits::is_openmp_policy< Policy > > exclusive_inplace(resources::Host host_res, const Policy &, Iter begin, Iter end, BinFn f, ValueT v)
Definition: scan.hpp:96
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result min(Args... args)
Definition: foldl.hpp:161
Policy
Definition: PolicyBase.hpp:32
Header file containing RAJA OpenMP policy definitions.
Header file providing RAJA scan declarations.
Definition: policy.hpp:78
Definition: PolicyBase.hpp:215