Documentation 6b54b78464
Loading...
Searching...
No Matches
omp_structure.hpp File Reference

OpenMP interface header, provides compatibility functions if the code is built without OpenMP support. Parallel pragmas are defined here so that they can be completely "disabled" when compiling without OpenMP. More...

#include <cstddef>
#include <algorithm>
#include "../code_config.hpp"
#include <ctime>

Go to the source code of this file.

Classes

struct  omp_lock_t
 Dummy lock type and associated functions. More...
 
struct  DummyVectorOfLocks
 

Macros

#define SU2_OMP(ARGS)
 
#define SU2_OMP_SIMD
 
#define SU2_OMP_SIMD_IF_NOT_AD   SU2_OMP_SIMD
 
#define SU2_OMP_ATOMIC   SU2_OMP(atomic)
 
#define SU2_OMP_ATOMIC_WRITE   SU2_OMP(atomic write)
 
#define SU2_OMP_MASTER   SU2_OMP(master)
 
#define SU2_OMP_BARRIER   SU2_OMP(barrier)
 
#define SU2_OMP_CRITICAL   SU2_OMP(critical)
 
#define SU2_OMP_PARALLEL   SU2_OMP(parallel)
 
#define SU2_OMP_PARALLEL_(ARGS)   SU2_OMP(parallel ARGS)
 
#define SU2_OMP_PARALLEL_ON(NTHREADS)   SU2_OMP(parallel num_threads(NTHREADS))
 
#define SU2_OMP_FOR_(ARGS)   SU2_OMP(for ARGS)
 
#define SU2_OMP_FOR_DYN(CHUNK)   SU2_OMP(for schedule(dynamic,CHUNK))
 
#define SU2_OMP_FOR_STAT(CHUNK)   SU2_OMP(for schedule(static,CHUNK))
 
#define SU2_NOWAIT   nowait
 
#define END_SU2_OMP_MASTER
 
#define END_SU2_OMP_CRITICAL
 
#define END_SU2_OMP_PARALLEL
 
#define END_SU2_OMP_FOR
 
#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
 
#define END_SU2_OMP_SAFE_GLOBAL_ACCESS
 
#define SU2_OMP_SAFE_GLOBAL_ACCESS(...)   BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS{__VA_ARGS__} END_SU2_OMP_SAFE_GLOBAL_ACCESS
 
#define ATOMIC_COMPARE_SINCE   202011
 
#define ATOMIC_COMPARE_FALLBACK
 

Functions

constexpr int omp_get_max_threads ()
 Maximum number of threads available.
 
constexpr int omp_get_num_threads ()
 Number of threads in current team.
 
void omp_set_num_threads (int)
 Set the maximum number of threads.
 
constexpr int omp_get_thread_num ()
 Index of current thread, akin to MPI rank.
 
constexpr bool omp_in_parallel ()
 Returns true if inside a parallel section.
 
passivedouble omp_get_wtime ()
 Return the wall time.
 
void omp_init_lock (omp_lock_t *)
 
void omp_set_lock (omp_lock_t *)
 
void omp_unset_lock (omp_lock_t *)
 
void omp_destroy_lock (omp_lock_t *)
 
void omp_initialize ()
 
void omp_finalize ()
 
constexpr size_t roundUpDiv (size_t numerator, size_t denominator)
 Integer division rounding up.
 
constexpr size_t nextMultiple (size_t argument, size_t multiple)
 Round up to next multiple.
 
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 number of chunks (with limited size).
 
template<class T , class U >
void parallelCopy (size_t size, const T *src, U *dst)
 Copy data from one array-like object to another in parallel.
 
template<class T , class U >
void parallelSet (size_t size, T val, U *dst)
 Set the entries of an array-like object to a constant value in parallel.
 
template<class T , su2enable_if<!std::is_arithmetic< T >::value > = 0>
void atomicAdd (T rhs, T &lhs)
 Atomically update a (shared) lhs value with a (local) rhs value.
 
