1// { dg-options "-O2 -fopenmp" } 2// { dg-additional-sources "target-2-aux.cc" } 3 4extern "C" void abort (void); 5 6void 7fn1 (double *x, double *y, int z) 8{ 9 int i; 10 for (i = 0; i < z; i++) 11 { 12 x[i] = i & 31; 13 y[i] = (i & 63) - 30; 14 } 15} 16 17double b[1024]; 18double (&br) [1024] = b; 19double cbuf[1024]; 20double *c = cbuf; 21double *&cr = c; 22extern double (&fr) [1024]; 23extern double *&gr; 24 25double 26fn2 (int x, double (&dr) [1024], double *&er) 27{ 28 double s = 0; 29 double h[1024]; 30 double (&hr) [1024] = h; 31 double ibuf[1024]; 32 double *i = ibuf; 33 double *&ir = i; 34 int j; 35 fn1 (hr + 2 * x, ir + 2 * x, x); 36 #pragma omp target map(to: br[:x], cr[0:x], dr[x:x], er[x:x]) \ 37 map(to: fr[0:x], gr[0:x], hr[2 * x:x], ir[2 * x:x]) 38 #pragma omp parallel for reduction(+:s) 39 for (j = 0; j < x; j++) 40 s += br[j] * cr[j] + dr[x + j] + er[x + j] 41 + fr[j] + gr[j] + hr[2 * x + j] + ir[2 * x + j]; 42 return s; 43} 44 45int 46main () 47{ 48 double d[1024]; 49 double ebuf[1024]; 50 double *e = ebuf; 51 fn1 (br, cr, 128); 52 fn1 (d + 128, e + 128, 128); 53 fn1 (fr, gr, 128); 54 double h = fn2 (128, d, e); 55 if (h != 20416.0) 56 abort (); 57 return 0; 58} 59