aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.oacc-c-c++-common/pr95270-2.c
blob: 0575e726738de53ec7170f6b1789466c8005195f (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
/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */

#include <assert.h>
#include <openacc.h>
#include <stdint.h>

#define N 128

int
main ()
{
  int *ptrarr[N];
  int otherarr[N];
  int sum = 0, hostsum = 0;

  for (int i = 0; i < N; i++)
    {
      otherarr[i] = i * 2 + 1;
      ptrarr[i] = &otherarr[N - 1 - i];
      hostsum += otherarr[i];
    }

  acc_copyin (otherarr, sizeof otherarr);
  acc_copyin (ptrarr, sizeof ptrarr);

  for (int i = 0; i < N; i++)
    {
      #pragma acc enter data attach(ptrarr[i])
    }

  #pragma acc parallel loop copyin(ptrarr[0:N], otherarr[0:N]) \
		       reduction(+:sum)
  for (int i = 0; i < N; i++)
    sum += *ptrarr[i];

  for (int i = 0; i < N; i++)
    {
      #pragma acc exit data detach(ptrarr[i])
    }

  assert (sum == hostsum);

  acc_delete (ptrarr, sizeof ptrarr);
  acc_delete (otherarr, sizeof otherarr);

  return 0;
}