summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/test/worksharing/single/omp_single.c
blob: 49635798c2d085920fcfcee2be5b047ecff6d94e (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"

int test_omp_single()
{
  int nr_threads_in_single;
  int result;
  int nr_iterations;
  int i;

  nr_threads_in_single = 0;
  result = 0;
  nr_iterations = 0;

  #pragma omp parallel private(i)
  {
    for (i = 0; i < LOOPCOUNT; i++) {
      #pragma omp single
      {
        #pragma omp flush
        nr_threads_in_single++;
        #pragma omp flush
        nr_iterations++;
        nr_threads_in_single--;
        result = result + nr_threads_in_single;
      }
    }
  }
  return ((result == 0) && (nr_iterations == LOOPCOUNT));
} /* end of check_single*/

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

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