chombo-discharge
CD_OpenMP.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2023 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_OpenMP_H
13 #define CD_OpenMP_H
14 
15 // Chombo includes
16 #include <IntVectSet.H>
17 #include <List.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
25 inline void
26 ThreadSafeIVSUnion(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 catenation for a particle list.
33 template <typename P>
34 inline void
35 ThreadSafeCatenation(List<P>& particlesOut, List<P>& particlesIn) noexcept
36 {
37  particlesOut.catenate(particlesIn);
38 }
39 
40 // Thread-safe join for a particle list.
41 template <typename P>
42 inline void
43 ThreadSafeJoin(List<P>& particlesOut, List<P>& particlesIn) noexcept
44 {
45  particlesOut.join(particlesIn);
46 }
47 
48 // Thread-safe minimum of pair<Real, RealVect>.
49 inline void
50 ThreadSafePairMin(std::pair<Real, RealVect>& ompOut, const std::pair<Real, RealVect>& ompIn) noexcept
51 {
52  ompOut = (ompIn.first < ompOut.first) ? ompIn : ompOut;
53 }
54 #pragma omp declare reduction(pairmin : std::pair<Real, RealVect> : ThreadSafePairMin(omp_out, omp_in)) initializer(omp_priv=omp_orig)
55 
56 #endif
57 
58 #include <CD_NamespaceFooter.H>
59 
60 #endif