| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-additional-options "-msse2" { target sse2_runtime } } */ |
| 3 |
/* { dg-additional-options "-mavx" { target avx_runtime } } */ |
| 4 |
|
| 5 |
#define N 100 |
| 6 |
#define EPS 0.0000000000000001 |
| 7 |
|
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
void init(double *a, double *a_ref, double *b, int n) |
| 11 |
{ |
| 12 |
int i, s = -1; |
| 13 |
for ( i = 0; i < n; i++ ) |
| 14 |
{ |
| 15 |
a[i] = i*i*s; |
| 16 |
a_ref[i] = a[i]; |
| 17 |
b[i] = i+i; |
| 18 |
s = -s; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
double work( double *a, double *b, int n ) |
| 23 |
{ |
| 24 |
int i; |
| 25 |
double tmp, sum; |
| 26 |
sum = 0.0; |
| 27 |
#pragma omp simd private(tmp) reduction(+:sum) |
| 28 |
for (i = 0; i < n; i++) { |
| 29 |
tmp = a[i] + b[i]; |
| 30 |
sum += tmp; |
| 31 |
} |
| 32 |
return sum; |
| 33 |
} |
| 34 |
|
| 35 |
double work_ref( double *a, double *b, int n ) |
| 36 |
{ |
| 37 |
int i; |
| 38 |
double tmp, sum; |
| 39 |
sum = 0.0; |
| 40 |
for (i = 0; i < n; i++) { |
| 41 |
tmp = a[i] + b[i]; |
| 42 |
sum += tmp; |
| 43 |
} |
| 44 |
return sum; |
| 45 |
} |
| 46 |
|
| 47 |
int main () |
| 48 |
{ |
| 49 |
double a[N], a_ref[N], b[N], res, ref, diff; |
| 50 |
|
| 51 |
init(a, a_ref, b, N); |
| 52 |
|
| 53 |
res = work(a, b, N); |
| 54 |
ref = work_ref(a_ref, b, N); |
| 55 |
|
| 56 |
diff = res - ref; |
| 57 |
|
| 58 |
if (diff > EPS || -diff > EPS) |
| 59 |
abort (); |
| 60 |
|
| 61 |
return 0; |
| 62 |
} |