1 // RUN: %libomp-compile-and-run 2 #include <stdio.h> 3 #include "omp_testsuite.h" 4 test_omp_parallel_num_threads()5int test_omp_parallel_num_threads() 6 { 7 int num_failed; 8 int threads; 9 int nthreads; 10 int max_threads = 0; 11 12 num_failed = 0; 13 14 /* first we check how many threads are available */ 15 #pragma omp parallel 16 { 17 #pragma omp master 18 max_threads = omp_get_num_threads (); 19 } 20 21 /* we increase the number of threads from one to maximum:*/ 22 for(threads = 1; threads <= max_threads; threads++) { 23 nthreads = 0; 24 #pragma omp parallel reduction(+:num_failed) num_threads(threads) 25 { 26 num_failed = num_failed + !(threads == omp_get_num_threads()); 27 #pragma omp atomic 28 nthreads += 1; 29 } 30 num_failed = num_failed + !(nthreads == threads); 31 } 32 return (!num_failed); 33 } 34 main()35int main() 36 { 37 int i; 38 int num_failed=0; 39 40 for(i = 0; i < REPETITIONS; i++) { 41 if(!test_omp_parallel_num_threads()) { 42 num_failed++; 43 } 44 } 45 return num_failed; 46 } 47