Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MFParallelForC.H
Go to the documentation of this file.
1#ifndef AMREX_MF_PARALLEL_FOR_C_H_
2#define AMREX_MF_PARALLEL_FOR_C_H_
3#include <AMReX_Config.H>
4
5#ifndef AMREX_USE_GPU
6
7#include <AMReX_Concepts.H>
8#include <AMReX_MFIter.H>
9
11namespace amrex::detail {
12
13template <FabArrayType MF, typename F>
14void ParallelFor_doit (MF const& mf, IntVect const& nghost, IntVect const& ts, bool dynamic, F const& f)
15{
16#ifdef AMREX_USE_OMP
17#pragma omp parallel
18#endif
19 for (MFIter mfi(mf,MFItInfo().EnableTiling(ts).SetDynamic(dynamic)); mfi.isValid(); ++mfi) {
20 Box const& bx = mfi.growntilebox(nghost);
21 int const lidx = mfi.LocalIndex();
22 const auto lo = amrex::lbound(bx);
23 const auto hi = amrex::ubound(bx);
24 for ( int k = lo.z; k <= hi.z; ++k) {
25 for ( int j = lo.y; j <= hi.y; ++j) {
27 for (int i = lo.x; i <= hi.x; ++i) {
28 f(lidx,i,j,k);
29 }
30 }
31 }
32 }
33}
34
35template <FabArrayType MF, typename F>
36void ParallelFor_doit (MF const& mf, IntVect const& nghost, int ncomp, IntVect const& ts, bool dynamic, F const& f)
37{
38#ifdef AMREX_USE_OMP
39#pragma omp parallel
40#endif
41 for (MFIter mfi(mf,MFItInfo().EnableTiling(ts).SetDynamic(dynamic)); mfi.isValid(); ++mfi) {
42 Box const& bx = mfi.growntilebox(nghost);
43 int const lidx = mfi.LocalIndex();
44 const auto lo = amrex::lbound(bx);
45 const auto hi = amrex::ubound(bx);
46 for (int n = 0; n < ncomp; ++n) {
47 for ( int k = lo.z; k <= hi.z; ++k) {
48 for ( int j = lo.y; j <= hi.y; ++j) {
50 for (int i = lo.x; i <= hi.x; ++i) {
51 f(lidx,i,j,k,n);
52 }
53 }
54 }
55 }
56 }
57}
58
59template <FabArrayType MF, typename F>
60void ParallelForStrided_doit (MF const& mf, IntVect const& stride, IntVect const& offset, F const& f)
61{
62 const Dim3 s = stride.dim3(1);
63#ifdef AMREX_USE_OMP
64#pragma omp parallel
65#endif
66 for (MFIter mfi(mf,MFItInfo().EnableTiling(FabArrayBase::mfiter_tile_size)); mfi.isValid(); ++mfi) {
67 Box const& bx = mfi.tilebox();
68 int const lidx = mfi.LocalIndex();
69 const auto lo = amrex::lbound(strided_box(bx, stride, offset));
70 const auto hi = amrex::ubound(bx);
71 for ( int k = lo.z; k <= hi.z; k += s.z) {
72 for ( int j = lo.y; j <= hi.y; j += s.y) {
73 for (int i = lo.x; i <= hi.x; i += s.x) {
74 f(lidx,i,j,k);
75 }
76 }
77 }
78 }
79}
80
81template <FabArrayType MF, typename F>
82void ParallelForRedBlack_doit (MF const& mf, int redblack, F const& f)
83{
84#ifdef AMREX_USE_OMP
85#pragma omp parallel
86#endif
87 for (MFIter mfi(mf,MFItInfo().EnableTiling(FabArrayBase::mfiter_tile_size)); mfi.isValid(); ++mfi) {
88 Box const& bx = mfi.tilebox();
89 int const lidx = mfi.LocalIndex();
90 const auto lo = amrex::lbound(bx);
91 const auto hi = amrex::ubound(bx);
92 for ( int k = lo.z; k <= hi.z; ++k) {
93 for ( int j = lo.y; j <= hi.y; ++j) {
94 for (int i = lo.x + ((lo.x+j+k+redblack) & 1); i <= hi.x; i += 2) {
95 f(lidx,i,j,k);
96 }
97 }
98 }
99 }
100}
101
102}
104
105#endif
106#endif
#define AMREX_PRAGMA_SIMD
Definition AMReX_Extension.H:85
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1139
GpuArray< MultiArray4< Real const >, 3 > s
Definition AMReX_MLEBNodeFDLaplacian.cpp:214
static IntVect mfiter_tile_size
Default tilesize in MFIter.
Definition AMReX_FabArrayBase.H:306
__host__ __device__ Dim3 ubound(Array4< T > const &a) noexcept
Return the inclusive upper bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1365
__host__ __device__ Dim3 lbound(Array4< T > const &a) noexcept
Return the inclusive lower bounds of an Array4 in Dim3 form.
Definition AMReX_Array4.H:1351
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38