aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.oacc-c-c++-common/parallel-reduction.c
blob: 077571f29f0aadbb7673e8124d000830cf6e5c51 (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
/* { dg-do run } */
/* { dg-additional-options "-w" } */

#include <stdlib.h>
#include <openacc.h>

#define N 10

int
main ()
{
  int s1 = 0, s2 = 0;
  int i;
  int dummy = 0;

#pragma acc data copy (dummy)
  {
#pragma acc parallel num_gangs (N) reduction (+:s1) copy(s1)
    {
      s1++;
    }
  }

  if (acc_get_device_type () == acc_device_host)
    {
      if (s1 != 1)
	abort ();
    }
  else
    {
      if (s1 != N)
	abort ();
    }

  s1 = 0;
  s2 = 0;

#pragma acc parallel num_gangs (10) reduction (+:s1, s2) copy(s1, s2)
  {
    s1++;
    s2 += N;
  }

  if (acc_get_device_type () == acc_device_host)
    {
      if (s1 != 1)
	abort ();
      if (s2 != N)
	abort ();
    }
  else
    {
      if (s1 != N)
	abort ();
      if (s2 != N*N)
	abort ();
    }

  s1 = 0;

#pragma acc parallel num_gangs (10) reduction (+:s1) copy(s1)
  {
#pragma acc loop gang reduction (+:s1)
    for (i = 0; i < 10; i++)
      s1++;
  }

  if (s1 != N)
    abort ();

  return 0;
}