aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/scan-1.c
blob: d1951a34696fcf26ea10507d2ce2d5f88ce8787b (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
66
67
68
#define N 30
#define M 3

int a[N][M], b[N][M], c[N][M];

int
main()
{
  int x, y, shift;
  int j = 0;
  for (int i = 0; i < N; i++)
    {
      a[i][0] = (i+1)*32;
      a[i][1] = (i+1)*17;
      a[i][2] = (i+1)*11;
      b[i][0] = (i+1)*7;
      b[i][1] = (i+1)*5;
      b[i][2] = (i+1)*3;
    }

  x = 0;
  #pragma omp parallel for simd collapse(2) reduction(inscan,+: x) private(shift)
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      {
	x += a[i][j];
	x += b[i][j];
        #pragma omp scan inclusive(x)
        shift = i + 29*j;
        c[i][j] = x + shift;
      }

  y = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      {
	y += a[i][j] + b[i][j];
	if (c[i][j] != y + i + 29*j)
	  __builtin_abort ();
      }
  if (x != y)
    __builtin_abort ();

  x = 0;
  #pragma omp parallel for simd collapse(2) reduction(inscan,+: x) private(shift)
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      {
	shift = i + 29*j;
	c[i][j] = x + shift;
	#pragma omp scan exclusive(x)
	x += a[i][j];
	x += b[i][j];
      }

  y = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++)
      {
	if (c[i][j] != y + i + 29*j)
	  __builtin_abort ();
	y += a[i][j] + b[i][j];
      }
  if (x != y)
    __builtin_abort ();

  return 0;
}