Block-Structured AMR Software Framework
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_FabArrayBase.H>
6 #include <AMReX_TypeTraits.H>
7 
8 #ifdef AMREX_USE_GPU
9 #include <AMReX_MFParallelForG.H>
10 #else
11 #include <AMReX_MFParallelForC.H>
12 #endif
13 
14 namespace amrex {
15 
16 struct TileSize {
18  explicit TileSize (IntVect const& ts) noexcept : tile_size(ts) {}
19 };
20 
21 struct DynamicTiling {
22  bool dynamic;
23  explicit DynamicTiling (bool f) noexcept : dynamic(f) {}
24 };
25 
26 namespace experimental {
27 
43 template <typename MF, typename F>
44 std::enable_if_t<IsFabArray<MF>::value>
45 ParallelFor (MF const& mf, F&& f)
46 {
47  detail::ParallelFor(mf, IntVect(0), FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
48 }
49 
66 template <int MT, typename MF, typename F>
67 std::enable_if_t<IsFabArray<MF>::value>
68 ParallelFor (MF const& mf, F&& f)
69 {
70 #ifdef AMREX_USE_GPU
71  detail::ParallelFor<MT>(mf, IntVect(0), FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
72 #else
73  detail::ParallelFor(mf, IntVect(0), FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
74 #endif
75 }
76 
93 template <typename MF, typename F>
94 std::enable_if_t<IsFabArray<MF>::value>
95 ParallelFor (MF const& mf, IntVect const& ng, F&& f)
96 {
97  detail::ParallelFor(mf, ng, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
98 }
99 
117 template <int MT, typename MF, typename F>
118 std::enable_if_t<IsFabArray<MF>::value>
119 ParallelFor (MF const& mf, IntVect const& ng, F&& f)
120 {
121 #ifdef AMREX_USE_GPU
122  detail::ParallelFor<MT>(mf, ng, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
123 #else
124  detail::ParallelFor(mf, ng, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
125 #endif
126 }
127 
145 template <typename MF, typename F>
146 std::enable_if_t<IsFabArray<MF>::value>
147 ParallelFor (MF const& mf, IntVect const& ng, int ncomp, F&& f)
148 {
149  detail::ParallelFor(mf, ng, ncomp, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
150 }
151 
170 template <int MT, typename MF, typename F>
171 std::enable_if_t<IsFabArray<MF>::value>
172 ParallelFor (MF const& mf, IntVect const& ng, int ncomp, F&& f)
173 {
174 #ifdef AMREX_USE_GPU
175  detail::ParallelFor<MT>(mf, ng, ncomp, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
176 #else
177  detail::ParallelFor(mf, ng, ncomp, FabArrayBase::mfiter_tile_size, false, std::forward<F>(f));
178 #endif
179 }
180 
198 template <typename MF, typename F>
199 std::enable_if_t<IsFabArray<MF>::value>
200 ParallelFor (MF const& mf, TileSize const& ts, F&& f)
201 {
202  detail::ParallelFor(mf, IntVect(0), ts.tile_size, false, std::forward<F>(f));
203 }
204 
223 template <int MT, typename MF, typename F>
224 std::enable_if_t<IsFabArray<MF>::value>
225 ParallelFor (MF const& mf, TileSize const& ts, F&& f)
226 {
227 #ifdef AMREX_USE_GPU
228  detail::ParallelFor<MT>(mf, IntVect(0), ts.tile_size, false, std::forward<F>(f));
229 #else
230  detail::ParallelFor(mf, IntVect(0), ts.tile_size, false, std::forward<F>(f));
231 #endif
232 }
233 
252 template <typename MF, typename F>
253 std::enable_if_t<IsFabArray<MF>::value>
254 ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts, F&& f)
255 {
256  detail::ParallelFor(mf, ng, ts.tile_size, false, std::forward<F>(f));
257 }
258 
278 template <int MT, typename MF, typename F>
279 std::enable_if_t<IsFabArray<MF>::value>
280 ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts, F&& f)
281 {
282 #ifdef AMREX_USE_GPU
283  detail::ParallelFor<MT>(mf, ng, ts.tile_size, false, std::forward<F>(f));
284 #else
285  detail::ParallelFor(mf, ng, ts.tile_size, false, std::forward<F>(f));
286 #endif
287 }
288 
308 template <typename MF, typename F>
309 std::enable_if_t<IsFabArray<MF>::value>
310 ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts, F&& f)
311 {
312  detail::ParallelFor(mf, ng, ncomp, ts.tile_size, false, std::forward<F>(f));
313 }
314 
335 template <int MT, typename MF, typename F>
336 std::enable_if_t<IsFabArray<MF>::value>
337 ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts, F&& f)
338 {
339 #ifdef AMREX_USE_GPU
340  detail::ParallelFor<MT>(mf, ng, ncomp, ts.tile_size, false, std::forward<F>(f));
341 #else
342  detail::ParallelFor(mf, ng, ncomp, ts.tile_size, false, std::forward<F>(f));
343 #endif
344 }
345 
365 template <typename MF, typename F>
366 std::enable_if_t<IsFabArray<MF>::value>
367 ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts, DynamicTiling dt, F&& f)
368 {
369  detail::ParallelFor(mf, ng, ts.tile_size, dt.dynamic, std::forward<F>(f));
370 }
371 
392 template <typename MF, typename F>
393 std::enable_if_t<IsFabArray<MF>::value>
394 ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts,
395  DynamicTiling dt, F&& f)
396 {
397  detail::ParallelFor(mf, ng, ncomp, ts.tile_size, dt.dynamic, std::forward<F>(f));
398 }
399 
420 template <int MT, typename MF, typename F>
421 std::enable_if_t<IsFabArray<MF>::value>
422 ParallelFor (MF const& mf, IntVect const& ng, TileSize const& ts,
423  DynamicTiling dt, F&& f)
424 {
425 #ifdef AMREX_USE_GPU
426  detail::ParallelFor<MT>(mf, ng, ts.tile_size, dt.dynamic, std::forward<F>(f));
427 #else
428  detail::ParallelFor(mf, ng, ts.tile_size, dt.dynamic, std::forward<F>(f));
429 #endif
430 }
431 
453 template <int MT, typename MF, typename F>
454 std::enable_if_t<IsFabArray<MF>::value>
455 ParallelFor (MF const& mf, IntVect const& ng, int ncomp, TileSize const& ts,
456  DynamicTiling dt, F&& f)
457 {
458 #ifdef AMREX_USE_GPU
459  detail::ParallelFor<MT>(mf, ng, ncomp, ts.tile_size, dt.dynamic, std::forward<F>(f));
460 #else
461  detail::ParallelFor(mf, ng, ncomp, ts.tile_size, dt.dynamic, std::forward<F>(f));
462 #endif
463 }
464 
465 }
466 
468 
469 }
470 
471 #endif
static AMREX_EXPORT IntVect mfiter_tile_size
Default tilesize in MFIter.
Definition: AMReX_FabArrayBase.H:288
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
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
std::enable_if_t< IsFabArray< MF >::value > ParallelFor(MF const &mf, F &&f)
ParallelFor for MultiFab/FabArray.
Definition: AMReX_MFParallelFor.H:45
Definition: AMReX_Amr.cpp:49
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
Definition: AMReX_MFParallelFor.H:21
DynamicTiling(bool f) noexcept
Definition: AMReX_MFParallelFor.H:23
bool dynamic
Definition: AMReX_MFParallelFor.H:22
Definition: AMReX_MFParallelFor.H:16
TileSize(IntVect const &ts) noexcept
Definition: AMReX_MFParallelFor.H:18
IntVect tile_size
Definition: AMReX_MFParallelFor.H:17