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

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