1 // RUN: %libomp-compile-and-run
2 #include <stdio.h>
3 #include "omp_testsuite.h"
4 
5 /*
6  * Test if the compiler supports nested parallelism
7  * By Chunhua Liao, University of Houston
8  * Oct. 2005
9  */
10 int test_omp_nested()
11 {
12 #ifdef _OPENMP
13   if (omp_get_max_threads() > 4)
14     omp_set_num_threads(4);
15 #endif
16 
17   int counter = 0;
18 #ifdef _OPENMP
19   omp_set_nested(1);
20 #endif
21 
22   #pragma omp parallel shared(counter)
23   {
24     #pragma omp critical
25     counter++;
26     #pragma omp parallel
27     {
28       #pragma omp critical
29       counter--;
30     }
31   }
32   return (counter != 0);
33 }
34 
35 int main()
36 {
37   int i;
38   int num_failed=0;
39 
40   for(i = 0; i < REPETITIONS; i++) {
41     if(!test_omp_nested()) {
42       num_failed++;
43     }
44   }
45   return num_failed;
46 }
47