summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/test/api/omp_in_parallel.c
blob: 5e9e635fa155822402df756ba5ec168fbeade55f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"

/*
 * Checks that false is returned when called from serial region
 * and true is returned when called within parallel region.
 */
int test_omp_in_parallel()
{
  int serial;
  int isparallel;

  serial = 1;
  isparallel = 0;
  serial = omp_in_parallel();

  #pragma omp parallel
  {
    #pragma omp single
    {
      isparallel = omp_in_parallel();
    }
  }
  return (!(serial) && isparallel);
}

int main()
{
  int i;
  int num_failed=0;

  // the test requires more than 1 thread to pass
  omp_set_dynamic(0); // disable dynamic adjustment of threads
  if (omp_get_max_threads() == 1)
    omp_set_num_threads(2); // set 2 threads if no HW resources available

  for(i = 0; i < REPETITIONS; i++) {
    if(!test_omp_in_parallel()) {
      num_failed++;
    }
  }
  return num_failed;
}
OpenPOWER on IntegriCloud