1 /* { dg-do run } */ 2 3 #include <stdlib.h> 4 5 #define EPS 0.000001 6 #define N 100000 7 8 #pragma omp declare target 9 float p1[N], p2[N], v1[N], v2[N]; 10 #pragma omp end declare target 11 init()12void init () 13 { 14 int i, s = -1; 15 for (i = 0; i < N; i++) 16 { 17 v1[i] = s * 0.01; 18 v2[i] = i; 19 s = -s; 20 } 21 } 22 check()23void check () 24 { 25 int i; 26 for (i = 0; i < N; i++) 27 if (p1[i] - p2[i] > EPS || p2[i] - p1[i] > EPS) 28 abort (); 29 } 30 vec_mult_ref()31void vec_mult_ref () 32 { 33 int i; 34 for (i = 0; i < N; i++) 35 p1[i] = v1[i] * v2[i]; 36 } 37 vec_mult()38void vec_mult () 39 { 40 int i; 41 42 #pragma omp target update to(v1, v2) 43 44 #pragma omp target 45 #pragma omp parallel for 46 for (i = 0; i < N; i++) 47 p2[i] = v1[i] * v2[i]; 48 49 #pragma omp target update from(p2) 50 } 51 main()52int main () 53 { 54 init (); 55 56 vec_mult_ref (); 57 vec_mult (); 58 59 check (); 60 61 return 0; 62 } 63