44#include "../code_config.hpp"
51#include "opdi/backend/ompt/omptBackend.hpp"
53#include "opdi/backend/macro/macroBackend.hpp"
59#define SU2_OMP(ARGS) PRAGMIZE(omp ARGS)
121#define SU2_OMP_SIMD PRAGMIZE(omp simd)
128#if !defined(CODI_FORWARD_TYPE) && !defined(CODI_REVERSE_TYPE)
129#define SU2_OMP_SIMD_IF_NOT_AD SU2_OMP_SIMD
131#define SU2_OMP_SIMD_IF_NOT_AD
136#define SU2_OMP_ATOMIC SU2_OMP(atomic)
137#define SU2_OMP_ATOMIC_WRITE SU2_OMP(atomic write)
141#define SU2_OMP_MASTER SU2_OMP(master)
142#define SU2_OMP_BARRIER SU2_OMP(barrier)
143#define SU2_OMP_CRITICAL SU2_OMP(critical)
145#define SU2_OMP_PARALLEL SU2_OMP(parallel)
146#define SU2_OMP_PARALLEL_(ARGS) SU2_OMP(parallel ARGS)
147#define SU2_OMP_PARALLEL_ON(NTHREADS) SU2_OMP(parallel num_threads(NTHREADS))
149#define SU2_OMP_FOR_(ARGS) SU2_OMP(for ARGS)
150#define SU2_OMP_FOR_DYN(CHUNK) SU2_OMP(for schedule(dynamic,CHUNK))
151#define SU2_OMP_FOR_STAT(CHUNK) SU2_OMP(for schedule(static,CHUNK))
153#define SU2_NOWAIT nowait
155#define END_SU2_OMP_MASTER
156#define END_SU2_OMP_CRITICAL
157#define END_SU2_OMP_PARALLEL
158#define END_SU2_OMP_FOR
162#define SU2_OMP_MASTER OPDI_MASTER()
163#define SU2_OMP_BARRIER OPDI_BARRIER()
164#define SU2_OMP_CRITICAL OPDI_CRITICAL()
166#define SU2_OMP_PARALLEL OPDI_PARALLEL()
167#define SU2_OMP_PARALLEL_(ARGS) OPDI_PARALLEL(ARGS)
168#define SU2_OMP_PARALLEL_ON(NTHREADS) OPDI_PARALLEL(num_threads(NTHREADS))
170#define SU2_OMP_FOR_(ARGS) OPDI_FOR(ARGS)
171#define SU2_OMP_FOR_DYN(CHUNK) OPDI_FOR(schedule(dynamic, CHUNK))
172#define SU2_OMP_FOR_STAT(CHUNK) OPDI_FOR(schedule(static, CHUNK))
174#define SU2_NOWAIT OPDI_NOWAIT
176#define END_SU2_OMP_MASTER OPDI_END_MASTER
177#define END_SU2_OMP_CRITICAL OPDI_END_CRITICAL
178#define END_SU2_OMP_PARALLEL OPDI_END_PARALLEL
179#define END_SU2_OMP_FOR OPDI_END_FOR
187#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS \
189 if (omp_in_parallel()) AD::StartNoSharedReading(); \
192#define END_SU2_OMP_SAFE_GLOBAL_ACCESS \
194 if (omp_in_parallel()) AD::EndNoSharedReading(); \
197#define SU2_OMP_SAFE_GLOBAL_ACCESS(...) BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS{__VA_ARGS__} END_SU2_OMP_SAFE_GLOBAL_ACCESS
204inline constexpr size_t roundUpDiv(
size_t numerator,
size_t denominator) {
205 return (numerator + denominator - 1) / denominator;
211inline constexpr size_t nextMultiple(
size_t argument,
size_t multiple) {
212 return roundUpDiv(argument, multiple) * multiple;
224 if (!totalWork)
return maxChunkSize;
225 size_t workPerThread =
roundUpDiv(totalWork, numThreads);
226 size_t chunksPerThread =
roundUpDiv(workPerThread, maxChunkSize);
227 return roundUpDiv(workPerThread, chunksPerThread);
236template <
class T,
class U>
239 for (
size_t i = 0; i < size; ++i) dst[i] = src[i];
249template <
class T,
class U>
252 for (
size_t i = 0; i < size; ++i) dst[i] = val;
262template <class T, su2enable_if<!std::is_arithmetic<T>::value> = 0>
268template <class T, su2enable_if<std::is_arithmetic<T>::value> = 0>
275#define ATOMIC_COMPARE_SINCE 202011
278#undef ATOMIC_COMPARE_SINCE
279#define ATOMIC_COMPARE_SINCE 201511
284#define ATOMIC_COMPARE_FALLBACK
290#if defined(_OPENMP) && !defined(__CUDACC__)
291#if _OPENMP >= ATOMIC_COMPARE_SINCE
293template <class T, su2enable_if<std::is_arithmetic<T>::value> = 0>
294inline void atomicMax(
const T& local, T& shared) {
295#pragma omp atomic compare
296 shared = shared < local ? local : shared;
300#undef ATOMIC_COMPARE_FALLBACK
301#define ATOMIC_COMPARE_FALLBACK , su2enable_if<!std::is_arithmetic<T>::value> = 0
304template <
class T ATOMIC_COMPARE_FALLBACK>
307 shared = std::max(local, shared);
312#if defined(_OPENMP) && !defined(__CUDACC__)
313#if _OPENMP >= ATOMIC_COMPARE_SINCE
314template <class T, su2enable_if<std::is_arithmetic<T>::value> = 0>
315inline void atomicMin(
const T& local, T& shared) {
316#pragma omp atomic compare
317 shared = shared > local ? local : shared;
321template <
class T ATOMIC_COMPARE_FALLBACK>
324 shared = std::min(local, shared);
327#undef ATOMIC_COMPARE_FALLBACK
double passivedouble
Definition code_config.hpp:129
constexpr int omp_get_num_threads()
Number of threads in current team.
Definition omp_structure.hpp:75
#define SU2_OMP_ATOMIC
Definition omp_structure.hpp:136
#define END_SU2_OMP_FOR
Definition omp_structure.hpp:158
constexpr size_t roundUpDiv(size_t numerator, size_t denominator)
Integer division rounding up.
Definition omp_structure.hpp:204
void omp_set_num_threads(int)
Set the maximum number of threads.
Definition omp_structure.hpp:80
constexpr int omp_get_max_threads()
Maximum number of threads available.
Definition omp_structure.hpp:70
void omp_init_lock(omp_lock_t *)
Definition omp_structure.hpp:105
void parallelCopy(size_t size, const T *src, U *dst)
Copy data from one array-like object to another in parallel.
Definition omp_structure.hpp:237
passivedouble omp_get_wtime()
Return the wall time.
Definition omp_structure.hpp:95
void atomicMin(const T &local, T &shared)
Definition omp_structure.hpp:322
size_t computeStaticChunkSize(size_t totalWork, size_t numThreads, size_t maxChunkSize)
Compute a chunk size based on totalWork and number of threads such that all threads get the same numb...
Definition omp_structure.hpp:223
constexpr bool omp_in_parallel()
Returns true if inside a parallel section.
Definition omp_structure.hpp:90
void omp_finalize()
Definition omp_structure.cpp:44
#define SU2_OMP_CRITICAL
Definition omp_structure.hpp:143
void atomicAdd(T rhs, T &lhs)
Atomically update a (shared) lhs value with a (local) rhs value.
Definition omp_structure.hpp:263
void omp_initialize()
Definition omp_structure.cpp:31
void parallelSet(size_t size, T val, U *dst)
Set the entries of an array-like object to a constant value in parallel.
Definition omp_structure.hpp:250
constexpr int omp_get_thread_num()
Index of current thread, akin to MPI rank.
Definition omp_structure.hpp:85
#define END_SU2_OMP_CRITICAL
Definition omp_structure.hpp:156
void omp_unset_lock(omp_lock_t *)
Definition omp_structure.hpp:107
void omp_set_lock(omp_lock_t *)
Definition omp_structure.hpp:106
void atomicMax(const T &local, T &shared)
Definition omp_structure.hpp:305
#define SU2_OMP_FOR_STAT(CHUNK)
Definition omp_structure.hpp:151
constexpr size_t nextMultiple(size_t argument, size_t multiple)
Round up to next multiple.
Definition omp_structure.hpp:211
void omp_destroy_lock(omp_lock_t *)
Definition omp_structure.hpp:108
Definition omp_structure.hpp:101
omp_lock_t & operator[](int)
Definition omp_structure.hpp:103
omp_lock_t l
Definition omp_structure.hpp:102
Dummy lock type and associated functions.
Definition omp_structure.hpp:100