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 (i: ii) && is_larger; |
44 | sum = sum + ii; |
45 | } |
46 | } |
47 | known_sum = (99 * 100) / 2; |
48 | fprintf (stderr,format: " known_sum = %d , sum = %d \n" , known_sum, sum); |
49 | fprintf (stderr,format: " 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 | } |
65 | |