aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/gomp/imperfect5.c
blob: da92578ed25285dc47ceadfcfafc9c6dbb6840fb (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* { dg-do compile } */

/* This test case is expected to fail due to errors.  */

#define N 30
#define M 3

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

extern void dostuff (int, int);

/* good1 and good2 should compile without error.  */
void
good1 (void)
{
  int x, shift;

  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;
	}
    }
}

void
good2 (void)
{
  int x, shift;
  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];
	}
    }
}

/* Adding intervening code should trigger an error.  */

void
bad1 (void)
{
  int x, shift;

  x = 0;
  #pragma omp parallel for simd collapse(2) reduction(inscan,+: x) private(shift)
  for (int i = 0; i < N; i++)  /* { dg-error "inner loops must be perfectly nested" } */
    {
      dostuff (i, 0);
      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;
	}
    }
}

void
bad2 (void)
{
  int x, shift;
  x = 0;

  #pragma omp parallel for simd collapse(2) reduction(inscan,+: x) private(shift)
  for (int i = 0; i < N; i++)  /* { dg-error "inner loops must be perfectly nested" } */
    {
      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];
	}
      dostuff (i, 1);
    }
}