50 lines · c
1// RUN: %libomp-compile-and-run2#include <stdio.h>3#include "omp_testsuite.h"4 5/*6 * Test if the compiler supports nested parallelism7 * By Chunhua Liao, University of Houston8 * Oct. 20059 */10int test_omp_nested()11{12#ifdef _OPENMP13 if (omp_get_max_threads() > 4)14 omp_set_num_threads(4);15 if (omp_get_max_threads() < 2)16 omp_set_num_threads(2);17#endif18 19 int counter = 0;20#ifdef _OPENMP21 omp_set_nested(1);22 omp_set_max_active_levels(omp_get_supported_active_levels());23#endif24 25 #pragma omp parallel shared(counter)26 {27 #pragma omp critical28 counter++;29 #pragma omp parallel30 {31 #pragma omp critical32 counter--;33 }34 }35 return (counter != 0);36}37 38int main()39{40 int i;41 int num_failed=0;42 43 for(i = 0; i < REPETITIONS; i++) {44 if(!test_omp_nested()) {45 num_failed++;46 }47 }48 return num_failed;49}50