MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
maia Namespace Reference

Namespace for auxiliary functions/classes. More...

Namespaces

namespace  acoustic
 
namespace  acoustic_analogy
 
namespace  alloc
 
namespace  collector_memory
 Helper functions useful for allocating collector memory.
 
namespace  container
 
namespace  coupling
 
namespace  debug
 
namespace  detail_
 
namespace  dg
 
namespace  dlb
 
namespace  dlbTimer
 
namespace  fc
 
namespace  filter
 
namespace  fv
 
namespace  geom
 
namespace  grid
 
namespace  io
 
namespace  lb
 
namespace  lblpt
 
namespace  logtable
 
namespace  lpt
 
namespace  ls
 
namespace  math
 
namespace  mpi
 
namespace  parallel_io
 
namespace  post
 
namespace  rb
 
namespace  sbp
 
namespace  structured
 
namespace  tensor
 Namespace that contains all classes, functions and constants needed for Tensor.
 

Classes

class  CartesianSolver
 
struct  is_unsigned
 
struct  is_unsigned< MUint >
 
struct  is_unsigned< MUlong >
 
struct  maia_signed
 
struct  maia_unsigned
 
struct  PatchRefinement
 
struct  RangeIterator
 Dummy iterator class. More...
 
struct  type_traits
 
struct  type_traits< long >
 
struct  type_traits< MBool >
 
struct  type_traits< MChar >
 
struct  type_traits< MFloat >
 
struct  type_traits< MInt >
 
struct  type_traits< MLong >
 
struct  type_traits< MString >
 
struct  type_traits< MUint >
 
struct  type_traits< MUlong >
 
struct  type_traits< uint_fast8_t >
 

Functions

template<class UnaryFunction >
void parallelFor_base (MInt begin, MInt end, UnaryFunction &&f)
 Wrapper function for parallel for loop (no PSTL) More...
 
template<class UnaryFunction >
void parallelFor_pstl (MInt begin, MInt end, UnaryFunction &&f)
 Wrapper function for parallel for loop (PSTL) More...
 
template<MBool portedToGpu = false, class UnaryFunction >
void parallelFor (MInt begin, MInt end, UnaryFunction &&f)
 Wrapper function for parallel for loop. More...
 
template<class UnaryFunction , class T >
void parallelFor_base (const std::vector< T > &container, UnaryFunction &&f)
 Wrapper function for parallel for loop (STL container based, no PSTL) More...
 
template<class UnaryFunction , class T >
void parallelFor_pstl (const std::vector< T > &container, UnaryFunction &&f)
 Wrapper function for parallel for loop (STL container based, PSTL) More...
 
template<MBool portedToGpu = false, class UnaryFunction , class T >
void parallelFor (const std::vector< T > &container, UnaryFunction &&f)
 Wrapper function for parallel for loop (STL container based) More...
 
template<MInt nDim, class UnaryFunction >
void parallelFor_base (std::array< MInt, nDim > begin, std::array< MInt, nDim > end, UnaryFunction &&f)
 Wrapper function for parallel nested for loops [NON-PSTL]. More...
 
template<MInt nDim, class UnaryFunction >
void parallelFor_pstl (std::array< MInt, nDim > begin, std::array< MInt, nDim > end, UnaryFunction &&f)
 Wrapper function for parallel nested for loops [PSTL]. More...
 
template<MBool portedToGpu = false, MInt nDim, class UnaryFunction >
void parallelFor (std::array< MInt, nDim > begin, std::array< MInt, nDim > end, UnaryFunction &&f)
 Wrapper function for parallel nested for loops. More...
 

Detailed Description

Classes with constant number of space dimensions nd.

Helper class for automatic tracing.

type traits for dealing with signed vs unsigned indices

Note: we should not do this...

Todo:
labels:toenhance use <type_traits> instead of this hack

Function Documentation

◆ parallelFor() [1/3]

template<MBool portedToGpu = false, class UnaryFunction , class T >
void maia::parallelFor ( const std::vector< T > &  container,
UnaryFunction &&  f 
)
inline
Author
Miro Gondrum
Date
18.02.2022
Parameters
[in]containerSTL container over whose entries are looped over
[in]ffunction which represents the loops body

This function wraps a for loop, such that it is performed parallel depending on the given compiler flags. This loop has to be of following type: for( auto& item: container) { f(item); }

Definition at line 197 of file parallelfor.h.

