1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include <math.h>
4#include "omp_testsuite.h"
5
6static int last_i = 0;
7
8/* Utility function to check that i is increasing monotonically
9 with each call */
10static int check_i_islarger (int i)
11{
12 int islarger;
13 islarger = (i > last_i);
14 last_i = i;
15 return (islarger);
16}
17
18int test_omp_for_ordered()
19{
20 int sum;
21 int is_larger = 1;
22 int known_sum;
23
24 last_i = 0;
25 sum = 0;
26
27 #pragma omp parallel
28 {
29 int i;
30 int my_islarger = 1;
31 #pragma omp for schedule(static,1) ordered
32 for (i = 1; i < 100; i++) {
33 #pragma omp ordered
34 {
35 my_islarger = check_i_islarger(i) && my_islarger;
36 sum = sum + i;
37 }
38 }
39 #pragma omp critical
40 {
41 is_larger = is_larger && my_islarger;
42 }
43 }
44
45 known_sum=(99 * 100) / 2;
46 return ((known_sum == sum) && is_larger);
47}
48
49int main()
50{
51 int i;
52 int num_failed=0;
53
54 for(i = 0; i < REPETITIONS; i++) {
55 if(!test_omp_for_ordered()) {
56 num_failed++;
57 }
58 }
59 return num_failed;
60}
61

source code of openmp/runtime/test/worksharing/for/omp_for_ordered.c