Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:description>Test which checks the omp parallel for nowait directive. It fills an array with values and operates on these in the following.</ompts:description> |
| 3 | <ompts:directive>omp parallel for nowait</ompts:directive> |
| 4 | <ompts:version>1.0</ompts:version> |
| 5 | <ompts:dependences>omp parallel for, omp flush</ompts:dependences> |
| 6 | <ompts:testcode> |
| 7 | #include <stdio.h> |
| 8 | |
| 9 | #include "omp_testsuite.h" |
| 10 | #include "omp_my_sleep.h" |
| 11 | |
| 12 | int <ompts:testcode:functionname>omp_for_nowait</ompts:testcode:functionname> (FILE * logFile) |
| 13 | { |
| 14 | <ompts:orphan:vars> |
| 15 | int result; |
| 16 | int count; |
| 17 | </ompts:orphan:vars> |
| 18 | int j; |
| 19 | int myarray[LOOPCOUNT]; |
| 20 | |
| 21 | result = 0; |
| 22 | count = 0; |
| 23 | |
| 24 | #pragma omp parallel |
| 25 | { |
| 26 | <ompts:orphan> |
| 27 | int rank; |
| 28 | int i; |
| 29 | |
| 30 | rank = omp_get_thread_num(); |
| 31 | |
| 32 | #pragma omp for <ompts:check>nowait</ompts:check> |
| 33 | for (i = 0; i < LOOPCOUNT; i++) { |
| 34 | if (i == 0) { |
| 35 | fprintf (logFile, "Thread nr %d entering for loop and going to sleep.\n", rank); |
| 36 | my_sleep(SLEEPTIME); |
| 37 | count = 1; |
| 38 | #pragma omp flush(count) |
| 39 | fprintf (logFile, "Thread nr %d woke up and set count = 1.\n", rank); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | fprintf (logFile, "Thread nr %d exited first for loop and enters the second.\n", rank); |
| 44 | #pragma omp for |
| 45 | for (i = 0; i < LOOPCOUNT; i++) |
| 46 | { |
| 47 | #pragma omp flush(count) |
| 48 | if (count == 0) |
| 49 | result = 1; |
| 50 | } |
| 51 | </ompts:orphan> |
| 52 | } |
| 53 | |
| 54 | return result; |
| 55 | } |
| 56 | </ompts:testcode> |
| 57 | </ompts:test> |