Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:testdescription>Test which checks the omp for lastprivate clause by counting up a variable in a parallelized loop. Each thread saves the next summand in a lastprivate variable i0. At the end i0 is compared to the value of the expected last summand.</ompts:testdescription> |
| 3 | <ompts:ompversion>2.0</ompts:ompversion> |
| 4 | <ompts:directive>omp for lastprivate</ompts:directive> |
| 5 | <ompts:dependences>omp critical,omp parallel firstprivate,omp schedule</ompts:dependences> |
| 6 | <ompts:testcode> |
| 7 | #include <stdio.h> |
| 8 | #include <math.h> |
| 9 | |
| 10 | #include "omp_testsuite.h" |
| 11 | |
| 12 | int sum0; |
| 13 | #pragma omp threadprivate(sum0) |
| 14 | |
| 15 | int <ompts:testcode:functionname>omp_for_lastprivate</ompts:testcode:functionname> (FILE * logFile) |
| 16 | { |
| 17 | int sum = 0; |
| 18 | int known_sum; |
| 19 | <ompts:orphan:vars> |
| 20 | int i0; |
| 21 | </ompts:orphan:vars> |
| 22 | |
| 23 | i0 = -1; |
| 24 | |
| 25 | #pragma omp parallel |
| 26 | { |
| 27 | sum0 = 0; |
| 28 | { /* Begin of orphaned block */ |
| 29 | <ompts:orphan> |
| 30 | int i; |
| 31 | #pragma omp for schedule(static,7) <ompts:check>lastprivate(i0)</ompts:check> |
| 32 | for (i = 1; i <= LOOPCOUNT; i++) |
| 33 | { |
| 34 | sum0 = sum0 + i; |
| 35 | i0 = i; |
| 36 | } /* end of for */ |
| 37 | </ompts:orphan> |
| 38 | } /* end of orphaned block */ |
| 39 | |
| 40 | #pragma omp critical |
| 41 | { |
| 42 | sum = sum + sum0; |
| 43 | } /* end of critical */ |
| 44 | } /* end of parallel */ |
| 45 | |
| 46 | known_sum = (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; |
| 47 | fprintf(logFile," known_sum = %d , sum = %d \n",known_sum,sum); |
| 48 | fprintf(logFile," LOOPCOUNT = %d , i0 = %d \n",LOOPCOUNT,i0); |
| 49 | return ((known_sum == sum) && (i0 == LOOPCOUNT) ); |
| 50 | } |
| 51 | </ompts:testcode> |
| 52 | </ompts:test> |