Loading [MathJax]/extensions/tex2jax.js
Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ForEachFab.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #ifndef FUB_AMREX_FOR_EACH_FAB_HPP
22 #define FUB_AMREX_FOR_EACH_FAB_HPP
23 
24 #include "fub/Execution.hpp"
25 
26 #include <AMReX_MultiFab.H>
27 
28 namespace fub::amrex {
29 
30 /// @{
31 /// \ingroup ForEach
32 /// \brief Iterate through all local FArrayBox objects in a MultiFab.
33 template <typename Tag, typename F>
34 void ForEachFab(Tag, const ::amrex::FabArrayBase& fabarray, F function) {
35  for (::amrex::MFIter mfi(fabarray); mfi.isValid(); ++mfi) {
36  function(mfi);
37  }
38 }
39 
40 template <typename Tag, typename F>
41 void ForEachFab(Tag, const ::amrex::BoxArray& ba,
42  const ::amrex::DistributionMapping& dm, F function) {
43  for (::amrex::MFIter mfi(ba, dm); mfi.isValid(); ++mfi) {
44  function(mfi);
45  }
46 }
47 
48 template <typename F>
49 void ForEachFab(execution::OpenMpTag, const ::amrex::FabArrayBase& fabarray,
50  F function) {
51 #if defined(_OPENMP) && defined(AMREX_USE_OMP)
52 #pragma omp parallel
53 #endif
54  for (::amrex::MFIter mfi(fabarray, true); mfi.isValid(); ++mfi) {
55  function(mfi);
56  }
57 }
58 
59 template <typename F>
60 void ForEachFab(execution::OpenMpTag, const ::amrex::BoxArray& ba,
61  const ::amrex::DistributionMapping& dm, F function) {
62 #if defined(_OPENMP) && defined(AMREX_USE_OMP)
63 #pragma omp parallel
64 #endif
65  for (::amrex::MFIter mfi(ba, dm, true); mfi.isValid(); ++mfi) {
66  function(mfi);
67  }
68 }
69 
70 template <typename F>
71 void ForEachFab(execution::OpenMpSimdTag, const ::amrex::FabArrayBase& fabarray,
72  F function) {
73  ForEachFab(execution::openmp, fabarray, std::move(function));
74 }
75 
76 template <typename F>
77 void ForEachFab(const ::amrex::FabArrayBase& fabarray, F function) {
78  ForEachFab(execution::seq, fabarray, std::move(function));
79 }
80 
81 template <typename F>
82 void ForEachFab(execution::OpenMpSimdTag, const ::amrex::BoxArray& ba,
83  const ::amrex::DistributionMapping& dm, F function) {
84  ForEachFab(execution::openmp, ba, dm, std::move(function));
85 }
86 
87 template <typename F>
88 void ForEachFab(const ::amrex::BoxArray& ba,
89  const ::amrex::DistributionMapping& dm, F function) {
90  ForEachFab(execution::seq, ba, dm, std::move(function));
91 }
92 /// @}
93 
94 } // namespace fub::amrex
95 
96 #endif
void ForEachFab(Tag, const ::amrex::FabArrayBase &fabarray, F function)
Iterate through all local FArrayBox objects in a MultiFab.
Definition: ForEachFab.hpp:34
The amrex namespace.
Definition: AverageState.hpp:33
constexpr SequentialTag seq
Definition: Execution.hpp:31
constexpr OpenMpTag openmp
Definition: Execution.hpp:37
Definition: Execution.hpp:39
Definition: Execution.hpp:36