aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/target-2.C
blob: 35e910acc2e3da4c1b83dc8f4282eec22ec1a3cf (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
// { dg-additional-sources "target-2-aux.cc" }

extern "C" void abort (void);

void
fn1 (double *x, double *y, int z)
{
  int i;
  for (i = 0; i < z; i++)
    {
      x[i] = i & 31;
      y[i] = (i & 63) - 30;
    }
}

double b[1024];
double (&br) [1024] = b;
double cbuf[1024];
double *c = cbuf;
double *&cr = c;
extern double (&fr) [1024];
extern double *&gr;

double
fn2 (int x, double (&dr) [1024], double *&er)
{
  double s = 0;
  double h[1024];
  double (&hr) [1024] = h;
  double ibuf[1024];
  double *i = ibuf;
  double *&ir = i;
  int j;
  fn1 (hr + 2 * x, ir + 2 * x, x);
  #pragma omp target map(to: br[:x], cr[0:x], dr[x:x], er[x:x]) \
		     map(to: fr[0:x], gr[0:x], hr[2 * x:x], ir[2 * x:x])
    #pragma omp parallel for reduction(+:s)
      for (j = 0; j < x; j++)
	s += br[j] * cr[j] + dr[x + j] + er[x + j]
	     + fr[j] + gr[j] + hr[2 * x + j] + ir[2 * x + j];
  return s;
}

int
main ()
{
  double d[1024];
  double ebuf[1024];
  double *e = ebuf;
  fn1 (br, cr, 128);
  fn1 (d + 128, e + 128, 128);
  fn1 (fr, gr, 128);
  double h = fn2 (128, d, e);
  if (h != 20416.0)
    abort ();
  return 0;
}