LLVM OpenMP
20.0.0git
runtime
test
tasking
omp_record_replay_deps.cpp
Go to the documentation of this file.
1
// REQUIRES: ompx_taskgraph
2
// RUN: %libomp-cxx-compile-and-run
3
#include <iostream>
4
#include <cassert>
5
#define NT 100
6
#define MULTIPLIER 100
7
#define DECREMENT 5
8
9
int
val
;
10
// Compiler-generated code (emulation)
11
typedef
struct
ident
{
12
void
*
dummy
;
13
}
ident_t
;
14
15
16
#ifdef __cplusplus
17
extern
"C"
{
18
int
__kmpc_global_thread_num
(
ident_t
*);
19
int
__kmpc_start_record_task(
ident_t
*,
int
,
int
,
int
);
20
void
__kmpc_end_record_task(
ident_t
*,
int
,
int
,
int
);
21
}
22
#endif
23
24
void
sub
() {
25
#pragma omp atomic
26
val
-=
DECREMENT
;
27
}
28
29
void
add
() {
30
#pragma omp atomic
31
val
+=
DECREMENT
;
32
}
33
34
void
mult
() {
35
// no atomicity needed, can only be executed by 1 thread
36
// and no concurrency with other tasks possible
37
val
*=
MULTIPLIER
;
38
}
39
40
int
main
() {
41
val
= 0;
42
int
*x, *y;
43
#pragma omp parallel
44
#pragma omp single
45
for
(
int
iter = 0; iter <
NT
; ++iter) {
46
int
gtid =
__kmpc_global_thread_num
(
nullptr
);
47
int
res
= __kmpc_start_record_task(
nullptr
, gtid,
/* kmp_tdg_flags */
0,
/* tdg_id */
0);
48
if
(
res
) {
49
#pragma omp task depend(out:y)
50
add
();
51
#pragma omp task depend(out:x)
52
sub
();
53
#pragma omp task depend(in:x,y)
54
mult
();
55
}
56
__kmpc_end_record_task(
nullptr
, gtid,
/* kmp_tdg_flags */
0,
/* tdg_id */
0);
57
}
58
assert(
val
==0);
59
60
std::cout <<
"Passed"
<< std::endl;
61
return
0;
62
}
63
// CHECK: Passed
__kmpc_global_thread_num
KMP_EXPORT kmp_int32 __kmpc_global_thread_num(ident_t *)
Definition:
kmp_csupport.cpp:100
mult
void mult()
Definition:
omp_record_replay_deps.cpp:34
add
void add()
Definition:
omp_record_replay_deps.cpp:29
NT
#define NT
Definition:
omp_record_replay_deps.cpp:5
DECREMENT
#define DECREMENT
Definition:
omp_record_replay_deps.cpp:7
val
int val
Definition:
omp_record_replay_deps.cpp:9
MULTIPLIER
#define MULTIPLIER
Definition:
omp_record_replay_deps.cpp:6
ident_t
struct ident ident_t
main
int main()
Definition:
omp_record_replay_deps.cpp:40
sub
void sub()
Definition:
omp_record_replay_deps.cpp:24
res
#define res
Definition:
omp_task_red_taskloop.c:54
ident_t
Definition:
teams-no-par.c:23
ident
The ident structure that describes a source location.
Definition:
kmp.h:247
ident::dummy
void * dummy
Definition:
bug_taskwait_detach.cpp:26
Generated on Tue Jan 28 2025 22:40:54 for LLVM OpenMP by
1.9.6