aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.hsa.c/gridify-4.c
blob: c3fbdbf55d4afa6eaa3b031adc567d86f9feb28d (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
#define THE_LOOP \
  for (i = j + 1; i < n; i += 3) \
    a[i] = i

void __attribute__((noinline, noclone))
foo (int j, int n, int *a)
{
#pragma omp parallel
  {
    #pragma omp single
    {
      int i;
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for shared(a) firstprivate(n) private(i) firstprivate(j)
      THE_LOOP;
    }
  }
}

void __attribute__((noinline, noclone))
bar (int j, int n, int *a)
{
  int i;
  THE_LOOP;
}

int main (int argc, char **argv)
{
  int n = 32;
  int *a = __builtin_malloc (sizeof (int) * n);
  int *ref = __builtin_malloc (sizeof (int) * n);
  int i, j = 4;

  __builtin_memset (a, 0, sizeof (int) * n);
  __builtin_memset (ref, 0, sizeof (int) * n);
  bar (j, n, ref);
  foo (j, n, a);
  for (i = 0; i < n; i ++)
    {
      if (a[i] != ref[i])
	__builtin_abort ();
    }
  return 0;
}