LLVM OpenMP
20.0.0git
Toggle main menu visibility
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
c
d
e
g
h
i
m
n
p
r
s
t
u
Functions
c
d
e
g
i
m
n
p
r
s
u
Variables
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
~
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
w
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
Typedefs
Enumerations
Enumerator
Related Functions
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
Typedefs
_
a
b
c
d
e
i
k
l
m
n
o
p
r
t
u
Enumerations
_
b
c
d
f
k
l
n
o
s
t
Enumerator
_
a
b
c
d
e
f
k
l
n
o
p
r
s
t
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
runtime
test
teams
teams-atomic.c
Go to the documentation of this file.
1
// Check that omp atomic is permitted and behaves when strictly nested within
2
// omp teams. This is an extension to OpenMP 5.2 and is enabled by default.
3
4
// RUN: %libomp-compile-and-run | FileCheck %s
5
// GCC has really limited OpenMP 5.2 support yet.
6
// UNSUPPORTED: gcc
7
8
#include <omp.h>
9
#include <stdbool.h>
10
#include <stdio.h>
11
#include <string.h>
12
13
// High parallelism increases our chances of detecting a lack of atomicity.
14
#define NUM_TEAMS_TRY 256
15
16
int
main
() {
17
// CHECK: update: num_teams=[[#NUM_TEAMS:]]{{$}}
18
// CHECK-NEXT: update: x=[[#NUM_TEAMS]]{{$}}
19
int
x = 0;
20
int
numTeams;
21
#pragma omp teams num_teams(NUM_TEAMS_TRY)
22
{
23
#pragma omp atomic update
24
++x;
25
if
(omp_get_team_num() == 0)
26
numTeams = omp_get_num_teams();
27
}
28
printf(
"update: num_teams=%d\n"
, numTeams);
29
printf(
"update: x=%d\n"
, x);
30
31
// CHECK-NEXT: capture: x=[[#NUM_TEAMS]]{{$}}
32
// CHECK-NEXT: capture: xCapturedCount=[[#NUM_TEAMS]]{{$}}
33
bool
xCaptured[numTeams];
34
memset(xCaptured, 0,
sizeof
xCaptured);
35
x = 0;
36
#pragma omp teams num_teams(NUM_TEAMS_TRY)
37
{
38
int
v;
39
#pragma omp atomic capture
40
v = x++;
41
xCaptured[v] =
true
;
42
}
43
printf(
"capture: x=%d\n"
, x);
44
int
xCapturedCount = 0;
45
for
(
int
i
= 0;
i
< numTeams; ++
i
) {
46
if
(xCaptured[
i
])
47
++xCapturedCount;
48
}
49
printf(
"capture: xCapturedCount=%d\n"
, xCapturedCount);
50
return
0;
51
}
i
#define i
Definition:
kmp_stub.cpp:87
main
int main()
Definition:
teams-atomic.c:16
Generated on Mon May 19 2025 19:08:58 for LLVM OpenMP by
1.9.6