AVR: Assert minimal required bit width of section_common::flags.
[gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / lib-32.c
blob9ec345361d8e215b535d93e9e537fbd63e6f09df
1 /* acc_present_or_create, acc_present_or_copyin, etc. */
2 /* See also Fortran variants in "../libgomp.oacc-fortran/lib-32*". */
4 #include <stdbool.h>
5 #include <stdlib.h>
6 #include <openacc.h>
8 int
9 main (int argc, char **argv)
11 int *h, *d;
12 const int N = 10000;
13 const int S = N * sizeof *h;
14 bool shared_mem;
16 h = (int *) malloc (S);
17 if (!h)
18 abort ();
19 for (int i = 0; i < N; ++i)
20 h[i] = i + 0;
22 shared_mem = acc_is_present (h, S);
24 d = (int *) acc_present_or_create (h, S);
25 if (!d)
26 abort ();
27 if (shared_mem)
28 if (h != d)
29 abort ();
30 if (!acc_is_present (h, S))
31 abort ();
33 #pragma acc parallel loop deviceptr (d)
34 for (int i = 0; i < N; ++i)
36 d[i] = i + 1;
39 for (int i = 0; i < N; ++i)
41 if (h[i] != i + (shared_mem ? 1 : 0))
42 abort ();
43 h[i] = i + 2;
47 int *d_ = (int *) acc_present_or_create (h, S);
48 if (d_ != d)
49 abort ();
52 #pragma acc parallel loop deviceptr (d)
53 for (int i = 0; i < N; ++i)
55 if (d[i] != i + (shared_mem ? 2 : 1))
56 abort ();
57 d[i] = i + 3;
60 for (int i = 0; i < N; ++i)
62 if (h[i] != i + (shared_mem ? 3 : 2))
63 abort ();
64 h[i] = i + 4;
68 int *d_ = (int *) acc_pcreate (h, S);
69 if (d_ != d)
70 abort ();
73 #pragma acc parallel loop deviceptr (d)
74 for (int i = 0; i < N; ++i)
76 if (d[i] != i + (shared_mem ? 4 : 3))
77 abort ();
78 d[i] = i + 5;
81 for (int i = 0; i < N; ++i)
83 if (h[i] != i + (shared_mem ? 5 : 4))
84 abort ();
85 h[i] = i + 6;
89 int *d_ = (int *) acc_present_or_copyin (h, S);
90 if (d_ != d)
91 abort ();
94 #pragma acc parallel loop deviceptr (d)
95 for (int i = 0; i < N; ++i)
97 if (d[i] != i + (shared_mem ? 6 : 5))
98 abort ();
99 d[i] = i + 7;
102 for (int i = 0; i < N; ++i)
104 if (h[i] != i + (shared_mem ? 7 : 6))
105 abort ();
106 h[i] = i + 8;
110 int *d_ = (int *) acc_pcopyin (h, S);
111 if (d_ != d)
112 abort ();
115 #pragma acc parallel loop deviceptr (d)
116 for (int i = 0; i < N; ++i)
118 if (d[i] != i + (shared_mem ? 8 : 7))
119 abort ();
120 d[i] = i + 9;
123 for (int i = 0; i < N; ++i)
125 if (h[i] != i + (shared_mem ? 9 : 8))
126 abort ();
127 h[i] = i + 10;
130 acc_copyout_finalize (h, S);
131 d = NULL;
132 if (!shared_mem)
133 if (acc_is_present (h, S))
134 abort ();
136 for (int i = 0; i < N; ++i)
138 if (h[i] != i + (shared_mem ? 10 : 9))
139 abort ();
142 d = (int *) acc_pcopyin (h, S);
143 if (!d)
144 abort ();
145 if (shared_mem)
146 if (h != d)
147 abort ();
148 if (!acc_is_present (h, S))
149 abort ();
151 #pragma acc parallel loop deviceptr (d)
152 for (int i = 0; i < N; ++i)
154 if (d[i] != i + (shared_mem ? 10 : 9))
155 abort ();
156 d[i] = i + 11;
159 for (int i = 0; i < N; ++i)
161 if (h[i] != i + (shared_mem ? 11 : 9))
162 abort ();
163 h[i] = i + 12;
167 int *d_ = (int *) acc_pcopyin (h, S);
168 if (d_ != d)
169 abort ();
172 #pragma acc parallel loop deviceptr (d)
173 for (int i = 0; i < N; ++i)
175 if (d[i] != i + (shared_mem ? 12 : 11))
176 abort ();
177 d[i] = i + 13;
180 for (int i = 0; i < N; ++i)
182 if (h[i] != i + (shared_mem ? 13 : 12))
183 abort ();
184 h[i] = i + 14;
188 int *d_ = (int *) acc_pcreate (h, S);
189 if (d_ != d)
190 abort ();
193 #pragma acc parallel loop deviceptr (d)
194 for (int i = 0; i < N; ++i)
196 if (d[i] != i + (shared_mem ? 14 : 13))
197 abort ();
198 d[i] = i + 15;
201 for (int i = 0; i < N; ++i)
203 if (h[i] != i + (shared_mem ? 15 : 14))
204 abort ();
205 h[i] = i + 16;
209 int *d_ = (int *) acc_pcreate (h, S);
210 if (d_ != d)
211 abort ();
214 #pragma acc parallel loop deviceptr (d)
215 for (int i = 0; i < N; ++i)
217 if (d[i] != i + (shared_mem ? 16 : 15))
218 abort ();
219 d[i] = i + 17;
222 for (int i = 0; i < N; ++i)
224 if (h[i] != i + (shared_mem ? 17 : 16))
225 abort ();
226 h[i] = i + 18;
229 acc_update_self (h, S);
230 if (!acc_is_present (h, S))
231 abort ();
233 for (int i = 0; i < N; ++i)
235 if (h[i] != i + (shared_mem ? 18 : 17))
236 abort ();
239 acc_delete_finalize (h, S);
240 d = NULL;
241 if (!shared_mem)
242 if (acc_is_present (h, S))
243 abort();
245 free (h);
247 return 0;