Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MFParallelFor.H
Go to the documentation of this file.
1#ifndef AMREX_MF_PARALLEL_FOR_H_
2#define AMREX_MF_PARALLEL_FOR_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Concepts.H>
7#include <AMReX_TypeTraits.H>
8
9#ifdef AMREX_USE_GPU
11#else
13#endif
14
15namespace amrex {
16
17struct TileSize {
19 explicit TileSize (IntVect const& ts) noexcept : tile_size(ts) {}
20};
21
23 bool dynamic;
24 explicit DynamicTiling (bool f) noexcept : dynamic(f) {}
25};
26
42template <FabArrayType MF, typename F>
43void
44ParallelFor (MF const& mf, F&& f)
45{
46 detail::ParallelFor_doit(mf, IntVect(0), FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
47}
48
65template <int MT, FabArrayType MF, typename F>
66void
67ParallelFor (MF const& mf, F&& f)
68{
69#ifdef AMREX_USE_GPU
70 detail::ParallelFor_doit<MT>(mf, IntVect(0), 1, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
71#else
72 detail::ParallelFor_doit(mf, IntVect(0), FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
73#endif
74}
75
92template <FabArrayType MF, typename F>
93void
94ParallelFor (MF const& mf, IntVect const& ng, F&& f)
95{
96 detail::ParallelFor_doit(mf, ng, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
97}
98
116template <int MT, FabArrayType MF, typename F>
117void
118ParallelFor (MF const& mf, IntVect const& ng, F&& f)
119{
120#ifdef AMREX_USE_GPU
121 detail::ParallelFor_doit<MT>(mf, ng, 1, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
122#else
123 detail::ParallelFor_doit(mf, ng, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
124#endif
125}
126
144template <FabArrayType MF, typename F>
145void
146ParallelFor (MF const& mf, IntVect const& ng, int ncomp, F&& f)
147{
148 detail::ParallelFor_doit(mf, ng, ncomp, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
149}
150
169template <int MT, FabArrayType MF, typename F>
170void
171ParallelFor (MF const& mf, IntVect const& ng, int ncomp, F&& f)
172{
173#ifdef AMREX_USE_GPU
174 detail::ParallelFor_doit<MT>(mf, ng, ncomp, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
175#else
176 detail::ParallelFor_doit(mf, ng, ncomp, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
177#endif
178}
179
197template <FabArrayType MF, typename F>
198void
199ParallelFor (MF const& mf, TileSize const& ts, F&& f)
200{
201 detail::ParallelFor_doit(mf, IntVect(0), ts.tile_size, false, std::forward<F>(f));
202}
203
222template <int MT, FabArrayType MF, typename F>
223void
224ParallelFor (MF const& mf, TileSize const& ts, F&& f)
225{
226#ifdef AMREX_USE_GPU
227 detail::ParallelFor_doit<MT>(mf, IntVect(0), 1, ts.tile_size, false, std::forward<F>(f));
228#else
229 detail::ParallelFor_doit(mf, IntVect(0), ts.tile_size, false, std::forward<F>(f));
230#endif
231}
232
251template <FabArrayType MF, typename F>
252void
253ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts, F&& f)
254{
255 detail::ParallelFor_doit(mf, ng, ts.tile_size, false, std::forward<F>(f));
256}
257
277template <int MT, FabArrayType MF, typename F>
278void
279ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts, F&& f)
280{
281#ifdef AMREX_USE_GPU
282 detail::ParallelFor_doit<MT>(mf, ng, 1, ts.tile_size, false, std::forward<F>(f));
283#else
284 detail::ParallelFor_doit(mf, ng, ts.tile_size, false, std::forward<F>(f));
285#endif
286}
287
307template <FabArrayType MF, typename F>
308void
309ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts, F&& f)
310{
311 detail::ParallelFor_doit(mf, ng, ncomp, ts.tile_size, false, std::forward<F>(f));
312}
313
334template <int MT, FabArrayType MF, typename F>
335void
336ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts, F&& f)
337{
338#ifdef AMREX_USE_GPU
339 detail::ParallelFor_doit<MT>(mf, ng, ncomp, ts.tile_size, false, std::forward<F>(f));
340#else
341 detail::ParallelFor_doit(mf, ng, ncomp, ts.tile_size, false, std::forward<F>(f));
342#endif
343}
344
364template <FabArrayType MF, typename F>
365void
366ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts, DynamicTiling dt, F&& f)
367{
368 detail::ParallelFor_doit(mf, ng, ts.tile_size, dt.dynamic, std::forward<F>(f));
369}
370
391template <FabArrayType MF, typename F>
392void
393ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts,
394 DynamicTiling dt, F&& f)
395{
396 detail::ParallelFor_doit(mf, ng, ncomp, ts.tile_size, dt.dynamic, std::forward<F>(f));
397}
398
419template <int MT, FabArrayType MF, typename F>
420void
421ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts,
422 DynamicTiling dt, F&& f)
423{
424#ifdef AMREX_USE_GPU
425 detail::ParallelFor_doit<MT>(mf, ng, 1, ts.tile_size, dt.dynamic, std::forward<F>(f));
426#else
427 detail::ParallelFor_doit(mf, ng, ts.tile_size, dt.dynamic, std::forward<F>(f));
428#endif
429}
430
452template <int MT, FabArrayType MF, typename F>
453void
454ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts,
455 DynamicTiling dt, F&& f)
456{
457#ifdef AMREX_USE_GPU
458 detail::ParallelFor_doit<MT>(mf, ng, ncomp, ts.tile_size, dt.dynamic, std::forward<F>(f));
459#else
460 detail::ParallelFor_doit(mf, ng, ncomp, ts.tile_size, dt.dynamic, std::forward<F>(f));
461#endif
462}
463
470[[nodiscard]] constexpr IntVect multicolor_offset (int color) noexcept
471{
472 return IntVect(AMREX_D_DECL(color&1, (color>>1)&1, (color>>2)&1));
473}
474
495template <FabArrayType MF, typename F>
496void
497ParallelForStrided (MF const& mf, IntVect const& stride, IntVect const& offset, F&& f)
498{
499 AMREX_ASSERT(stride.allGT(0));
500 // Equivalent offsets share one cached ParForInfo.
501 IntVect o;
502 for (int d = 0; d < AMREX_SPACEDIM; ++d) {
503 o[d] = ((offset[d] % stride[d]) + stride[d]) % stride[d];
504 }
505 detail::ParallelForStrided_doit(mf, stride, o, std::forward<F>(f));
506}
507
527template <FabArrayType MF, typename F>
528void
529ParallelForRedBlack (MF const& mf, int redblack, F&& f)
530{
531 detail::ParallelForRedBlack_doit(mf, redblack, std::forward<F>(f));
532}
533
546template <FabArrayType MF, typename F>
547void
548ParallelForRedBlack (MF const& mf, int ncomp, int redblack, F const& f)
549{
550 if (ncomp == 1) {
551 detail::ParallelForRedBlack_doit(mf, redblack,
552 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
553 {
554 f(box_no, i, j, k, 0);
555 });
556 } else {
557 detail::ParallelForRedBlack_doit(mf, redblack,
558 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
559 {
560 for (int n = 0; n < ncomp; ++n) {
561 f(box_no, i, j, k, n);
562 }
563 });
564 }
565}
566
567}
568
569#endif
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Common infrastructure shared by FabArray specializations.
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1139
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
static IntVect mfiter_tile_size
Default tilesize in MFIter.
Definition AMReX_FabArrayBase.H:306
__host__ __device__ constexpr bool allGT(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than argument for all components. NOTE: This is NOT a strict weak ord...
Definition AMReX_IntVect.H:517
Definition AMReX_Amr.cpp:50
void ParallelForRedBlack(MF const &mf, int redblack, F &&f)
ParallelFor over the red or black points of the valid region of a MultiFab/FabArray.
Definition AMReX_MFParallelFor.H:529
constexpr IntVect multicolor_offset(int color) noexcept
Index offset of one color of a multi-color sweep.
Definition AMReX_MFParallelFor.H:470
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
void ParallelForStrided(MF const &mf, IntVect const &stride, IntVect const &offset, F &&f)
ParallelFor over a strided subset of the valid region of a MultiFab/FabArray.
Definition AMReX_MFParallelFor.H:497
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
Definition AMReX_MFParallelFor.H:22
DynamicTiling(bool f) noexcept
Definition AMReX_MFParallelFor.H:24
bool dynamic
Definition AMReX_MFParallelFor.H:23
Definition AMReX_MFParallelFor.H:17
TileSize(IntVect const &ts) noexcept
Definition AMReX_MFParallelFor.H:19
IntVect tile_size
Definition AMReX_MFParallelFor.H:18