CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
openMPMutex.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <omp.h>
38
39#include "../mutexInterface.hpp"
40
42namespace codi {
43
47 struct OpenMPMutex : public MutexInterface {
48 private:
49 omp_lock_t mutex;
50
51 public:
53
55
57 void initialize() {
58 omp_init_lock(&mutex);
59 }
60
62 void finalize() {
63 omp_destroy_lock(&mutex);
64 }
65
67 void lock() {
68 omp_set_lock(&mutex);
69 }
70
72 void unlock() {
73 omp_unset_lock(&mutex);
74 }
75 };
76}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Abstracts a mutex.
Definition mutexInterface.hpp:47
Mutex implementation for OpenMP.
Definition openMPMutex.hpp:47
void finalize()
Finalize the mutex.
Definition openMPMutex.hpp:62
void unlock()
Unlock the mutex.
Definition openMPMutex.hpp:72
void initialize()
Initialize the mutex.
Definition openMPMutex.hpp:57
~OpenMPMutex()
Destructor.
Definition openMPMutex.hpp:54
OpenMPMutex()
Constructor.
Definition openMPMutex.hpp:52
void lock()
Lock the mutex.
Definition openMPMutex.hpp:67