Block-Structured AMR Software Framework
AMReX_BinIterator.H
Go to the documentation of this file.
1 #ifndef AMREX_BINITERATOR_H_
2 #define AMREX_BINITERATOR_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Gpu.H>
6 
7 #include <utility>
8 
9 namespace amrex
10 {
11 
12 template< class T >
13 constexpr decltype(T::is_particle_tile_data) IsParticleTileData () { // NOLINT(readability-const-return-type)
14  return T::is_particle_tile_data;
15 }
16 
17 template< class T, class...Args >
18 constexpr bool IsParticleTileData (Args...) {
19  return false;
20 }
21 
22 template <typename T>
24 {
25  using index_type = int;
26 
27  using const_pointer_type = std::conditional_t<IsParticleTileData<T>(),
28  T,
29  const T*
30  >;
31 
32  using const_pointer_input_type = std::conditional_t<IsParticleTileData<T>(),
33  const T&,
34  const T*
35  >;
36 
37  struct iterator
38  {
41  const index_type* a_perm, const_pointer_input_type a_items)
42  : m_items(a_items), m_perm(a_perm), m_index(start), m_stop(stop)
43  {}
44 
46  void operator++ () { ++m_index;; }
47 
48  [[nodiscard]] AMREX_GPU_HOST_DEVICE
49  bool operator!= (iterator const& /*rhs*/) const { return m_index < m_stop; }
50 
51  [[nodiscard]] AMREX_GPU_HOST_DEVICE
52  auto operator* () const
53  {
54  return std::make_pair(m_perm[m_index], m_items[m_perm[m_index]]);
55  }
56 
57  private:
62  };
63 
64  [[nodiscard]] AMREX_GPU_HOST_DEVICE
65  iterator begin () const
66  {
67  if (m_i == m_not_found) {
68  return iterator(0, 0, m_permutation_ptr, m_items);
69  }
71  }
72 
73  [[nodiscard]] AMREX_GPU_HOST_DEVICE
74  iterator end () const {
75  if (m_i == m_not_found) {
76  return iterator(0, 0, m_permutation_ptr, m_items);
77  }
79  }
80 
82  BinIterator (index_type i, const index_type *offsets_ptr,
83  const index_type *permutation_ptr, const_pointer_input_type items)
84  : m_i(i), m_offsets_ptr(offsets_ptr), m_permutation_ptr(permutation_ptr), m_items(items)
85  {}
86 
87 private:
92 
94 };
95 
96 }
97 
98 #endif
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
@ max
Definition: AMReX_ParallelReduce.H:17
Definition: AMReX_Amr.cpp:49
constexpr decltype(T::is_particle_tile_data) IsParticleTileData()
Definition: AMReX_BinIterator.H:13
const int[]
Definition: AMReX_BLProfiler.cpp:1664
Definition: AMReX_BinIterator.H:38
AMREX_GPU_HOST_DEVICE bool operator!=(iterator const &) const
Definition: AMReX_BinIterator.H:49
index_type m_stop
Definition: AMReX_BinIterator.H:61
const_pointer_type m_items
Definition: AMReX_BinIterator.H:58
AMREX_GPU_HOST_DEVICE void operator++()
Definition: AMReX_BinIterator.H:46
AMREX_GPU_HOST_DEVICE iterator(index_type start, index_type stop, const index_type *a_perm, const_pointer_input_type a_items)
Definition: AMReX_BinIterator.H:40
AMREX_GPU_HOST_DEVICE auto operator*() const
Definition: AMReX_BinIterator.H:52
const index_type * m_perm
Definition: AMReX_BinIterator.H:59
index_type m_index
Definition: AMReX_BinIterator.H:60
Definition: AMReX_BinIterator.H:24
const_pointer_type m_items
Definition: AMReX_BinIterator.H:91
int index_type
Definition: AMReX_BinIterator.H:25
AMREX_GPU_HOST_DEVICE iterator end() const
Definition: AMReX_BinIterator.H:74
const index_type * m_offsets_ptr
Definition: AMReX_BinIterator.H:89
AMREX_GPU_HOST_DEVICE BinIterator(index_type i, const index_type *offsets_ptr, const index_type *permutation_ptr, const_pointer_input_type items)
Definition: AMReX_BinIterator.H:82
std::conditional_t< IsParticleTileData< T >(), T, const T * > const_pointer_type
Definition: AMReX_BinIterator.H:30
AMREX_GPU_HOST_DEVICE iterator begin() const
Definition: AMReX_BinIterator.H:65
const index_type * m_permutation_ptr
Definition: AMReX_BinIterator.H:90
static constexpr index_type m_not_found
Definition: AMReX_BinIterator.H:93
std::conditional_t< IsParticleTileData< T >(), const T &, const T * > const_pointer_input_type
Definition: AMReX_BinIterator.H:35
index_type m_i
Definition: AMReX_BinIterator.H:88