Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:testdescription>Test with omp for collapse clause. Bind with two loops. Without the collapse clause, the first loop will not be ordered</ompts:testdescription> |
| 3 | <ompts:ompversion>3.0</ompts:ompversion> |
| 4 | <ompts:directive>omp for collapse</ompts:directive> |
| 5 | <ompts:dependences>omp critical,omp for schedule</ompts:dependences> |
| 6 | <ompts:testcode> |
| 7 | #include <stdio.h> |
| 8 | #include <math.h> |
| 9 | |
| 10 | #include "omp_testsuite.h" |
| 11 | |
| 12 | |
| 13 | /* Utility function to check that i is increasing monotonically |
| 14 | with each call */ |
| 15 | static int check_i_islarger (int i) |
| 16 | { |
| 17 | static int last_i; |
| 18 | int islarger; |
| 19 | if (i==1) |
| 20 | last_i=0; |
| 21 | islarger = ((i >= last_i)&&(i - last_i<=1)); |
| 22 | last_i = i; |
| 23 | return (islarger); |
| 24 | } |
| 25 | |
| 26 | int <ompts:testcode:functionname>omp_for_collapse</ompts:testcode:functionname> (FILE * logFile) |
| 27 | { |
| 28 | <ompts:orphan:vars> |
| 29 | int is_larger = 1; |
| 30 | </ompts:orphan:vars> |
| 31 | |
| 32 | #pragma omp parallel |
| 33 | { |
| 34 | <ompts:orphan> |
| 35 | int i,j; |
| 36 | int my_islarger = 1; |
| 37 | #pragma omp for private(i,j) schedule(static,1) <ompts:check>collapse(2)</ompts:check> ordered |
| 38 | for (i = 1; i < 100; i++){ |
| 39 | <ompts:crosscheck>my_islarger = check_i_islarger(i)&& my_islarger;</ompts:crosscheck> |
| 40 | for (j =1; j <100; j++) |
| 41 | { |
| 42 | <ompts:check> |
| 43 | #pragma omp ordered |
| 44 | my_islarger = check_i_islarger(i)&&my_islarger; |
| 45 | </ompts:check> |
| 46 | } /* end of for */ |
| 47 | } |
| 48 | #pragma omp critical |
| 49 | is_larger = is_larger && my_islarger; |
| 50 | </ompts:orphan> |
| 51 | } |
| 52 | |
| 53 | return (is_larger); |
| 54 | } |
| 55 | </ompts:testcode> |
| 56 | </ompts:test> |