Debian Codegraph @

openmp/runtime/test/api/omp_get_num_threads.c

raw
1 // RUN: %libomp-compile-and-run
2 #include <stdio.h>
3 #include "omp_testsuite.h"
4
5 int test_omp_get_num_threads()
6 {
7 /* checks that omp_get_num_threads is equal to the number of
8 threads */
9 int nthreads_lib;
10 int nthreads = 0;
11
12 nthreads_lib = -1;
13
14 #pragma omp parallel
15 {
16 #pragma omp critical
17 {
18 nthreads++;
19 } /* end of critical */
20 #pragma omp single
21 {
22 nthreads_lib = omp_get_num_threads ();
23 } /* end of single */
24 } /* end of parallel */
25 return (nthreads == nthreads_lib);
26 }
27
28 int main()
29 {
30 int i;
31 int num_failed=0;
32
33 for(i = 0; i < REPETITIONS; i++) {
34 if(!test_omp_get_num_threads()) {
35 num_failed++;
36 }
37 }
38 return num_failed;
39 }