197 {
198 if constexpr(portedToGpu) {
199 parallelFor_pstl(container, f);
200 } else {
201 parallelFor_base(container, f);
202 }
203}
void parallelFor_pstl(MInt begin, MInt end, UnaryFunction &&f)
Wrapper function for parallel for loop (PSTL)
Definition: parallelfor.h:114

◆ parallelFor() [2/3]

template<MBool portedToGpu = false, class UnaryFunction >
void maia::parallelFor ( MInt  begin,
MInt  end,
UnaryFunction &&  f 
)
inline
Author
Miro Gondrum
Date
02.12.2021
Parameters
[in]beginstart value of iteration
[in]endend value of iteration
[in]ffunction which represents the loops body

This function wraps a for loop, such that it is performed parallel depending on the given compiler flags. This loop has to be of following type: for( int i = begin; i < end ; i++) { f(i); }

Definition at line 147 of file parallelfor.h.

147 {
148 if constexpr(portedToGpu) {
149 parallelFor_pstl(begin, end, f);
150 } else {
151 parallelFor_base(begin, end, f);
152 }
153}

◆ parallelFor() [3/3]

template<MBool portedToGpu = false, MInt nDim, class UnaryFunction >
void maia::parallelFor ( std::array< MInt, nDim >  begin,
std::array< MInt, nDim >  end,
UnaryFunction &&  f 
)
inline
Author
Marian Albers, Miro Gondrum
Date
07.03.2023
Parameters
[in]begin[nDim]start value of iteration
[in]end[nDim]end value of iteration
[in]ffunction which represents the loops body

This function wraps a one or multiple nested for loops, such that it is performed parallel depending on the given compiler flags. This loop has to be of following type: for( int i = begin[0]; i < end[0] ; i++) { f(i); } or for( int i = begin[0]; i < end[0] ; i++) { for( int j = begin[1]; j < end[1] ; j++) { f(i,j); } }

Definition at line 306 of file parallelfor.h.

306 {
307 if constexpr(portedToGpu) {
308 parallelFor_pstl<nDim>(begin, end, f);
309 } else {
310 parallelFor_base<nDim>(begin, end, f);
311 }
312}

◆ parallelFor_base() [1/3]

template<class UnaryFunction , class T >
void maia::parallelFor_base ( const std::vector< T > &  container,
UnaryFunction &&  f 
)
inline
Author
Miro Gondrum
Date
21.02.2022
Note
PLEASE USE parallelFor(..) function

Definition at line 161 of file parallelfor.h.

161 {
162 const MInt end = container.size();
163#if defined(_OPENMP)
164#pragma omp parallel for schedule(static, CHUNK_SIZE) default(none) shared(end, f, container)
165#endif
166 for(MInt i = 0; i < end; i++) {
167 f(container[i]);
168 }
169}
int32_t MInt
Definition: maiatypes.h:62

◆ parallelFor_base() [2/3]

template<class UnaryFunction >
void maia::parallelFor_base ( MInt  begin,
MInt  end,
UnaryFunction &&  f 
)
inline
Author
Miro Gondrum
Date
21.02.2022
Note
PLEASE USE parallelFor(..) function

Definition at line 99 of file parallelfor.h.

99 {
100#if defined(_OPENMP)
101#pragma omp parallel for schedule(static, CHUNK_SIZE) default(none) shared(begin, end, f)
102#endif
103 for(MInt i = begin; i < end; i++) {
104 f(i);
105 }
106}

◆ parallelFor_base() [3/3]

template<MInt nDim, class UnaryFunction >
void maia::parallelFor_base ( std::array< MInt, nDim >  begin,
std::array< MInt, nDim >  end,
UnaryFunction &&  f 
)
inline
Author
Marian Albers, Miro Gondrum
Date
07.03.2023
Note
PLEASE USE parallelFor(..) function

Definition at line 212 of file parallelfor.h.

212 {
213 if constexpr(nDim == 3) {
214#if defined(_OPENMP)
215#pragma omp parallel for schedule(static, CHUNK_SIZE) default(none) shared(begin, end, f) collapse(3)
216#endif
217 for(MInt k = begin[2]; k < end[2]; k++) {
218 for(MInt j = begin[1]; j < end[1]; j++) {
219 for(MInt i = begin[0]; i < end[0]; i++) {
220 f(i, j, k);
221 }
222 }
223 }
224 } else if constexpr(nDim == 2) {
225#if defined(_OPENMP)
226#pragma omp parallel for schedule(static, CHUNK_SIZE) default(none) shared(begin, end, f) collapse(2)
227#endif
228 for(MInt j = begin[1]; j < end[1]; j++) {
229 for(MInt i = begin[0]; i < end[0]; i++) {
230 f(i, j);
231 }
232 }
233 } else {
234 mTerm(1, AT_, "Only nDim==2 and nDim==3 supported");
235 }
236}
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29

