1 #ifndef AMREX_SPARSEBINS_H_
2 #define AMREX_SPARSEBINS_H_
3 #include <AMReX_Config.H>
48 if (
m_bins_ptr[lo] == bin_number) {
return lo; }
49 if (
m_bins_ptr[hi] == bin_number) {
return hi; }
53 if (mid_value == bin_number) {
return mid; }
55 mid_value < bin_number ? lo = mid+1 : hi = mid;
123 template <
typename N,
typename F>
131 std::map<index_type, index_type> bins_map;
132 const auto lo =
lbound(bx);
133 const auto hi =
ubound(bx);
134 for (
int i = 0; i < nitems; ++i)
137 auto iv3 = iv.
dim3();
138 int nx = hi.
x-lo.x+1;
139 int ny = hi.y-lo.y+1;
140 int nz = hi.z-lo.z+1;
144 host_cells[i] = (uix * ny + uiy) * nz + uiz;
145 bins_map[host_cells[i]] += 1;
149 std::iota(host_perm.
begin(), host_perm.
end(), 0);
150 std::sort(host_perm.
begin(), host_perm.
end(),
151 [&](
int i,
int j) {return host_cells[i] < host_cells[j];});
155 for (
const auto& kv : bins_map)
#define BL_PROFILE(a)
Definition: AMReX_BLProfiler.H:551
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 dim3() const noexcept
Definition: AMReX_IntVect.H:163
Definition: AMReX_PODVector.H:246
size_type size() const noexcept
Definition: AMReX_PODVector.H:575
T & back() noexcept
Definition: AMReX_PODVector.H:589
iterator begin() noexcept
Definition: AMReX_PODVector.H:601
iterator end() noexcept
Definition: AMReX_PODVector.H:605
void push_back(const T &a_value)
Definition: AMReX_PODVector.H:556
A container for storing items in a set of bins using "sparse" storage.
Definition: AMReX_SparseBins.H:95
Gpu::DeviceVector< index_type > m_perm
Definition: AMReX_SparseBins.H:209
index_type * permutationPtr() noexcept
returns the pointer to the permutation array
Definition: AMReX_SparseBins.H:180
index_type * getNonZeroBinsPtr() noexcept
returns the pointer to the array of non-zero bins
Definition: AMReX_SparseBins.H:186
const index_type * permutationPtr() const noexcept
returns const pointer to the permutation array
Definition: AMReX_SparseBins.H:189
std::conditional_t< IsParticleTileData< T >(), T, const T * > const_pointer_type
Definition: AMReX_SparseBins.H:105
SparseBinIteratorFactory< T > getBinIteratorFactory() const noexcept
returns a GPU-capable object that can create iterators over the items in a bin.
Definition: AMReX_SparseBins.H:198
const index_type * getNonZeroBinsPtr() const noexcept
returns the pointer to the array of non-zero bins
Definition: AMReX_SparseBins.H:195
Gpu::DeviceVector< index_type > m_offsets
Definition: AMReX_SparseBins.H:208
const index_type * offsetsPtr() const noexcept
returns const pointer to the offsets array
Definition: AMReX_SparseBins.H:192
Long numItems() const noexcept
the number of items in the container
Definition: AMReX_SparseBins.H:174
index_type * offsetsPtr() noexcept
returns the pointer to the offsets array
Definition: AMReX_SparseBins.H:183
int index_type
Definition: AMReX_SparseBins.H:100
Long numBins() const noexcept
the number of bins in the container
Definition: AMReX_SparseBins.H:177
std::conditional_t< IsParticleTileData< T >(), const T &, const T * > const_pointer_input_type
Definition: AMReX_SparseBins.H:110
void build(N nitems, const_pointer_input_type v, const Box &bx, F const &f)
Populate the bins with a set of items.
Definition: AMReX_SparseBins.H:124
const_pointer_type m_items
Definition: AMReX_SparseBins.H:205
Gpu::DeviceVector< index_type > m_bins
Definition: AMReX_SparseBins.H:207
AMREX_GPU_HOST_DEVICE Long size(T const &b) noexcept
integer version
Definition: AMReX_GpuRange.H:26
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition: AMReX_GpuContainers.H:233
static constexpr HostToDevice hostToDevice
Definition: AMReX_GpuContainers.H:98
void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.H:237
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
@ max
Definition: AMReX_ParallelReduce.H:17
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
const int[]
Definition: AMReX_BLProfiler.cpp:1664
Definition: AMReX_BinIterator.H:24
int x
Definition: AMReX_Dim3.H:12
Definition: AMReX_SparseBins.H:15
const_pointer_type m_items
Definition: AMReX_SparseBins.H:71
index_type m_num_bins
Definition: AMReX_SparseBins.H:72
SparseBinIteratorFactory(const Gpu::DeviceVector< index_type > &bins, const Gpu::DeviceVector< index_type > &offsets, const Gpu::DeviceVector< index_type > &permutation, const_pointer_input_type items)
Definition: AMReX_SparseBins.H:29
const index_type * m_permutation_ptr
Definition: AMReX_SparseBins.H:70
static constexpr index_type m_not_found
Definition: AMReX_SparseBins.H:74
std::conditional_t< IsParticleTileData< T >(), T, const T * > const_pointer_type
Definition: AMReX_SparseBins.H:22
std::conditional_t< IsParticleTileData< T >(), const T &, const T * > const_pointer_input_type
Definition: AMReX_SparseBins.H:27
const index_type * m_offsets_ptr
Definition: AMReX_SparseBins.H:69
int index_type
Definition: AMReX_SparseBins.H:17
AMREX_GPU_HOST_DEVICE index_type getIndex(const index_type bin_number) const noexcept
Definition: AMReX_SparseBins.H:40
const index_type * m_bins_ptr
Definition: AMReX_SparseBins.H:68
AMREX_GPU_HOST_DEVICE BinIterator< T > getBinIterator(const index_type bin_number) const noexcept
Definition: AMReX_SparseBins.H:62