RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
IndexSetUtils.hpp
Go to the documentation of this file.
1 
12 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
13 // Copyright (c) Lawrence Livermore National Security, LLC and other
14 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
15 // files for dates and other details. No copyright assignment is required
16 // to contribute to RAJA.
17 //
18 // SPDX-License-Identifier: (BSD-3-Clause)
19 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
20 
21 #ifndef RAJA_IndexSetUtils_HPP
22 #define RAJA_IndexSetUtils_HPP
23 
24 #include "RAJA/config.hpp"
25 
26 #include "RAJA/pattern/forall.hpp"
27 
29 
30 namespace RAJA
31 {
32 
34 
49 template<typename CONTAINER_T, typename... SEG_TYPES>
50 RAJA_INLINE void getIndices(CONTAINER_T& con,
51  const TypedIndexSet<SEG_TYPES...>& iset)
52 {
53  CONTAINER_T tcon;
54  forall<ExecPolicy<seq_segit, seq_exec>>(
55  iset, [&](typename CONTAINER_T::value_type idx) {
56  tcon.push_back(idx);
57  });
58  con = tcon;
59 }
60 
68 template<typename CONTAINER_T, typename SEGMENT_T>
69 RAJA_INLINE void getIndices(CONTAINER_T& con, const SEGMENT_T& seg)
70 {
71  CONTAINER_T tcon;
72  forall<seq_exec>(seg, [&](typename CONTAINER_T::value_type idx) {
73  tcon.push_back(idx);
74  });
75  con = tcon;
76 }
77 
86 template<typename CONTAINER_T, typename... SEG_TYPES, typename CONDITIONAL>
87 RAJA_INLINE void getIndicesConditional(CONTAINER_T& con,
88  const TypedIndexSet<SEG_TYPES...>& iset,
89  CONDITIONAL conditional)
90 {
91  CONTAINER_T tcon;
92  forall<ExecPolicy<seq_segit, seq_exec>>(
93  iset, [&](typename CONTAINER_T::value_type idx) {
94  if (conditional(idx)) tcon.push_back(idx);
95  });
96  con = tcon;
97 }
98 
107 template<typename CONTAINER_T, typename SEGMENT_T, typename CONDITIONAL>
108 RAJA_INLINE void getIndicesConditional(CONTAINER_T& con,
109  const SEGMENT_T& seg,
110  CONDITIONAL conditional)
111 {
112  CONTAINER_T tcon;
113  forall<seq_exec>(seg, [&](typename CONTAINER_T::value_type idx) {
114  if (conditional(idx)) tcon.push_back(idx);
115  });
116  con = tcon;
117 }
118 
120 
121 } // namespace RAJA
122 
123 #endif // closing endif for header file include guard
Definition: IndexSet.hpp:52
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_INLINE void getIndicesConditional(CONTAINER_T &con, const TypedIndexSet< SEG_TYPES... > &iset, CONDITIONAL conditional)
Copy all indices in given index set that satisfy given conditional to given container.
Definition: IndexSetUtils.hpp:87
RAJA_INLINE void getIndices(CONTAINER_T &con, const TypedIndexSet< SEG_TYPES... > &iset)
Copy all indices in given index set to given container.
Definition: IndexSetUtils.hpp:50
Header file containing RAJA index set and segment iteration template methods that take an execution p...
Header file containing RAJA headers for sequential execution.