aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c/examples-4/simd-1.c
blob: 5baaf307639e9a3024b26e1be274cbe706b5c51e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* { dg-do run } */
/* { dg-additional-options "-msse2" { target sse2_runtime } } */
/* { dg-additional-options "-mavx" { target avx_runtime } } */

#define N 100
#define OFF 32
#define EPS 0.0000000000000001

#include <stdlib.h>

void init(double *a, double *a_ref, double *b, double *c, int n, int ioff)
{
  int i;
  for ( i = 0; i < n; i++ )
  {
    a[i] = i*i;
    a_ref[i] = a[i];
    b[i] = i+i;
  }

  int s = -1;
  for ( i = 0; i < n+ioff; i++ )
  {
    c[i] = s*3;
    s = -s;
  }
}

void star( double *a, double *b, double *c, int n, int *ioff )
{
  int i;
  #pragma omp simd
  for ( i = 0; i < n; i++ )
    a[i] *= b[i] * c[i+ *ioff];
}

void star_ref( double *a, double *b, double *c, int n, int *ioff )
{
  int i;
  for ( i = 0; i < n; i++ )
    a[i] *= b[i] * c[i+ *ioff];
}

void check (double *a, double *b)
{
  int i;
  for (i = 0; i < N; i++)
    if (a[i] - b[i] > EPS || b[i] - a[i] > EPS)
      abort ();
}

int main ()
{
  double a[N], a_ref[N], b[N], c[N+OFF];
  int ioff = OFF;

  init(a, a_ref, b, c, N, ioff);

  star(a, b, c, N, &ioff);
  star_ref(a_ref, b, c, N, &ioff);

  check(a, a_ref);

  return 0;
}