aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/cilk-plus/pragma_simd_tests/execute/p_simd_test2.c
blob: 14d53f643087925df28bb26bad850d7bfd2dd245 (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
/* { dg-do run } */
/* { dg-options "-O3 -ftree-vectorize -fcilkplus -w" } */


#define N 256
#if HAVE_IO
#include <stdio.h>
#endif
#include <malloc.h>

int
reduction_simd (int *a)
{
  int i, s = 0;

#pragma simd reduction (+:s) private(i)
  for (i = 0; i < N; i++)
    {
      s += a[i];
    }

  return s;
}

int
main ()
{
  int *a = (int *) malloc (N * sizeof (int));
  int i, s = (N - 1) * N / 2;

  for (i = 0; i < N; i++)
    {
      a[i] = i;
    }
#if HAVE_IO
  printf ("%d, %d\n", s, reduction_simd (a));
#endif
  if (s == reduction_simd (a))
    return 0;
  else
    return 1;
}