chombo-discharge
Loading...
Searching...
No Matches
CD_OpenMP.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_OPENMP_H
14#define CD_OPENMP_H
15
16// Chombo includes
17#include <IntVectSet.H>
18
19// Our includes
20#include <CD_NamespaceHeader.H>
21
22#ifdef _OPENMP
23
24// Thread-safe reduction operator for taking the union of IntVectSet
25inline void
26ThreadSafeIVSUnion(IntVectSet& ivsInOut, const IntVectSet& ivsIn) noexcept
27{
28 ivsInOut |= ivsIn;
29}
30#pragma omp declare reduction(+ : IntVectSet : ThreadSafeIVSUnion(omp_out, omp_in))
31
32// Thread-safe minimum of pair<Real, RealVect>.
33inline void
34ThreadSafePairMin(std::pair<Real, RealVect>& ompOut, const std::pair<Real, RealVect>& ompIn) noexcept
35{
36 ompOut = (ompIn.first < ompOut.first) ? ompIn : ompOut;
37}
38#pragma omp declare reduction(pairmin : std::pair<Real, RealVect> : ThreadSafePairMin(omp_out, omp_in)) \
39 initializer(omp_priv = omp_orig)
40
41// Thread-safe maximum of pair<Real, RealVect>.
42inline void
43ThreadSafePairMax(std::pair<Real, RealVect>& ompOut, const std::pair<Real, RealVect>& ompIn) noexcept
44{
45 ompOut = (ompIn.first > ompOut.first) ? ompIn : ompOut;
46}
47#pragma omp declare reduction(pairmax : std::pair<Real, RealVect> : ThreadSafePairMax(omp_out, omp_in)) \
48 initializer(omp_priv = omp_orig)
49
50#endif
51
52#include <CD_NamespaceFooter.H>
53
54#endif