Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:testdescription>Test which checks that the omp_get_num_threads returns the correct number of threads. Therefor it counts up a variable in a parallelized section and compars this value with the result of the omp_get_num_threads function.</ompts:testdescription> |
| 3 | <ompts:ompversion>2.0</ompts:ompversion> |
| 4 | <ompts:directive>omp_get_num_threads</ompts:directive> |
| 5 | <ompts:testcode> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include "omp_testsuite.h" |
| 9 | |
| 10 | int <ompts:testcode:functionname>omp_get_num_threads</ompts:testcode:functionname> (FILE * logFile) |
| 11 | { |
| 12 | /* checks that omp_get_num_threads is equal to the number of |
| 13 | threads */ |
| 14 | <ompts:orphan:vars> |
| 15 | int nthreads_lib; |
| 16 | </ompts:orphan:vars> |
| 17 | int nthreads = 0; |
| 18 | |
| 19 | nthreads_lib = -1; |
| 20 | |
| 21 | #pragma omp parallel |
| 22 | { |
| 23 | #pragma omp critical |
| 24 | { |
| 25 | nthreads++; |
| 26 | } /* end of critical */ |
| 27 | #pragma omp single |
| 28 | { |
| 29 | <ompts:orphan> |
| 30 | <ompts:check>nthreads_lib = omp_get_num_threads ();</ompts:check> |
| 31 | </ompts:orphan> |
| 32 | } /* end of single */ |
| 33 | } /* end of parallel */ |
| 34 | |
| 35 | fprintf (logFile, "Counted %d threads. get_num_threads returned %d.\n", nthreads, nthreads_lib); |
| 36 | return (nthreads == nthreads_lib); |
| 37 | } |
| 38 | </ompts:testcode> |
| 39 | </ompts:test> |