Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:testdescription>Test which checks the omp critical directive by counting up a variable in a parallelized loop within a critical section.</ompts:testdescription> |
| 3 | <ompts:ompversion>2.0</ompts:ompversion> |
| 4 | <ompts:directive>omp critical</ompts:directive> |
| 5 | <ompts:testcode> |
| 6 | #include <stdio.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | #include "omp_testsuite.h" |
| 10 | #include "omp_my_sleep.h" |
| 11 | |
| 12 | int <ompts:testcode:functionname>omp_critical</ompts:testcode:functionname> (FILE * logFile) |
| 13 | { |
| 14 | <ompts:orphan:vars> |
| 15 | int sum; |
| 16 | </ompts:orphan:vars> |
| 17 | sum=0; |
| 18 | int known_sum; |
| 19 | |
| 20 | <ompts:orphan> |
| 21 | #pragma omp parallel |
| 22 | { |
| 23 | int mysum=0; |
| 24 | int i; |
| 25 | |
| 26 | #pragma omp for |
| 27 | for (i = 0; i < 1000; i++) |
| 28 | mysum = mysum + i; |
| 29 | |
| 30 | <ompts:check>#pragma omp critical</ompts:check> |
| 31 | sum = mysum +sum; |
| 32 | |
| 33 | } /* end of parallel */ |
| 34 | </ompts:orphan> |
| 35 | |
| 36 | printf("sum=%d\n",sum); |
| 37 | known_sum = 999 * 1000 / 2; |
| 38 | return (known_sum == sum); |
| 39 | |
| 40 | } |
| 41 | </ompts:testcode> |
| 42 | </ompts:test> |