20 #ifndef RAJA_IndexSet_HPP
21 #define RAJA_IndexSet_HPP
23 #include "RAJA/config.hpp"
51 template<
typename... TALL>
66 template<
typename SEG_ITER_POLICY_T,
typename SEG_EXEC_POLICY_T =
void>
69 RAJA::Pattern::forall>
88 template<
typename T0,
typename... TREST>
92 static const int T0_TypeId =
sizeof...(TREST);
99 static_assert(std::is_same<value_type, typename PARENT::value_type>::value ||
101 "All segments must have the same value_type");
115 size_t num = c.data.
size();
117 for (
size_t i = 0; i < num; ++i)
139 size_t num_seg = data.size();
140 for (
size_t i = 0; i < num_seg; ++i)
157 swap(data, other.data);
158 swap(owner, other.owner);
166 template<
typename P0,
typename... PREST>
172 if (getSegmentTypes()[segid] != T0_TypeId)
175 return PARENT::compareSegmentById(segid, other);
179 if (!other.template checkSegmentType<T0>(segid))
185 Index_type offset = getSegmentOffsets()[segid];
186 return *data[offset] == other.template getSegment<T0>(segid);
189 template<
typename P0>
192 if (getSegmentTypes()[segid] == T0_TypeId)
194 return std::is_same<T0, P0>::value;
196 return PARENT::template checkSegmentType<P0>(segid);
200 template<
typename P0>
203 if (getSegmentTypes()[segid] == T0_TypeId)
205 Index_type offset = getSegmentOffsets()[segid];
206 return *
reinterpret_cast<P0 const*
>(data[offset]);
208 return PARENT::template getSegment<P0>(segid);
212 template<
typename P0>
215 if (getSegmentTypes()[segid] == T0_TypeId)
217 Index_type offset = getSegmentOffsets()[segid];
218 return *
reinterpret_cast<P0 const*
>(data[offset]);
220 return PARENT::template getSegment<P0>(segid);
225 constexpr
size_t getNumTypes()
const {
return 1 + PARENT::getNumTypes(); }
250 template<
typename... CALL>
261 segment_push_into(i, c, pend, pcopy);
268 segment_push_into(i, c, pend, pcopy);
279 template<
typename... CALL>
285 if (getSegmentTypes()[segid] != T0_TypeId)
287 PARENT::segment_push_into(segid, c, pend, pcopy);
290 Index_type offset = getSegmentOffsets()[segid];
291 switch (value_for(pend, pcopy))
294 c.push_back(*data[offset]);
297 c.push_back_nocopy(data[offset]);
300 c.push_front(*data[offset]);
303 c.push_front_nocopy(data[offset]);
309 template<
typename Tnew>
316 template<
typename Tnew>
323 template<
typename Tnew>
326 push_internal(
new typename std::decay<Tnew>::type(std::forward<Tnew>(val)),
331 template<
typename Tnew>
334 push_internal(
new typename std::decay<Tnew>::type(std::forward<Tnew>(val)),
341 size_t total = PARENT::getLength();
342 size_t num = data.size();
343 for (
size_t i = 0; i < num; ++i)
345 total += data[i]->size();
353 return data.size() + PARENT::getNumSegments();
365 template<
typename BODY,
typename... ARGS>
368 ARGS&&...
args)
const
370 if (getSegmentTypes()[segid] != T0_TypeId)
372 PARENT::segmentCall(segid, std::forward<BODY>(
body),
373 std::forward<ARGS>(
args)...);
376 Index_type offset = getSegmentOffsets()[segid];
377 body(*data[offset], std::forward<ARGS>(
args)...);
382 template<
typename Tnew>
387 static_assert(
sizeof...(TREST) > 0,
"Invalid type for this TypedIndexSet");
388 PARENT::push_internal(val, pend, pcopy);
403 getSegmentTypes().push_back(T0_TypeId);
406 getSegmentOffsets().push_back(data.size() - 1);
409 size_t icount = val->size();
410 getSegmentIcounts().push_back(getTotalLength());
411 increaseTotalLength(icount);
416 getSegmentTypes().push_front(T0_TypeId);
419 getSegmentOffsets().push_front(data.size() - 1);
422 getSegmentIcounts().push_front(0);
423 size_t icount = val->size();
424 for (
size_t i = 1; i < getSegmentIcounts().size(); ++i)
426 getSegmentIcounts()[i] += icount;
428 increaseTotalLength(icount);
441 return PARENT::increaseTotalLength(n);
470 for (
int i = minSeg; i < maxSeg; ++i)
488 int numSeg = getNumSegments();
489 for (
int i = 0; i < len; ++i)
491 if (segIds[i] >= 0 && segIds[i] < numSeg)
513 int numSeg = getNumSegments();
514 for (
auto& seg : segIds)
516 if (seg >= 0 && seg < numSeg)
527 m_seg_interval_begin[interval_id] = begin;
528 m_seg_interval_end[interval_id] = end;
534 return m_seg_interval_begin[interval_id];
540 return m_seg_interval_end[interval_id];
547 return PARENT::getSegmentTypes();
553 return PARENT::getSegmentTypes();
559 return PARENT::getSegmentOffsets();
565 return PARENT::getSegmentOffsets();
571 return PARENT::getSegmentIcounts();
577 return PARENT::getSegmentIcounts();
587 template<
typename P0,
typename... PREST>
590 size_t num_seg = getNumSegments();
591 if (num_seg != other.getNumSegments())
return false;
593 for (
size_t segid = 0; segid < num_seg; ++segid)
595 if (!compareSegmentById(segid, other))
604 template<
typename P0,
typename... PREST>
607 return (!(*
this == other));
642 segment_types = c.segment_types;
643 segment_offsets = c.segment_offsets;
644 segment_icounts = c.segment_icounts;
652 swap(segment_types, other.segment_types);
653 swap(segment_offsets, other.segment_offsets);
654 swap(segment_icounts, other.segment_icounts);
655 swap(m_len, other.m_len);
672 template<
typename BODY,
typename... ARGS>
678 return segment_types;
683 return segment_types;
688 return segment_offsets;
693 return segment_offsets;
698 return segment_icounts;
703 return segment_icounts;
712 template<
typename P0,
typename... PREST>
719 template<
typename P0>
725 template<
typename P0>
728 return *((P0*)(
this -
this));
731 template<
typename P0>
734 return *((P0*)(
this -
this));
737 template<
typename... CALL>
741 template<
typename... CALL>
748 template<
typename Tnew>
757 return segment_icounts[segid];
762 return segment_icounts[segid];
789 namespace type_traits
794 : ::RAJA::type_traits::SpecializationOf<RAJA::TypedIndexSet,
795 typename std::decay<T>::type>
800 : ::RAJA::type_traits::SpecializationOf<RAJA::ExecPolicy,
801 typename std::decay<T>::type>
Header file for RAJA iterator constructs.
Header file containing definition of RAJA list segment class.
Header file for RAJA operator definitions.
Header file for basic RAJA policy mechanics.
RAJA header file for simple vector template class that enables RAJA to be used with or without the C+...
Header file containing definitions of RAJA range segment classes.
Definition: Iterators.hpp:114
RAJA_INLINE void resize(size_type new_size)
Definition: RAJAVec.hpp:232
size_type size() const
Definition: RAJAVec.hpp:199
Class representing an index set which is a collection of segment objects.
Definition: IndexSet.hpp:90
iterator end() const
Get an iterator to the end.
Definition: IndexSet.hpp:448
RAJA_INLINE size_t getLength() const
Return total length – sum of lengths of all segments.
Definition: IndexSet.hpp:339
RAJA_INLINE bool operator!=(const TypedIndexSet< P0, PREST... > &other) const
Inequality operator returns true if any segment is not equal, else false.
Definition: IndexSet.hpp:605
RAJA_INLINE RAJA::RAJAVec< Index_type > & getSegmentIcounts()
Returns the icount of segments.
Definition: IndexSet.hpp:569
RAJA_INLINE bool operator==(const TypedIndexSet< P0, PREST... > &other) const
Definition: IndexSet.hpp:588
RAJA_INLINE P0 & getSegment(size_t segid)
get specified segment by ID
Definition: IndexSet.hpp:201
RAJA_INLINE RAJA::RAJAVec< Index_type > & getSegmentOffsets()
Returns the mapping of segment_index -> segment_offset.
Definition: IndexSet.hpp:557
int getSegmentIntervalEnd(size_t interval_id) const
get upper bound of segment identified with interval_id
Definition: IndexSet.hpp:538
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE void segmentCall(size_t segid, BODY &&body, ARGS &&... args) const
Definition: IndexSet.hpp:366
RAJA_INLINE P0 const & getSegment(size_t segid) const
get specified segment by ID
Definition: IndexSet.hpp:213
RAJA_INLINE void setTotalLength(int n)
set total length of the indexset
Definition: IndexSet.hpp:436
RAJA_INLINE TypedIndexSet(TypedIndexSet< T0, TREST... > const &c)
Copy-constructor for index set.
Definition: IndexSet.hpp:113
RAJA_INLINE void push_back_nocopy(Tnew *val)
Add segment to back end of index set without making a copy.
Definition: IndexSet.hpp:310
RAJA_INLINE void increaseTotalLength(int n)
increase the total stored size of the indexset
Definition: IndexSet.hpp:439
RAJA_INLINE RAJA::RAJAVec< Index_type > const & getSegmentIcounts() const
Returns the icount of segments.
Definition: IndexSet.hpp:575
RAJA_INLINE void push_front(Tnew &&val)
Add copy of segment to front end of index set.
Definition: IndexSet.hpp:332
TypedIndexSet< T0, TREST... > createSlice(int begin, int end)
Definition: IndexSet.hpp:464
RAJA_INLINE bool compareSegmentById(size_t segid, const TypedIndexSet< P0, PREST... > &other) const
Definition: IndexSet.hpp:167
RAJA_INLINE void push_internal(Tnew *val, PushEnd pend=PUSH_BACK, PushCopy pcopy=PUSH_COPY)
Internal logic to add a new segment – catch invalid type insertion.
Definition: IndexSet.hpp:383
RAJA_INLINE RAJA::RAJAVec< Index_type > const & getSegmentOffsets() const
Returns the mapping of segment_index -> segment_offset.
Definition: IndexSet.hpp:563
TypedIndexSet< T0, TREST... > createSlice(const T &segIds)
Definition: IndexSet.hpp:510
RAJA_INLINE void push_internal(T0 *val, PushEnd pend=PUSH_BACK, PushCopy pcopy=PUSH_COPY)
Internal logic to add a new segment.
Definition: IndexSet.hpp:392
iterator begin() const
Get an iterator to the beginning.
Definition: IndexSet.hpp:451
int getSegmentIntervalBegin(size_t interval_id) const
get lower bound of segment identified with interval_id
Definition: IndexSet.hpp:532
void swap(TypedIndexSet< T0, TREST... > &other)
Swap function for copy-and-swap idiom.
Definition: IndexSet.hpp:151
RAJA_INLINE ~TypedIndexSet()
Destroy index set including all index set segments.
Definition: IndexSet.hpp:137
RAJA_INLINE void push_front_nocopy(Tnew *val)
Add segment to front end of index set without making a copy.
Definition: IndexSet.hpp:317
RAJA_INLINE bool checkSegmentType(size_t segid) const
Definition: IndexSet.hpp:190
TypedIndexSet< T0, TREST... > & operator=(const TypedIndexSet< T0, TREST... > &rhs)
Copy-assignment operator for index set.
Definition: IndexSet.hpp:126
TypedIndexSet< T0, TREST... > createSlice(const int *segIds, int len)
Definition: IndexSet.hpp:484
RAJA_INLINE void push_back(Tnew &&val)
Add copy of segment to back end of index set.
Definition: IndexSet.hpp:324
RAJA_INLINE void segment_push_into(size_t segid, TypedIndexSet< CALL... > &c, PushEnd pend=PUSH_BACK, PushCopy pcopy=PUSH_COPY)
Definition: IndexSet.hpp:280
typename T0::value_type value_type
Definition: IndexSet.hpp:96
RAJA_INLINE RAJA::RAJAVec< Index_type > const & getSegmentTypes() const
Returns the mapping of segment_index -> segment_type.
Definition: IndexSet.hpp:551
RAJA_INLINE Index_type & getTotalLength()
Returns the number of indices (the total icount of segments.
Definition: IndexSet.hpp:433
RAJA_INLINE TypedIndexSet()
Construct empty index set.
Definition: IndexSet.hpp:106
constexpr RAJA_INLINE size_t getNumTypes() const
Returns the number of types this TypedIndexSet can store.
Definition: IndexSet.hpp:225
RAJA_INLINE RAJA::RAJAVec< Index_type > & getSegmentTypes()
Returns the mapping of segment_index -> segment_type.
Definition: IndexSet.hpp:545
void setSegmentInterval(size_t interval_id, int begin, int end)
Set [begin, end) interval of segments identified by interval_id.
Definition: IndexSet.hpp:525
constexpr RAJA_INLINE size_t getNumSegments() const
Return total number of segments in index set.
Definition: IndexSet.hpp:351
Index_type size() const
Return the number of elements in the range.
Definition: IndexSet.hpp:454
RAJA_INLINE RAJA::RAJAVec< Index_type > & getSegmentIcounts()
Definition: IndexSet.hpp:696
RAJA_INLINE RAJA::RAJAVec< Index_type > const & getSegmentTypes() const
Definition: IndexSet.hpp:681
RAJA_INLINE P0 const & getSegment(size_t) const
Definition: IndexSet.hpp:732
RAJA_INLINE void increaseTotalLength(int n)
Definition: IndexSet.hpp:710
static RAJA_INLINE size_t getNumTypes()
Definition: IndexSet.hpp:659
RAJA_INLINE P0 & getSegment(size_t)
Definition: IndexSet.hpp:726
constexpr RAJA_INLINE bool isValidSegmentType(T const &) const
Definition: IndexSet.hpp:662
RAJA_INLINE void segment_push_into(size_t, TypedIndexSet< CALL... > &, PushEnd, PushCopy) const
Definition: IndexSet.hpp:742
RAJA_INLINE int getStartingIcount(int segid)
Definition: IndexSet.hpp:755
RAJA_INLINE RAJA::RAJAVec< Index_type > const & getSegmentOffsets() const
Definition: IndexSet.hpp:691
RAJA::Index_type value_type
Definition: IndexSet.hpp:629
iterator begin() const
Get an iterator to the beginning.
Definition: IndexSet.hpp:769
RAJA_INLINE Index_type & getTotalLength()
Definition: IndexSet.hpp:706
RAJA_INLINE void setTotalLength(int n)
Definition: IndexSet.hpp:708
RAJA_INLINE RAJA::RAJAVec< Index_type > const & getSegmentIcounts() const
Definition: IndexSet.hpp:701
static RAJA_INLINE size_t getLength()
Definition: IndexSet.hpp:670
RAJA_INLINE void push_into(TypedIndexSet< CALL... > &, PushEnd, PushCopy) const
Definition: IndexSet.hpp:738
RAJA_INLINE int getStartingIcount(int segid) const
Definition: IndexSet.hpp:760
RAJA_INLINE RAJA::RAJAVec< Index_type > & getSegmentTypes()
Definition: IndexSet.hpp:676
void swap(TypedIndexSet &other)
Swap function for copy-and-swap idiom (deep copy).
Definition: IndexSet.hpp:649
RAJA_INLINE void push(Tnew const &, PushEnd, PushCopy)
Definition: IndexSet.hpp:749
RAJA_INLINE TypedIndexSet()
create empty TypedIndexSet
Definition: IndexSet.hpp:632
RAJA_INLINE TypedIndexSet(TypedIndexSet const &c)
Copy-constructor.
Definition: IndexSet.hpp:640
iterator end() const
Get an iterator to the end.
Definition: IndexSet.hpp:766
static RAJA_INLINE int getNumSegments()
Definition: IndexSet.hpp:668
RAJA_INLINE bool compareSegmentById(size_t, const TypedIndexSet< P0, PREST... > &) const
Definition: IndexSet.hpp:713
RAJA_INLINE ~TypedIndexSet()
dtor cleans up segements that we own (none)
Definition: IndexSet.hpp:636
RAJA_INLINE void segmentCall(size_t, BODY, ARGS...) const
Definition: IndexSet.hpp:673
RAJA_INLINE RAJA::RAJAVec< Index_type > & getSegmentOffsets()
Definition: IndexSet.hpp:686
Index_type size() const
Return the number of elements in the range.
Definition: IndexSet.hpp:772
RAJA_INLINE bool checkSegmentType(size_t) const
Definition: IndexSet.hpp:720
Definition: IndexSet.hpp:52
Header file for RAJA concept definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_SUPPRESS_HD_WARN
Definition: macros.hpp:68
Args args
Definition: WorkRunner.hpp:212
Definition: AlignedRangeIndexSetBuilders.cpp:35
std::ptrdiff_t Index_type
Definition: types.hpp:226
auto & body
Definition: launch.hpp:177
PushEnd
Definition: IndexSet.hpp:40
@ PUSH_FRONT
Definition: IndexSet.hpp:41
@ PUSH_BACK
Definition: IndexSet.hpp:42
PushCopy
Definition: IndexSet.hpp:46
@ PUSH_COPY
Definition: IndexSet.hpp:47
@ PUSH_NOCOPY
Definition: IndexSet.hpp:48
RAJA_INLINE void swap(RAJA::TypedListSegment< StorageT > &a, RAJA::TypedListSegment< StorageT > &b)
Specialization of std::swap for TypedListSegment.
Definition: ListSegment.hpp:420
Definition: PolicyBase.hpp:75
Definition: Operators.hpp:580
Definition: Operators.hpp:559
Definition: IndexSet.hpp:70
SEG_EXEC_POLICY_T seg_exec
Definition: IndexSet.hpp:72
SEG_ITER_POLICY_T seg_it
Definition: IndexSet.hpp:71
Definition: IndexSet.hpp:796
Definition: IndexSet.hpp:802