1 #ifndef AMREX_MF_PARALLEL_FOR_G_H_
2 #define AMREX_MF_PARALLEL_FOR_G_H_
3 #include <AMReX_Config.H>
18 if (!ncells.empty()) {
19 const int nboxes = ncells.
size();
21 const std::size_t nbytes = nbytes_boxes + nboxes*
sizeof(
BoxIndexer);
23 int* hp_blks = (
int*)a_hp;
24 auto* hp_boxes = (
BoxIndexer*)(a_hp + nbytes_boxes);
26 bool same_size =
true;
27 for (
int i = 0; i < nboxes; ++i) {
28 Long nblocks = (ncells[i] + nthreads-1) / nthreads;
30 hp_blks[i+1] = hp_blks[i] +
static_cast<int>(nblocks);
31 same_size = same_size && (ncells[i] == ncells[0]);
39 blocks_x.first = hp_blks;
40 blocks_x.second = (same_size) ?
nullptr : (
int*)a_dp;
53 namespace experimental::detail {
55 namespace parfor_mf_detail {
58 auto call_f (F
const&
f,
int b,
int i,
int j,
int k,
int) noexcept
59 -> decltype(
f(0,0,0,0))
66 auto call_f (F
const&
f,
int b,
int i,
int j,
int k,
int n) noexcept
67 -> decltype(
f(0,0,0,0,0))
73 template <
int MT,
typename MF,
typename F>
74 std::enable_if_t<IsFabArray<MF>::value>
77 const auto& index_array = mf.IndexArray();
78 const int nboxes = index_array.size();
82 }
else if (nboxes == 1) {
89 auto const& parforinfo = mf.getParForInfo(nghost,MT);
90 auto par_for_blocks = parforinfo.getBlocks();
91 const int nblocks = par_for_blocks.first[nboxes];
92 const int block_0_size = par_for_blocks.first[1];
93 const int* dp_nblocks = par_for_blocks.second;
94 const BoxIndexer* dp_boxes = parforinfo.getBoxes();
96 #if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
98 amrex::launch_global<MT>
105 ibox =
amrex::bisect(dp_nblocks, 0, nboxes,
static_cast<int>(blockIdx.x));
106 icell = std::uint64_t(blockIdx.x-dp_nblocks[ibox])*MT + threadIdx.x;
108 ibox = blockIdx.x / block_0_size;
109 icell = std::uint64_t(blockIdx.x-ibox*block_0_size)*MT + threadIdx.x;
112 #elif defined(AMREX_USE_SYCL)
119 int blockIdxx = item.get_group_linear_id();
120 int threadIdxx = item.get_local_linear_id();
122 ibox =
amrex::bisect(dp_nblocks, 0, nboxes,
static_cast<int>(blockIdxx));
123 icell = std::uint64_t(blockIdxx-dp_nblocks[ibox])*MT + threadIdxx;
125 ibox = blockIdxx / block_0_size;
126 icell = std::uint64_t(blockIdxx-ibox*block_0_size)*MT + threadIdxx;
130 if (icell < indexer.
numPts()) {
131 auto [i, j, k] = indexer(icell);
132 for (
int n = 0; n < ncomp; ++n) {
141 template <
typename MF,
typename F>
142 std::enable_if_t<IsFabArray<MF>::value>
145 ParallelFor<AMREX_GPU_MAX_THREADS>(mf, nghost, ncomp, ts, dynamic, std::forward<F>(
f));
148 template <
typename MF,
typename F>
149 std::enable_if_t<IsFabArray<MF>::value>
152 ParallelFor<AMREX_GPU_MAX_THREADS>(mf, nghost, 1, ts, dynamic, std::forward<F>(
f));
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_GPU_ERROR_CHECK()
Definition: AMReX_GpuError.H:125
#define AMREX_GPU_DEVICE
Definition: AMReX_GpuQualifiers.H:18
virtual void free(void *pt)=0
A pure virtual function for deleting the arena pointed to by pt.
virtual void * alloc(std::size_t sz)=0
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
Long size() const noexcept
Definition: AMReX_Vector.H:50
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition: AMReX_GpuDevice.H:251
gpuStream_t gpuStream() noexcept
Definition: AMReX_GpuDevice.H:218
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
void build_par_for_nblocks(char *&a_hp, char *&a_dp, std::pair< int *, int * > &blocks_x, BoxIndexer *&pboxes, Vector< Box > const &boxes, Vector< Long > const &ncells, int nthreads)
Definition: AMReX_MFParallelForG.H:15
void destroy_par_for_nblocks(char *hp, char *dp)
Definition: AMReX_MFParallelForG.H:46
AMREX_GPU_DEVICE auto call_f(F const &f, int b, int i, int j, int k, int) noexcept -> decltype(f(0, 0, 0, 0))
Definition: AMReX_MFParallelForG.H:58
std::enable_if_t< IsFabArray< MF >::value > ParallelFor(MF const &mf, IntVect const &nghost, int ncomp, IntVect const &, bool, F const &f)
Definition: AMReX_MFParallelForG.H:75
Definition: AMReX_Amr.cpp:49
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition: AMReX_CTOParallelForImpl.H:200
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Grow BoxND in all directions by given amount.
Definition: AMReX_Box.H:1211
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T bisect(T lo, T hi, F f, T tol=1e-12, int max_iter=100)
Definition: AMReX_Algorithm.H:105
BoxIndexerND< AMREX_SPACEDIM > BoxIndexer
Definition: AMReX_Box.H:2099
Arena * The_Pinned_Arena()
Definition: AMReX_Arena.cpp:649
std::size_t aligned_size(std::size_t align_requirement, std::size_t size) noexcept
Given a minimum required size of size bytes, this returns the next largest arena size that will align...
Definition: AMReX_Arena.H:30
Arena * The_Arena()
Definition: AMReX_Arena.cpp:609
Definition: AMReX_FabArrayCommI.H:841
integer, parameter dp
Definition: AMReX_SDCquadrature.F90:8
Definition: AMReX_Box.H:2027
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint64_t numPts() const
Definition: AMReX_Box.H:2068