1 /* { dg-do run } */
2
3 #include <stdlib.h>
4
5 #define EPS 0.00001
6 #define N 10000
7
init(float * a,float * b,int n)8 void init (float *a, float *b, int n)
9 {
10 int i;
11 for (i = 0; i < n; i++)
12 {
13 a[i] = 0.1 * i;
14 b[i] = 0.01 * i * i;
15 }
16 }
17
vec_mult_ref(float * p,float * v1,float * v2,int n)18 void vec_mult_ref (float *p, float *v1, float *v2, int n)
19 {
20 int i;
21 for (i = 0; i < n; i++)
22 p[i] = v1[i] * v2[i];
23 }
24
vec_mult(float * p,float * v1,float * v2,int n)25 void vec_mult (float *p, float *v1, float *v2, int n)
26 {
27 int i;
28 #pragma omp target teams map(to: v1[0:n], v2[:n]) map(from: p[0:n])
29 #pragma omp distribute simd
30 for (i = 0; i < n; i++)
31 p[i] = v1[i] * v2[i];
32 }
33
check(float * a,float * b,int n)34 void check (float *a, float *b, int n)
35 {
36 int i;
37 for (i = 0 ; i < n ; i++)
38 {
39 float err = (a[i] == 0.0) ? b[i] : (b[i] - a[i]) / a[i];
40 if (((err > 0) ? err : -err) > EPS)
41 abort ();
42 }
43 }
44
main()45 int main ()
46 {
47 float *p1 = (float *) malloc (N * sizeof (float));
48 float *p2 = (float *) malloc (N * sizeof (float));
49 float *v1 = (float *) malloc (N * sizeof (float));
50 float *v2 = (float *) malloc (N * sizeof (float));
51
52 init (v1, v2, N);
53
54 vec_mult_ref (p1, v1, v2, N);
55 vec_mult (p2, v1, v2, N);
56
57 check (p1, p2, N);
58
59 free (p1);
60 free (p2);
61 free (v1);
62 free (v2);
63
64 return 0;
65 }
66