template<class T >
void atomicMax (const T &local, T &shared)
 
template<class T >
void atomicMin (const T &local, T &shared)
 

Detailed Description

OpenMP interface header, provides compatibility functions if the code is built without OpenMP support. Parallel pragmas are defined here so that they can be completely "disabled" when compiling without OpenMP.

Note
Do not include omp.h explicitly anywhere, use this header instead.
If you use an omp_*** function define a compatibility version here, if that is not practical use define "HAVE_OMP" to guard that function.
Always use the macro "SU2_OMP" to create OpenMP constructs, this is so we can disable pragmas. Other convenient pragmas are also defined here e.g. SU2_OMP_PARALLEL. Exotic pragmas of limited portability should be defined here with suitable fallback versions to limit the spread of compiler tricks in other areas of the code.
Author
P. Gomes, J. Blühdorn
Version
8.5.0 "Harrier"

SU2 Project Website: https://su2code.github.io

The SU2 Project is maintained by the SU2 Foundation (http://su2foundation.org)

Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)

SU2 is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

SU2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with SU2. If not, see http://www.gnu.org/licenses/.

Macro Definition Documentation

◆ ATOMIC_COMPARE_FALLBACK

#define ATOMIC_COMPARE_FALLBACK

◆ ATOMIC_COMPARE_SINCE

#define ATOMIC_COMPARE_SINCE   202011

◆ BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS

#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS
Value:
if (omp_in_parallel()) AD::StartNoSharedReading(); \
Contains routines for the reverse mode of AD. In case there is no reverse type configured,...
#define SU2_OMP_BARRIER
Definition omp_structure.hpp:142
#define SU2_OMP_MASTER
Definition omp_structure.hpp:141
constexpr bool omp_in_parallel()
Returns true if inside a parallel section.
Definition omp_structure.hpp:90

◆ END_SU2_OMP_CRITICAL

#define END_SU2_OMP_CRITICAL

◆ END_SU2_OMP_FOR

#define END_SU2_OMP_FOR

◆ END_SU2_OMP_MASTER

#define END_SU2_OMP_MASTER

◆ END_SU2_OMP_PARALLEL

#define END_SU2_OMP_PARALLEL

◆ END_SU2_OMP_SAFE_GLOBAL_ACCESS

#define END_SU2_OMP_SAFE_GLOBAL_ACCESS
Value:
END_SU2_OMP_MASTER \
if (omp_in_parallel()) AD::EndNoSharedReading(); \

◆ SU2_NOWAIT

#define SU2_NOWAIT   nowait

◆ SU2_OMP

#define SU2_OMP (   ARGS)

◆ SU2_OMP_ATOMIC

#define SU2_OMP_ATOMIC   SU2_OMP(atomic)

◆ SU2_OMP_ATOMIC_WRITE

#define SU2_OMP_ATOMIC_WRITE   SU2_OMP(atomic write)

◆ SU2_OMP_BARRIER

#define SU2_OMP_BARRIER   SU2_OMP(barrier)

◆ SU2_OMP_CRITICAL

#define SU2_OMP_CRITICAL   SU2_OMP(critical)

◆ SU2_OMP_FOR_

#define SU2_OMP_FOR_ (   ARGS)    SU2_OMP(for ARGS)

◆ SU2_OMP_FOR_DYN

#define SU2_OMP_FOR_DYN (   CHUNK)    SU2_OMP(for schedule(dynamic,CHUNK))

◆ SU2_OMP_FOR_STAT

#define SU2_OMP_FOR_STAT (   CHUNK)    SU2_OMP(for schedule(static,CHUNK))

◆ SU2_OMP_MASTER

#define SU2_OMP_MASTER   SU2_OMP(master)

◆ SU2_OMP_PARALLEL

#define SU2_OMP_PARALLEL   SU2_OMP(parallel)

◆ SU2_OMP_PARALLEL_

#define SU2_OMP_PARALLEL_ (   ARGS)    SU2_OMP(parallel ARGS)