◆ parallelFor_pstl() [1/3]

template<class UnaryFunction , class T >
void maia::parallelFor_pstl ( const std::vector< T > &  container,
UnaryFunction &&  f 
)
inline
Author
Miro Gondrum
Date
21.02.2022
Note
PLEASE USE parallelFor(..) function

Definition at line 177 of file parallelfor.h.

177 {
178#if defined(MAIA_PSTL)
179 std::for_each_n(std::execution::par_unseq, container.begin(), container.end(), f);
180#else
181 parallelFor_base(container, f);
182#endif
183}
void parallelFor_base(MInt begin, MInt end, UnaryFunction &&f)
Wrapper function for parallel for loop (no PSTL)
Definition: parallelfor.h:99

◆ parallelFor_pstl() [2/3]

template<class UnaryFunction >
void maia::parallelFor_pstl ( MInt  begin,
MInt  end,
UnaryFunction &&  f 
)
inline
Author
Miro Gondrum
Date
21.02.2022
Note
PLEASE USE parallelFor(..) function

Definition at line 114 of file parallelfor.h.

114 {
115#if defined(MAIA_PSTL)
116#if defined(MAIA_NVHPC_COMPILER)
117 // WAR: https://nvbugs/3285841
118 // TODO labels:gpu So far this only works with begin == 0. The
119 // RangeIterator is not working for nvhpc's pstl implementation, yet.
120 auto begin_ = thrust::counting_iterator(MInt{begin});
121 auto end_ = end;
122#else
123 auto begin_ = RangeIterator(begin);
124 auto end_ = RangeIterator(end);
125#endif
126 // TODO miro: GCC: How to trigger the usage of more threads? Currently in my
127 // case it using only 1 thread. Hence, OpenMP is performing better
128 std::for_each_n(std::execution::par_unseq, begin_, end_, f);
129#else /* defined(MAIA_PSTL) */
130 parallelFor_base(begin, end, f);
131#endif
132}

◆ parallelFor_pstl() [3/3]

template<MInt nDim, class UnaryFunction >
void maia::parallelFor_pstl ( std::array< MInt, nDim >  begin,
std::array< MInt, nDim >  end,
UnaryFunction &&  f 
)
inline
Author
Marian Albers, Miro Gondrum
Date
07.03.2023
Note
PLEASE USE parallelFor(..) function

Definition at line 244 of file parallelfor.h.

244 {
245#if defined(MAIA_PSTL)
246 std::array<MInt, nDim> size{};
247 const MInt beginI = 0;
248 MInt endI = 1;
249 for(MInt dim = 0; dim < nDim; ++dim) {
250 size[dim] = end[dim] - begin[dim];
251 endI *= size[dim];
252 }
253#if defined(MAIA_NVHPC_COMPILER)
254 // WAR: https://nvbugs/3285841
255 // TODO labels:gpu So far this only works with begin == 0. The
256 // RangeIterator is not working for nvhpc's pstl implementation, yet.
257 auto begin_ = thrust::counting_iterator(MInt{beginI});
258 auto end_ = endI;
259#else
260 auto begin_ = RangeIterator(beginI);
261 auto end_ = RangeIterator(endI);
262#endif
263
264 if constexpr(nDim == 3) {
265 std::for_each_n(std::execution::par_unseq, begin_, end_, [=](auto& I) {
266 const MInt k = (I / (size[0] * size[1])) + begin[2];
267 const MInt j = ((I - k * size[0] * size[1]) / size[0]) + begin[1];
268 const MInt i = (I % size[0]) + begin[0];
269
270 f(i, j, k);
271 });
272 } else if constexpr(nDim == 2) {
273 std::for_each_n(std::execution::par_unseq, begin_, end_, [=](auto& I) {
274 const MInt j = (I / size[0]) + begin[1];
275 const MInt i = (I % size[0]) + begin[0];
276
277 f(i, j);
278 });
279 }
280#else /* defined(MAIA_PSTL) */
281 parallelFor_base<nDim>(begin, end, f);
282#endif
283}