aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/target-map-iterators-3.c
blob: be30fa65d8074ca64d68b507e690c27bf8f4f25d (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
/* { dg-do run } */
/* { dg-require-effective-target offload_device_nonshared_as } */

/* Test transfer of dynamically-allocated arrays to target using map
   iterators, with multiple iterators and function calls in the iterator
   expression.  */

#include <stdlib.h>

#define DIM1 16
#define DIM2 15

int mkarrays (int *x[], int *y[])
{
  int expected = 0;

  for (int i = 0; i < DIM1; i++)
    {
      x[i] = (int *) malloc (DIM2 * sizeof (int));
      y[i] = (int *) malloc (sizeof (int));
      *y[i] = rand ();
      for (int j = 0; j < DIM2; j++)
	{
	  x[i][j] = rand ();
	  expected += x[i][j] * *y[i];
	}
    }

  return expected;
}

int f (int i, int j)
{
  return i * 4 + j;
}

int main (void)
{
  int *x[DIM1], *y[DIM1];
  int sum;

  int expected = mkarrays (x, y);

  #pragma omp target enter data map(to: x, y)
  #pragma omp target map(iterator(i=0:DIM1/4, j=0:4), to: x[f(i, j)][:DIM2]) \
		     map(iterator(i=0:DIM1), to: y[i][:1]) \
		     map(from: sum)
    {
      sum = 0;
      for (int i = 0; i < DIM1; i++)
	for (int j = 0; j < DIM2; j++)
	  sum += x[i][j] * y[i][0];
    }

  return sum - expected;
}