aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/imperfect5.c
blob: 7bd4f12d472b456fe2019efa5fd2bb037820ed4d (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
/* { dg-do run } */

#ifndef __cplusplus
extern void abort (void);
#else
extern "C" void abort (void);
#endif

static int inner_loop_count = 0;
static int intervening_code_count = 0;

void
g (int x, int y)
{
  inner_loop_count++;
}

int
foo (int imax, int jmax)
{
  int j = 0;

#pragma omp for collapse(2)
  for (int i = 0; i < imax; ++i)
    {
      /* All the intervening code at the same level must be executed
	 the same number of times.  */
      ++intervening_code_count;
      for (int j = 0; j < jmax; ++j)
	{
	  g (i, j);
	}
      /* This is the outer j, not the one from the inner collapsed loop.  */
      ++j;
    }
  return j;
}

int
main (void)
{
  int j = foo (5, 3);
  if (j != intervening_code_count)
    abort ();
  if (inner_loop_count != 5 * 3)
    abort ();
  if (intervening_code_count < 5 || intervening_code_count > 5 * 3)
    abort ();
}