1 /* { dg-do run } */
2 /* { dg-additional-options "-msse2" { target sse2_runtime } } */
3 /* { dg-additional-options "-mavx" { target avx_runtime } } */
4 
5 #define N 128
6 #define M 16
7 #define EPS 0.0000000000000001
8 #define SAFELEN 16
9 
10 #include <stdlib.h>
11 
init(double a[N][N],double b[N][N],int n)12 void init(double a[N][N], double b[N][N], int n)
13 {
14   int i, j, s = -1;
15   for (i = 0; i < n; i++)
16   {
17     for (j = 0; j < n; j++)
18     {
19        a[i][j] = i * j * s;
20        b[i][j] = i + j + s;
21        s = -s;
22     }
23   }
24 }
25 
work(double a[N][N],double b[N][N],double c[N][N],int n)26 void work( double a[N][N], double b[N][N], double c[N][N], int n )
27 {
28    int i, j;
29    double tmp;
30    #pragma omp for simd collapse(2) private(tmp)
31    for (i = 0; i < n; i++)
32    {
33       for (j = 0; j < n; j++)
34       {
35          tmp = a[i][j] + b[i][j];
36          c[i][j] = tmp;
37       }
38    }
39 }
40 
work_ref(double a[N][N],double b[N][N],double c[N][N],int n)41 void work_ref( double a[N][N], double b[N][N], double c[N][N], int n )
42 {
43    int i, j;
44    double tmp;
45    for (i = 0; i < n; i++)
46    {
47       for (j = 0; j < n; j++)
48       {
49          tmp = a[i][j] + b[i][j];
50          c[i][j] = tmp;
51       }
52    }
53 }
54 
check(double a[N][N],double b[N][N])55 void check (double a[N][N], double b[N][N])
56 {
57   int i, j;
58   for (i = 0; i < N; i++)
59     for (j = 0; j < N; j++)
60       if (a[i][j] - b[i][j] > EPS || b[i][j] - a[i][j] > EPS)
61         abort ();
62 }
63 
main()64 int main ()
65 {
66   double a[N][N], b[N][N], c[N][N], c_ref[N][N];
67 
68   init(a, b, N);
69 
70   work(a, b, c, N);
71   work_ref(a, b, c_ref, N);
72 
73   check(c, c_ref);
74 
75   return 0;
76 }
77