LLVM OpenMP
20.0.0git
runtime
test
worksharing
for
omp_parallel_for_ordered.c
Go to the documentation of this file.
1
// RUN: %libomp-compile-and-run
2
#include <stdio.h>
3
#include "
omp_testsuite.h
"
4
5
static
int
last_i
= 0;
6
7
int
i
;
8
#pragma omp threadprivate(i)
9
10
/* Variable ii is used to avoid problems with a threadprivate variable used as a loop
11
* index. See test omp_threadprivate_for.
12
*/
13
static
int
ii
;
14
#pragma omp threadprivate(ii)
15
16
/*!
17
Utility function: returns true if the passed argument is larger than
18
the argument of the last call of this function.
19
*/
20
static
int
check_i_islarger2
(
int
i
)
21
{
22
int
islarger;
23
islarger = (
i
>
last_i
);
24
last_i
=
i
;
25
return
(islarger);
26
}
27
28
int
test_omp_parallel_for_ordered
()
29
{
30
int
sum
;
31
int
is_larger;
32
int
known_sum;
33
int
i
;
34
35
sum
= 0;
36
is_larger = 1;
37
last_i
= 0;
38
#pragma omp parallel for schedule(static,1) private(i) ordered
39
for
(
i
= 1;
i
< 100;
i
++) {
40
ii
=
i
;
41
#pragma omp ordered
42
{
43
is_larger =
check_i_islarger2
(
ii
) && is_larger;
44
sum
=
sum
+
ii
;
45
}
46
}
47
known_sum = (99 * 100) / 2;
48
fprintf (stderr,
" known_sum = %d , sum = %d \n"
, known_sum,
sum
);
49
fprintf (stderr,
" is_larger = %d\n"
, is_larger);
50
return
(known_sum ==
sum
) && is_larger;
51
}
52
53
int
main
()
54
{
55
int
i
;
56
int
num_failed=0;
57
58
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
59
if
(!
test_omp_parallel_for_ordered
()) {
60
num_failed++;
61
}
62
}
63
return
num_failed;
64
}
sum
int sum
Definition:
omp_for_schedule_runtime.c:19
last_i
static int last_i
Definition:
omp_parallel_for_ordered.c:5
ii
static int ii
Definition:
omp_parallel_for_ordered.c:13
test_omp_parallel_for_ordered
int test_omp_parallel_for_ordered()
Definition:
omp_parallel_for_ordered.c:28
i
int i
Definition:
omp_parallel_for_ordered.c:7
check_i_islarger2
static int check_i_islarger2(int i)
Utility function: returns true if the passed argument is larger than the argument of the last call of...
Definition:
omp_parallel_for_ordered.c:20
main
int main()
Definition:
omp_parallel_for_ordered.c:53
omp_testsuite.h
REPETITIONS
#define REPETITIONS
Definition:
omp_testsuite.h:13
Generated on Tue Jan 28 2025 22:40:54 for LLVM OpenMP by
1.9.6