blob: d2d5b085ba79a4330c6588c4fb9c4279968515b8 [file] [log] [blame]
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00001// 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 */
10int test_omp_nested()
11{
Hal Finkel2bc34492017-06-27 03:04:25 +000012#ifdef _OPENMP
13 if (omp_get_max_threads() > 4)
14 omp_set_num_threads(4);
Andrey Churbanov74f98552018-12-13 10:04:10 +000015 if (omp_get_max_threads() < 2)
16 omp_set_num_threads(2);
Hal Finkel2bc34492017-06-27 03:04:25 +000017#endif
18
Jonathan Peyton614c7ef2015-09-21 20:41:31 +000019 int counter = 0;
20#ifdef _OPENMP
21 omp_set_nested(1);
22#endif
23
24 #pragma omp parallel shared(counter)
25 {
26 #pragma omp critical
27 counter++;
28 #pragma omp parallel
29 {
30 #pragma omp critical
31 counter--;
32 }
33 }
34 return (counter != 0);
35}
36
37int main()
38{
39 int i;
40 int num_failed=0;
41
42 for(i = 0; i < REPETITIONS; i++) {
43 if(!test_omp_nested()) {
44 num_failed++;
45 }
46 }
47 return num_failed;
48}