Jim Cownie | 18d8473 | 2014-05-10 17:02:09 +0000 | [diff] [blame] | 1 | <ompts:test> |
| 2 | <ompts:testdescription>Test which checks the omp_parallel_num_threads directive by counting the threads in a parallel region which was started with an explicitly stated number of threads.</ompts:testdescription> |
| 3 | <ompts:ompversion>3.0</ompts:ompversion> |
| 4 | <ompts:directive>omp parellel num_threads</ompts:directive> |
| 5 | <ompts:dependences>omp master,omp parallel reduction,omp atomic</ompts:dependences> |
| 6 | <ompts:testcode> |
| 7 | #include <stdio.h> |
| 8 | #include "omp_testsuite.h" |
| 9 | |
| 10 | int <ompts:testcode:functionname>omp_parallel_num_threads</ompts:testcode:functionname>(FILE * logFile){ |
| 11 | <ompts:orphan:vars> |
| 12 | int failed; |
| 13 | int threads; |
| 14 | int nthreads; |
| 15 | </ompts:orphan:vars> |
| 16 | |
| 17 | int max_threads = 0; |
| 18 | |
| 19 | failed = 0; |
| 20 | |
| 21 | /* first we check how many threads are available */ |
| 22 | #pragma omp parallel |
| 23 | { |
| 24 | #pragma omp master |
| 25 | max_threads = omp_get_num_threads (); |
| 26 | } |
| 27 | |
| 28 | /* we increase the number of threads from one to maximum:*/ |
| 29 | for (threads = 1; threads <= max_threads; threads++) |
| 30 | { |
| 31 | nthreads = 0; |
| 32 | |
| 33 | <ompts:orphan> |
| 34 | #pragma omp parallel reduction(+:failed) <ompts:check>num_threads(threads)</ompts:check> |
| 35 | { |
| 36 | failed = failed + !(threads == omp_get_num_threads ()); |
| 37 | #pragma omp atomic |
| 38 | nthreads += 1; |
| 39 | } |
| 40 | </ompts:orphan> |
| 41 | failed = failed + !(nthreads == threads); |
| 42 | } |
| 43 | return (!failed); |
| 44 | } |
| 45 | </ompts:testcode> |
| 46 | </ompts:test> |