aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/task-reduction-16.c
blob: 44d32c7bc25a7866c6a111707672f8a001bcfd0c (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
74
75
76
extern
#ifdef __cplusplus
"C"
#endif
void abort (void);
int a, b[3] = { 1, 1, 1 };
unsigned long int c[2] = { ~0UL, ~0UL };

void
bar (int i)
{
  #pragma omp task in_reduction (*: b[:3]) in_reduction (&: c[1:]) \
	      in_reduction (+: a)
  {
    a += 4;
    b[1] *= 4;
    c[1] &= ~(1UL << (i + 16));
  }
}

void
foo (int x)
{
  #pragma omp scope reduction (task, +: a)
  {
    #pragma omp scope reduction (task, *: b)
    {
      #pragma omp scope reduction (task, &: c[1:1])
      {
	#pragma omp barrier
	#pragma omp sections
	{
	  {
	    a++; b[0] *= 2; bar (2); b[2] *= 3; c[1] &= ~(1UL << 2);
	  }
	#pragma omp section
	{ b[0] *= 2; bar (4); b[2] *= 3; c[1] &= ~(1UL << 4); a++; }
	#pragma omp section
	{ bar (6); b[2] *= 3; c[1] &= ~(1UL << 6); a++; b[0] *= 2; }
	#pragma omp section
	{ b[2] *= 3; c[1] &= ~(1UL << 8); a++; b[0] *= 2; bar (8); }
	#pragma omp section
	{ c[1] &= ~(1UL << 10); a++; b[0] *= 2; bar (10); b[2] *= 3; }
	#pragma omp section
	{ a++; b[0] *= 2; b[2] *= 3; c[1] &= ~(1UL << 12); bar (12); }
	#pragma omp section
	if (x)
	  {
	    a++; b[0] *= 2; b[2] *= 3; bar (14); c[1] &= ~(1UL << 14);
	  }
	}
      }
    }
  }
}

int
main ()
{
  volatile int one = 1;
  foo (!one);
  if (a != 30 || b[0] != 64 || b[1] != (1 << 12) || b[2] != 3 * 3 * 3 * 3 * 3 * 3
      || c[0] != ~0UL || c[1] != ~0x15541554UL)
    abort ();
  a = 0;
  b[0] = 1;
  b[1] = 1;
  b[2] = 1;
  c[1] = ~0UL;
  #pragma omp parallel
  foo (one);
  if (a != 35 || b[0] != 128 || b[1] != (1 << 14) || b[2] != 3 * 3 * 3 * 3 * 3 * 3 * 3
      || c[0] != ~0UL || c[1] != ~0x55545554UL)
    abort ();
  return 0;
}