gcc.c-torture/execute/builtins/fputs.c: fputs_unlocked prototype
[official-gcc.git] / libgomp / testsuite / libgomp.c / target-11.c
blob625c2863f4b2476f869bc5234946ec686add0ddc
1 /* { dg-require-effective-target offload_device_nonshared_as } */
3 #include <stdlib.h>
4 #include <assert.h>
6 #define N 32
8 void test_array_section (int *p)
10 #pragma omp target data map(alloc: p[0:N])
12 int ok = 1;
13 for (int i = 10; i < 10 + 4; i++)
14 p[i] = 997 * i;
16 #pragma omp target map(always to:p[10:4]) map(tofrom: ok)
17 for (int i = 10; i < 10 + 4; i++)
18 if (p[i] != 997 * i)
19 ok = 0;
21 assert (ok);
23 #pragma omp target map(always from:p[7:9])
24 for (int i = 0; i < N; i++)
25 p[i] = i;
29 int main ()
31 int aa = 0, bb = 0, cc = 0, dd = 0;
33 #pragma omp target data map(tofrom: aa) map(to: bb) map(from: cc, dd)
35 int ok;
36 aa = bb = cc = 1;
38 /* Set dd on target to 0 for the further check. */
39 #pragma omp target map(always to: dd)
42 dd = 1;
43 #pragma omp target map(tofrom: aa) map(always to: bb) \
44 map(always from: cc) map(to: dd) map(from: ok)
46 /* bb is always to, aa and dd are not. */
47 ok = (aa == 0) && (bb == 1) && (dd == 0);
48 aa = bb = cc = dd = 2;
51 assert (ok);
52 assert (aa == 1);
53 assert (bb == 1);
54 assert (cc == 2); /* cc is always from. */
55 assert (dd == 1);
57 dd = 3;
58 #pragma omp target map(from: cc) map(always to: dd) map(from: ok)
60 ok = (dd == 3); /* dd is always to. */
61 cc = dd = 4;
64 assert (ok);
65 assert (cc == 2);
66 assert (dd == 3);
69 assert (aa == 2);
70 assert (bb == 1);
71 assert (cc == 4);
72 assert (dd == 4);
74 int *array = calloc (N, sizeof (int));
75 test_array_section (array);
77 for (int i = 0; i < 7; i++)
78 assert (array[i] == 0);
79 for (int i = 7; i < 7 + 9; i++)
80 assert (array[i] == i);
81 for (int i = 7 + 9; i < N; i++)
82 assert (array[i] == 0);
84 free (array);
85 return 0;