blob: 5e9e635fa155822402df756ba5ec168fbeade55f [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 * Checks that false is returned when called from serial region
Jonathan Peyton37310762016-05-17 21:08:52 +00007 * and true is returned when called within parallel region.
Jonathan Peyton614c7ef2015-09-21 20:41:31 +00008 */
9int test_omp_in_parallel()
10{
11 int serial;
12 int isparallel;
13
14 serial = 1;
15 isparallel = 0;
16 serial = omp_in_parallel();
17
18 #pragma omp parallel
19 {
20 #pragma omp single
21 {
22 isparallel = omp_in_parallel();
23 }
24 }
25 return (!(serial) && isparallel);
26}
27
28int main()
29{
30 int i;
31 int num_failed=0;
32
Andrey Churbanov74f98552018-12-13 10:04:10 +000033 // the test requires more than 1 thread to pass
34 omp_set_dynamic(0); // disable dynamic adjustment of threads
35 if (omp_get_max_threads() == 1)
36 omp_set_num_threads(2); // set 2 threads if no HW resources available
37
Jonathan Peyton614c7ef2015-09-21 20:41:31 +000038 for(i = 0; i < REPETITIONS; i++) {
39 if(!test_omp_in_parallel()) {
40 num_failed++;
41 }
42 }
43 return num_failed;
44}