LLVM OpenMP
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).
15// End of definition copied from OpenMP RTL.
16// ---------------------------------------------------------------------------
17
18static int last_i = 0;
19
20/* Utility function to check that i is increasing monotonically
21 with each call */
22static int check_i_islarger(int i) {
23 int islarger;
24 islarger = (i > last_i);
25 last_i = i;
26 return (islarger);
27}
28
30 int sum;
31 int is_larger = 1;
32 int known_sum;
33 int i;
34
35 last_i = 0;
36 sum = 0;
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
53int main() {
54 int i;
55 int num_failed = 0;
56
57 for (i = 0; i < REPETITIONS; i++) {
59 num_failed++;
60 }
61 }
62 return num_failed;
63}
omp_sched_t
Definition kmp.h:4489
int test_static_steal_ordered()
static int check_i_islarger(int i)
static int last_i
#define i
Definition kmp_stub.cpp:88
#define omp_set_schedule
Definition kmp_stub.cpp:30
#define LOOPCOUNT
#define REPETITIONS