LLVM OpenMP
20.0.0git
runtime
test
worksharing
for
omp_for_private.c
Go to the documentation of this file.
1
// RUN: %libomp-compile-and-run
2
#include <stdio.h>
3
#include <math.h>
4
#include "
omp_testsuite.h
"
5
6
/* Utility function do spend some time in a loop */
7
static
void
do_some_work
()
8
{
9
int
i
;
10
double
sum
= 0;
11
for
(
i
= 0;
i
< 1000;
i
++){
12
sum
+= sqrt ((
double
)
i
);
13
}
14
}
15
16
int
sum1
;
17
#pragma omp threadprivate(sum1)
18
19
int
test_omp_for_private
()
20
{
21
int
sum
= 0;
22
int
sum0
;
23
int
known_sum;
24
25
sum0
= 0;
/* setting (global) sum0 = 0 */
26
27
#pragma omp parallel
28
{
29
sum1
= 0;
/* setting sum1 in each thread to 0 */
30
{
/* begin of orphaned block */
31
int
i
;
32
#pragma omp for private(sum0) schedule(static,1)
33
for
(
i
= 1;
i
<=
LOOPCOUNT
;
i
++) {
34
sum0
=
sum1
;
35
#pragma omp flush
36
sum0
=
sum0
+
i
;
37
do_some_work
();
38
#pragma omp flush
39
sum1
=
sum0
;
40
}
41
}
/* end of orphaned block */
42
43
#pragma omp critical
44
{
45
sum
=
sum
+
sum1
;
46
}
/*end of critical*/
47
}
/* end of parallel*/
48
known_sum = (
LOOPCOUNT
* (
LOOPCOUNT
+ 1)) / 2;
49
return
(known_sum ==
sum
);
50
}
51
52
int
main
()
53
{
54
int
i
;
55
int
num_failed=0;
56
57
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
58
if
(!
test_omp_for_private
()) {
59
num_failed++;
60
}
61
}
62
return
num_failed;
63
}
i
#define i
Definition:
kmp_stub.cpp:87
sum1
int sum1
Definition:
omp_for_private.c:16
test_omp_for_private
int test_omp_for_private()
Definition:
omp_for_private.c:19
do_some_work
static void do_some_work()
Definition:
omp_for_private.c:7
main
int main()
Definition:
omp_for_private.c:52
sum
int sum
Definition:
omp_for_schedule_runtime.c:19
omp_testsuite.h
LOOPCOUNT
#define LOOPCOUNT
Definition:
omp_testsuite.h:12
REPETITIONS
#define REPETITIONS
Definition:
omp_testsuite.h:13
sum0
static int sum0
Definition:
omp_threadprivate.c:14
Generated on Wed Jan 29 2025 20:58:02 for LLVM OpenMP by
1.9.6