RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
scan.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_scan_sequential_HPP
21 #define RAJA_scan_sequential_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #include <algorithm>
26 #include <functional>
27 #include <iterator>
28 
29 #include "RAJA/util/macros.hpp"
30 
31 #include "RAJA/util/concepts.hpp"
32 
34 
35 namespace RAJA
36 {
37 namespace impl
38 {
39 namespace scan
40 {
45 template<typename ExecPolicy, typename Iter, typename BinFn>
46 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
47  type_traits::is_sequential_policy<ExecPolicy>>
48 inclusive_inplace(resources::Host host_res,
49  const ExecPolicy&,
50  Iter begin,
51  Iter end,
52  BinFn f)
53 {
54  using ValueT = typename std::remove_reference<decltype(*begin)>::type;
55  ValueT agg = *begin;
56 
57  for (Iter i = ++begin; i != end; ++i)
58  {
59  agg = f(agg, *i);
60  *i = agg;
61  }
62 
63  return resources::EventProxy<resources::Host>(host_res);
64 }
65 
70 template<typename ExecPolicy, typename Iter, typename BinFn, typename T>
71 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
73 exclusive_inplace(resources::Host host_res,
74  const ExecPolicy&,
75  Iter begin,
76  Iter end,
77  BinFn f,
78  T v)
79 {
80  using std::distance;
81  const auto n = distance(begin, end);
82  using DistanceT = typename std::remove_const<decltype(n)>::type;
83 
84  using ValueT = typename std::remove_reference<decltype(*begin)>::type;
85  ValueT agg = v;
86 
87  for (DistanceT i = 0; i < n; ++i)
88  {
89  auto t = begin[i];
90  begin[i] = agg;
91  agg = f(agg, t);
92  }
93 
94  return resources::EventProxy<resources::Host>(host_res);
95 }
96 
101 template<typename ExecPolicy, typename Iter, typename OutIter, typename BinFn>
102 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
104 inclusive(resources::Host host_res,
105  const ExecPolicy&,
106  const Iter begin,
107  const Iter end,
108  OutIter out,
109  BinFn f)
110 {
111  using ValueT = typename std::remove_reference<decltype(*out)>::type;
112  ValueT agg = *begin;
113  *out++ = agg;
114 
115  for (Iter i = begin + 1; i != end; ++i)
116  {
117  agg = f(agg, *i);
118  *out++ = agg;
119  }
120 
121  return resources::EventProxy<resources::Host>(host_res);
122 }
123 
128 template<typename ExecPolicy,
129  typename Iter,
130  typename OutIter,
131  typename BinFn,
132  typename T>
133 RAJA_INLINE concepts::enable_if_t<resources::EventProxy<resources::Host>,
135 exclusive(resources::Host host_res,
136  const ExecPolicy&,
137  const Iter begin,
138  const Iter end,
139  OutIter out,
140  BinFn f,
141  T v)
142 {
143  using ValueT = typename std::remove_reference<decltype(*out)>::type;
144  ValueT agg = v;
145  OutIter o = out;
146  *o++ = v;
147 
148  for (Iter i = begin; i != end - 1; ++i, ++o)
149  {
150  agg = f(agg, *i);
151  *o = agg;
152  }
153 
154  return resources::EventProxy<resources::Host>(host_res);
155 }
156 
157 } // namespace scan
158 
159 } // namespace impl
160 
161 } // namespace RAJA
162 
163 #endif
Header file for RAJA concept definitions.
Header file for common RAJA internal macro definitions.
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
Header file containing RAJA sequential policy definitions.
Definition: IndexSet.hpp:70
Definition: PolicyBase.hpp:207