Skip gnat.dg/prot7.adb on hppa.
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / target-memcpy-async-2.c
blobd1353a5000cb785d464b3ed704d6ba3119808ea1
1 /* Test for omp_target_memcpy_async considering dependence objects. */
3 #include <omp.h>
4 #include <stdlib.h>
6 int
7 main ()
9 int d = omp_get_default_device ();
10 int id = omp_get_initial_device ();
11 int a[128], b[64], c[32], e[16], q[128], i;
12 void *p;
14 if (d < 0 || d >= omp_get_num_devices ())
15 d = id;
17 p = omp_target_alloc (130 * sizeof (int), d);
18 if (p == NULL)
19 return 0;
21 for (i = 0; i < 128; ++i)
22 a[i] = i + 1;
23 for (i = 0; i < 64; ++i)
24 b[i] = i + 2;
25 for (i = 0; i < 32; i++)
26 c[i] = 0;
27 for (i = 0; i < 16; i++)
28 e[i] = i + 4;
30 omp_depend_t obj[2];
32 #pragma omp parallel num_threads(5)
33 #pragma omp single
35 #pragma omp task depend(out: p)
36 omp_target_memcpy (p, a, 128 * sizeof (int), 0, 0, d, id);
38 #pragma omp task depend(inout: p)
39 omp_target_memcpy (p, b, 64 * sizeof (int), 0, 0, d, id);
41 #pragma omp task depend(out: c)
42 for (i = 0; i < 32; i++)
43 c[i] = i + 3;
45 #pragma omp depobj(obj[0]) depend(inout: p)
46 #pragma omp depobj(obj[1]) depend(in: c)
47 omp_target_memcpy_async (p, c, 32 * sizeof (int), 0, 0, d, id, 2, obj);
49 #pragma omp task depend(in: p)
50 omp_target_memcpy (p, e, 16 * sizeof (int), 0, 0, d, id);
53 #pragma omp taskwait
55 for (i = 0; i < 128; ++i)
56 q[i] = 0;
57 omp_target_memcpy (q, p, 128 * sizeof(int), 0, 0, id, d);
58 for (i = 0; i < 16; ++i)
59 if (q[i] != i + 4)
60 abort ();
61 for (i = 16; i < 32; ++i)
62 if (q[i] != i + 3)
63 abort ();
64 for (i = 32; i < 64; ++i)
65 if (q[i] != i + 2)
66 abort ();
67 for (i = 64; i < 128; ++i)
68 if (q[i] != i + 1)
69 abort ();
71 omp_target_free (p, d);
73 return 0;