aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/cancel-taskgroup-3.c
blob: 9e07cc10b6563f6ab8415363b9042c6d650a98f2 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* { dg-do run { target tls_runtime } } */
/* { dg-set-target-env-var OMP_CANCELLATION "true" } */

#include <stdlib.h>
#include <omp.h>

int t;
#pragma omp threadprivate (t)

int
main ()
{
  int a = 0, i;
  #pragma omp parallel
  #pragma omp taskgroup
  {
    #pragma omp task
    {
      #pragma omp cancel taskgroup
      if (omp_get_cancellation ())
	abort ();
    }
    #pragma omp taskwait
    #pragma omp for reduction (task, +: a)
    for (i = 0; i < 64; ++i)
      {
	a++;
	#pragma omp task in_reduction (+: a)
	{
	  volatile int zero = 0;
	  a += zero;
	  if (omp_get_cancellation ())
	    abort ();
	}
      }
    if (a != 64)
      abort ();
    #pragma omp task
    {
      if (omp_get_cancellation ())
	abort ();
    }
  }
  a = 0;
  #pragma omp parallel
  #pragma omp taskgroup
  {
    int p;
    #pragma omp for reduction (task, +: a)
    for (i = 0; i < 64; ++i)
      {
	a++;
	t = 1;
	#pragma omp task in_reduction (+: a)
	{
	  volatile int zero = 0;
	  a += zero;
	  #pragma omp cancel taskgroup
	  if (omp_get_cancellation ())
	    abort ();
	}
      }
    if (a != 64)
      abort ();
    p = t;
    #pragma omp task firstprivate (p)
    {
      if (p && omp_get_cancellation ())
	abort ();
    }
  }
  return 0;
}