LLVM OpenMP
20.0.0git
runtime
test
tasking
omp_task_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
int
test_omp_task_private
()
8
{
9
int
i
;
10
int
known_sum;
11
int
sum
= 0;
12
int
result
= 0;
/* counts the wrong sums from tasks */
13
14
known_sum = (
LOOPCOUNT
* (
LOOPCOUNT
+ 1)) / 2;
15
16
#pragma omp parallel
17
{
18
#pragma omp single
19
{
20
for
(
i
= 0;
i
<
NUM_TASKS
;
i
++) {
21
#pragma omp task private(sum) shared(result, known_sum)
22
{
23
int
j
;
24
//if sum is private, initialize to 0
25
sum
= 0;
26
for
(
j
= 0;
j
<=
LOOPCOUNT
;
j
++) {
27
#pragma omp flush
28
sum
+=
j
;
29
}
30
/* check if calculated sum was right */
31
if
(
sum
!= known_sum) {
32
#pragma omp critical
33
result
++;
34
}
35
}
/* end of omp task */
36
}
/* end of for */
37
}
/* end of single */
38
}
/* end of parallel*/
39
return
(
result
== 0);
40
}
41
42
int
main
()
43
{
44
int
i
;
45
int
num_failed=0;
46
47
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
48
if
(!
test_omp_task_private
()) {
49
num_failed++;
50
}
51
}
52
return
num_failed;
53
}
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_private
int test_omp_task_private()
Definition:
omp_task_private.c:7
main
int main()
Definition:
omp_task_private.c:42
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