◆ SU2_OMP_PARALLEL_ON

#define SU2_OMP_PARALLEL_ON (   NTHREADS)    SU2_OMP(parallel num_threads(NTHREADS))

◆ SU2_OMP_SAFE_GLOBAL_ACCESS

#define SU2_OMP_SAFE_GLOBAL_ACCESS (   ...)    BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS{__VA_ARGS__} END_SU2_OMP_SAFE_GLOBAL_ACCESS

◆ SU2_OMP_SIMD

#define SU2_OMP_SIMD

◆ SU2_OMP_SIMD_IF_NOT_AD

#define SU2_OMP_SIMD_IF_NOT_AD   SU2_OMP_SIMD

Function Documentation

◆ atomicAdd()

template<class T , su2enable_if<!std::is_arithmetic< T >::value > = 0>
void atomicAdd ( T  rhs,
T &  lhs 
)
inline

Atomically update a (shared) lhs value with a (local) rhs value.

Note
For types without atomic support (non-arithmetic) this is done via critical.
Parameters
[in]rhs- Local variable being added to the shared one.
[in,out]lhs- Shared variable being updated.

◆ atomicMax()

template<class T >
void atomicMax ( const T &  local,
T &  shared 
)
inline

◆ atomicMin()

template<class T >
void atomicMin ( const T &  local,
T &  shared 
)
inline

◆ computeStaticChunkSize()

size_t computeStaticChunkSize ( size_t  totalWork,
size_t  numThreads,
size_t  maxChunkSize 
)
inline

Compute a chunk size based on totalWork and number of threads such that all threads get the same number of chunks (with limited size).

Parameters
[in]totalWork- e.g. total number of loop iterations.
[in]numThreads- Number of threads that will share the work.
[in]maxChunkSize- Upper bound for chunk size.
Returns
The chunkSize.

◆ nextMultiple()

constexpr size_t nextMultiple ( size_t  argument,
size_t  multiple 
)
inlineconstexpr

Round up to next multiple.

◆ omp_destroy_lock()

void omp_destroy_lock ( omp_lock_t *  )
inline

◆ omp_finalize()

void omp_finalize ( )

◆ omp_get_max_threads()

constexpr int omp_get_max_threads ( )
inlineconstexpr

Maximum number of threads available.

◆ omp_get_num_threads()

constexpr int omp_get_num_threads ( )
inlineconstexpr

Number of threads in current team.

◆ omp_get_thread_num()

constexpr int omp_get_thread_num ( )
inlineconstexpr

Index of current thread, akin to MPI rank.

◆ omp_get_wtime()

passivedouble omp_get_wtime ( )
inline

Return the wall time.

◆ omp_in_parallel()

constexpr bool omp_in_parallel ( )
inlineconstexpr

Returns true if inside a parallel section.

◆ omp_init_lock()

void omp_init_lock ( omp_lock_t *  )
inline

◆ omp_initialize()

void omp_initialize ( )

◆ omp_set_lock()

void omp_set_lock ( omp_lock_t *  )
inline

◆ omp_set_num_threads()

void omp_set_num_threads ( int  )
inline

Set the maximum number of threads.

◆ omp_unset_lock()

void omp_unset_lock ( omp_lock_t *  )
inline

◆ parallelCopy()

template<class T , class U >
void parallelCopy ( size_t  size,
const T *  src,
U *  dst 
)

Copy data from one array-like object to another in parallel.

Parameters
[in]size- Number of elements.
[in]src- Source array.
[in]dst- Destination array.

◆ parallelSet()

template<class T , class U >
void parallelSet ( size_t  size,
T  val,
U *  dst 
)

Set the entries of an array-like object to a constant value in parallel.

Parameters
[in]size- Number of elements.
[in]val- Value to set.
[in]dst- Destination array.

◆ roundUpDiv()

constexpr size_t roundUpDiv ( size_t  numerator,
size_t  denominator 
)
inlineconstexpr

Integer division rounding up.