1#ifndef AMREX_MF_PARALLEL_FOR_G_H_
2#define AMREX_MF_PARALLEL_FOR_G_H_
3#include <AMReX_Config.H>
14namespace amrex::detail {
17void build_par_for_boxes (
char*& hp,
BoxIndexer*& pboxes, Vector<Box>
const& boxes)
19 if (boxes.empty()) {
return; }
20 const int nboxes = boxes.size();
21 const std::size_t nbytes = nboxes*
sizeof(
BoxIndexer);
24 for (
int i = 0; i < nboxes; ++i) {
34void destroy_par_for_boxes (
char* hp,
char* dp)
46namespace parfor_mf_detail {
49 auto call_f (F
const& f,
int b,
int i,
int j,
int k,
int)
noexcept
50 ->
decltype(f(0,0,0,0))
57 auto call_f (F
const& f,
int b,
int i,
int j,
int k,
int ncomp)
noexcept
58 ->
decltype(f(0,0,0,0,0))
60 for (
int n = 0; n < ncomp; ++n) {
66template <
int MT, FabArrayType MF,
typename F>
68ParallelFor_doit (MF
const& mf,
IntVect const& nghost,
int ncomp,
IntVect const&,
bool,
F const& f)
70 const auto& index_array = mf.IndexArray();
71 const int nboxes = index_array.size();
75 }
else if (nboxes == 1) {
79 parfor_mf_detail::call_f(f, 0, i, j, k, ncomp);
82 auto const& parforinfo = mf.getParForInfo(nghost);
83 auto nblocks_per_box = parforinfo.getNBlocksPerBox(MT);
85 const int nblocks = nblocks_per_box * nboxes;
86 const BoxIndexer* dp_boxes = parforinfo.getBoxes();
88#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
90 amrex::launch_global<MT>
94 int ibox =
int(blockIdx.x) / nblocks_per_box;
95 auto icell = std::uint64_t(blockIdx.x-ibox*nblocks_per_box)*MT + threadIdx.x;
97#elif defined(AMREX_USE_SYCL)
102 int blockIdxx = item.get_group_linear_id();
103 int threadIdxx = item.get_local_linear_id();
104 int ibox =
int(blockIdxx) / nblocks_per_box;
105 auto icell = std::uint64_t(blockIdxx-ibox*nblocks_per_box)*MT + threadIdxx;
108 if (icell < indexer.numPts()) {
109 auto [i, j, k] = indexer(icell);
110 parfor_mf_detail::call_f(f, ibox, i, j, k, ncomp);
117template <FabArrayType MF,
typename F>
119ParallelFor_doit (MF
const& mf,
IntVect const& nghost,
int ncomp,
IntVect const& ts,
bool dynamic,
F&& f)
122 constexpr int MT = 128;
124 constexpr int MT = AMREX_GPU_MAX_THREADS;
126 ParallelFor_doit<MT>(mf, nghost, ncomp, ts, dynamic, std::forward<F>(f));
129template <FabArrayType MF,
typename F>
131ParallelFor_doit (MF
const& mf,
IntVect const& nghost,
IntVect const& ts,
bool dynamic,
F&& f)
134 constexpr int MT = 128;
136 constexpr int MT = AMREX_GPU_MAX_THREADS;
138 ParallelFor_doit<MT>(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:151
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
virtual void * alloc(std::size_t sz)=0
Allocate sz bytes from this arena.
amrex_long Long
Definition AMReX_INT.H:30
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1326
Arena * The_Pinned_Arena()
Definition AMReX_Arena.cpp:855
Arena * The_Arena()
Definition AMReX_Arena.cpp:815
void freeAsync(Arena *arena, void *mem) noexcept
Definition AMReX_GpuDevice.H:345
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:421
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:291
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
BoxIndexerND< 3 > BoxIndexer
Definition AMReX_Box.H:2608
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
const int[]
Definition AMReX_BLProfiler.cpp:1665