Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:testdescription>Test which checks the firstprivate clause of the task directive. We create a set of tasks in a single region. We defines a variable named sum unequal zero which gets declared firstprivate for each task. Now each task calcualtes a sum using this private variable. Before each calcualation step we introduce a flush command so that maybe the private variabel gets bad. At the end we check if the calculated sum was right.</ompts:testdescription> |
| 3 | <ompts:ompversion>3.0</ompts:ompversion> |
| 4 | <ompts:directive>omp task firstprivate</ompts:directive> |
| 5 | <ompts:dependences>omp single,omp flush,omp critical</ompts:dependences> |
| 6 | <ompts:testcode> |
| 7 | #include <stdio.h> |
| 8 | #include <math.h> |
| 9 | #include "omp_testsuite.h" |
| 10 | |
| 11 | int <ompts:testcode:functionname>omp_task_firstprivate</ompts:testcode:functionname> (FILE * logFile) |
| 12 | { |
| 13 | int i; |
| 14 | <ompts:orphan:vars> |
| 15 | int sum = 1234; |
| 16 | int known_sum; |
| 17 | int result = 0; /* counts the wrong sums from tasks */ |
| 18 | </ompts:orphan:vars> |
| 19 | |
| 20 | known_sum = 1234 + (LOOPCOUNT * (LOOPCOUNT + 1)) / 2; |
| 21 | |
| 22 | #pragma omp parallel |
| 23 | { |
| 24 | #pragma omp single |
| 25 | { |
| 26 | for (i = 0; i < NUM_TASKS; i++) |
| 27 | { |
| 28 | <ompts:orphan> |
| 29 | #pragma omp task <ompts:check>firstprivate(sum)</ompts:check> |
| 30 | { |
| 31 | int j; |
| 32 | for (j = 0; j <= LOOPCOUNT; j++) { |
| 33 | #pragma omp flush |
| 34 | sum += j; |
| 35 | } |
| 36 | |
| 37 | /* check if calculated sum was right */ |
| 38 | if (sum != known_sum) { |
| 39 | #pragma omp critical |
| 40 | { result++; } |
| 41 | } |
| 42 | } /* end of omp task */ |
| 43 | </ompts:orphan> |
| 44 | } /* end of for */ |
| 45 | } /* end of single */ |
| 46 | } /* end of parallel*/ |
| 47 | |
| 48 | return (result == 0); |
| 49 | } |
| 50 | </ompts:testcode> |
| 51 | </ompts:test> |