LLVM OpenMP
runtime
test
worksharing
for
kmp_sched_static_steal_ordered.c
Go to the documentation of this file.
1
// RUN: %libomp-compile-and-run
2
3
// Tests that an ordered loop with schedule(runtime) when the run-time
4
// schedule is set to static_steal with omp_set_schedule(), does not
5
// use the unordered static-steal scheduling nor hang.
6
// Such loops must fall back to dynamic, as they do with the environment
7
// variable OMP_SCHEDULE=static_steal.
8
9
#include <omp.h>
10
#include "
omp_testsuite.h
"
11
12
// ---------------------------------------------------------------------------
13
// Definition copied from OpenMP RTL (kmp_sched_t in kmp.h).
14
enum
{
kmp_sched_static_steal
= 102 };
15
// End of definition copied from OpenMP RTL.
16
// ---------------------------------------------------------------------------
17
18
static
int
last_i
= 0;
19
20
/* Utility function to check that i is increasing monotonically
21
with each call */
22
static
int
check_i_islarger
(
int
i
) {
23
int
islarger;
24
islarger = (
i
>
last_i
);
25
last_i
=
i
;
26
return
(islarger);
27
}
28
29
int
test_static_steal_ordered
() {
30
int
sum
;
31
int
is_larger = 1;
32
int
known_sum;
33
int
i
;
34
35
last_i
= 0;
36
sum
= 0;
37
omp_set_schedule
((
omp_sched_t
)
kmp_sched_static_steal
, 4);
38
39
// num_threads(4): static_steal needs more than one thread.
40
#pragma omp parallel for schedule(runtime) ordered num_threads(4)
41
for
(
i
= 1;
i
<=
LOOPCOUNT
;
i
++) {
42
#pragma omp ordered
43
{
44
is_larger =
check_i_islarger
(
i
) && is_larger;
45
sum
=
sum
+
i
;
46
}
47
}
48
49
known_sum = (
LOOPCOUNT
* (
LOOPCOUNT
+ 1)) / 2;
50
return
(known_sum ==
sum
) && is_larger;
51
}
52
53
int
main
() {
54
int
i
;
55
int
num_failed = 0;
56
57
for
(
i
= 0;
i
<
REPETITIONS
;
i
++) {
58
if
(!
test_static_steal_ordered
()) {
59
num_failed++;
60
}
61
}
62
return
num_failed;
63
}
omp_sched_t
omp_sched_t
Definition
kmp.h:4489
test_static_steal_ordered
int test_static_steal_ordered()
Definition
kmp_sched_static_steal_ordered.c:29
check_i_islarger
static int check_i_islarger(int i)
Definition
kmp_sched_static_steal_ordered.c:22
kmp_sched_static_steal
@ kmp_sched_static_steal
Definition
kmp_sched_static_steal_ordered.c:14
last_i
static int last_i
Definition
kmp_sched_static_steal_ordered.c:18
main
int main()
Definition
kmp_sched_static_steal_ordered.c:53
i
#define i
Definition
kmp_stub.cpp:88
omp_set_schedule
#define omp_set_schedule
Definition
kmp_stub.cpp:30
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
Generated on
for LLVM OpenMP by
1.14.0