d-SEAMS
Install
Output
Methods
Docs
Engine & CLI
Python
Rust
Julia
R
Lua / Fennel
Fortran
PLUMED
linkcell
Wiki
Cite
GitHub
seams-core
v2.14.0
libyodaLib, the C++ engine of d-SEAMS
Toggle main menu visibility
Loading...
Searching...
No Matches
omp_tsan.hpp
Go to the documentation of this file.
1
// Copyright (c) d-SEAMS developers
2
#pragma once
3
4
// libgomp's barrier does not publish a happens-before that ThreadSanitizer
5
// can see, so a write inside a parallel region and a read after the join
6
// are reported as a race. This counter is the same join, made of atomics
7
// the sanitizer instruments. It is empty on every other build.
8
9
#include <atomic>
10
11
#if defined(__SANITIZE_THREAD__) && defined(_OPENMP)
12
#define SEAMS_TSAN_JOIN 1
13
#include <omp.h>
14
#endif
15
16
namespace
seams::tsan
{
17
18
struct
Slot
{
19
std::atomic<int>
arrived
{0};
20
std::atomic<int>
epoch
{0};
21
};
22
23
inline
void
arrive_and_wait
(
Slot
&slot,
int
threads) {
24
#ifdef SEAMS_TSAN_JOIN
25
if
(threads < 1) {
26
return
;
27
}
28
const
int
seen = slot.
epoch
.load(std::memory_order_relaxed);
29
const
int
turn = slot.
arrived
.fetch_add(1, std::memory_order_acq_rel);
30
if
(turn + 1 == threads) {
31
slot.
arrived
.store(0, std::memory_order_relaxed);
32
slot.
epoch
.fetch_add(1, std::memory_order_release);
33
return
;
34
}
35
while
(slot.
epoch
.load(std::memory_order_acquire) == seen) {
36
}
37
#else
38
(void)slot;
39
(void)threads;
40
#endif
41
}
42
43
}
// namespace seams::tsan
seams::tsan
Definition
omp_tsan.hpp:16
seams::tsan::arrive_and_wait
void arrive_and_wait(Slot &slot, int threads)
Definition
omp_tsan.hpp:23
seams::tsan::Slot
Definition
omp_tsan.hpp:18
seams::tsan::Slot::arrived
std::atomic< int > arrived
Definition
omp_tsan.hpp:19
seams::tsan::Slot::epoch
std::atomic< int > epoch
Definition
omp_tsan.hpp:20
src
include
internal
omp_tsan.hpp