LLVM OpenMP
20.0.0git
runtime
test
worksharing
for
omp_for_firstprivate.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
int
sum1
;
7
#pragma omp threadprivate(sum1)
8
9
int
test_omp_for_firstprivate
()
10
{
11
int
sum
;
12
int
sum0
;
13
int
known_sum;
14
int
threadsnum;
15
16
sum
= 0;
17
sum0
= 12345;
18
sum1
= 0;
19
20
#pragma omp parallel
21
{
22
#pragma omp single
23
{
24
threadsnum=
omp_get_num_threads
();
25
}
26
/* sum0 = 0; */
27
28
int
i
;
29
#pragma omp for firstprivate(sum0)
30
for
(
i
= 1;
i
<=
LOOPCOUNT
;
i
++) {
31
sum0
=
sum0
+
i
;
32
sum1
=
sum0
;
33
}
/* end of for */
34
35
#pragma omp critical
36
{
37
sum
=
sum
+
sum1
;
38
}
/* end of critical */
39
}
/* end of parallel */
40
known_sum = 12345* threadsnum+ (
LOOPCOUNT
* (
LOOPCOUNT
+ 1)) / 2;
41
return
(known_sum ==
sum
);
42
}
43
44
int
main
()
45
{
46
int
i
;
47
int
num_failed=0;
48
49
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
50
if
(!
test_omp_for_firstprivate
()) {
51
num_failed++;
52
}
53
}
54
return
num_failed;
55
}
i
#define i
Definition:
kmp_stub.cpp:87
test_omp_for_firstprivate
int test_omp_for_firstprivate()
Definition:
omp_for_firstprivate.c:9
sum1
int sum1
Definition:
omp_for_firstprivate.c:6
main
int main()
Definition:
omp_for_firstprivate.c:44
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
omp_get_num_threads
int omp_get_num_threads()
Generated on Wed Jan 29 2025 20:58:02 for LLVM OpenMP by
1.9.6