LLVM OpenMP
20.0.0git
runtime
test
tasking
omp_task_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
test_omp_task_firstprivate
()
7
{
8
int
i
;
9
int
sum
= 1234;
10
int
known_sum;
11
int
result
= 0;
/* counts the wrong sums from tasks */
12
13
known_sum = 1234 + (
LOOPCOUNT
* (
LOOPCOUNT
+ 1)) / 2;
14
15
#pragma omp parallel
16
{
17
#pragma omp single
18
{
19
for
(
i
= 0;
i
<
NUM_TASKS
;
i
++) {
20
#pragma omp task firstprivate(sum)
21
{
22
int
j
;
23
for
(
j
= 0;
j
<=
LOOPCOUNT
;
j
++) {
24
#pragma omp flush
25
sum
+=
j
;
26
}
27
28
/* check if calculated sum was right */
29
if
(
sum
!= known_sum) {
30
#pragma omp critical
31
{
result
++; }
32
}
33
}
/* omp task */
34
}
/* for loop */
35
}
/* omp single */
36
}
/* omp parallel */
37
return
(
result
== 0);
38
}
39
40
int
main
()
41
{
42
int
i
;
43
int
num_failed=0;
44
45
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
46
if
(!
test_omp_task_firstprivate
()) {
47
num_failed++;
48
}
49
}
50
return
num_failed;
51
}
result
int result[2]
Definition:
cancellation_for_sections.c:13
i
#define i
Definition:
kmp_stub.cpp:87
sum
int sum
Definition:
omp_for_schedule_runtime.c:19
j
int j
Definition:
omp_single_copyprivate.c:6
test_omp_task_firstprivate
int test_omp_task_firstprivate()
Definition:
omp_task_firstprivate.c:6
main
int main()
Definition:
omp_task_firstprivate.c:40
omp_testsuite.h
LOOPCOUNT
#define LOOPCOUNT
Definition:
omp_testsuite.h:12
NUM_TASKS
#define NUM_TASKS
Definition:
omp_testsuite.h:20
REPETITIONS
#define REPETITIONS
Definition:
omp_testsuite.h:13
Generated on Wed Jan 29 2025 20:58:02 for LLVM OpenMP by
1.9.6