summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/test/worksharing/single/omp_single_nowait.c
blob: 983748d59edd6ae79315cc903a126c4130f54b6c (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
45
46
47
48
49
50
51
52
53
54
55
56
57
// RUN: %libomp-compile-and-run
#include <stdio.h>
#include "omp_testsuite.h"

int my_iterations;
#pragma omp threadprivate(my_iterations)

int test_omp_single_nowait()
{
  int nr_iterations;
  int total_iterations = 0;
  int i;

  nr_iterations = 0;
  my_iterations = 0;

  #pragma omp parallel private(i)
  {
    for (i = 0; i < LOOPCOUNT; i++) {
      #pragma omp single nowait
      {
        #pragma omp atomic  
        nr_iterations++;
      }
    }
  }

  #pragma omp parallel private(i) 
  {
    my_iterations = 0;
    for (i = 0; i < LOOPCOUNT; i++) {
      #pragma omp single nowait
      {
        my_iterations++;
      }
    }
    #pragma omp critical
    {
      total_iterations += my_iterations;
    }

  }
  return ((nr_iterations == LOOPCOUNT) && (total_iterations == LOOPCOUNT));
} /* end of check_single_nowait*/

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

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