Set num_threads to 50 on 32-bit hppa in two libgomp loop tests
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / alloc-11.c
blob5fbadf4406a1665dfbf14b8bc7c1e7991533594e
1 /* This testcase is mostly the same as alloc-9.c.
2 However, on systems where the numa and/or memkind libraries are
3 installed, libgomp uses those. This test ensures that the minimal
4 features work. Note: No attempt has been made to verify the parition
5 hints interleaved and nearest as the kernal purposely ignore them once
6 in a while and it would also require a 'dlopen' dance.
8 memkind is used for omp_high_bw_mem_space, omp_large_cap_mem_space
9 and partition = interleaved, albeit it won't be interleaved for
10 omp_large_cap_mem_space.
12 numa is used for partition = nearest, unless memkind is used. */
14 #include <omp.h>
15 #include <stdint.h>
16 #include <stdlib.h>
18 const omp_alloctrait_t traits2[]
19 = { { omp_atk_alignment, 16 },
20 { omp_atk_sync_hint, omp_atv_default },
21 { omp_atk_access, omp_atv_default },
22 { omp_atk_pool_size, 1024 },
23 { omp_atk_fallback, omp_atv_default_mem_fb },
24 { omp_atk_partition, omp_atv_nearest } };
25 omp_alloctrait_t traits3[]
26 = { { omp_atk_sync_hint, omp_atv_uncontended },
27 { omp_atk_alignment, 32 },
28 { omp_atk_access, omp_atv_all },
29 { omp_atk_pool_size, 512 },
30 { omp_atk_fallback, omp_atv_allocator_fb },
31 { omp_atk_fb_data, 0 },
32 { omp_atk_partition, omp_atv_interleaved } };
33 const omp_alloctrait_t traits4[]
34 = { { omp_atk_alignment, 128 },
35 { omp_atk_pool_size, 1024 },
36 { omp_atk_fallback, omp_atv_null_fb } };
38 int
39 main ()
41 int *volatile p = (int *) omp_alloc (3 * sizeof (int), omp_default_mem_alloc);
42 int *volatile q;
43 int *volatile r;
44 omp_alloctrait_t traits[4]
45 = { { omp_atk_alignment, 64 },
46 { omp_atk_fallback, omp_atv_null_fb },
47 { omp_atk_pool_size, 4096 },
48 { omp_atk_partition, omp_atv_nearest } };
49 omp_alloctrait_t traits5[2]
50 = { { omp_atk_fallback, omp_atv_null_fb },
51 { omp_atk_pool_size, 4096 } };
52 omp_allocator_handle_t a, a2;
54 if ((((uintptr_t) p) % __alignof (int)) != 0)
55 abort ();
56 p[0] = 1;
57 p[1] = 2;
58 p[2] = 3;
59 p = (int *) omp_realloc (p, 4 * sizeof (int), omp_high_bw_mem_alloc, omp_high_bw_mem_alloc);
60 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 1 || p[1] != 2 || p[2] != 3)
61 abort ();
62 p[0] = 4;
63 p[1] = 5;
64 p[2] = 6;
65 p[3] = 7;
66 p = (int *) omp_realloc (p, 2 * sizeof (int), omp_high_bw_mem_alloc, omp_high_bw_mem_alloc);
67 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 4 || p[1] != 5)
68 abort ();
69 p[0] = 8;
70 p[1] = 9;
71 if (omp_realloc (p, 0, omp_null_allocator, omp_high_bw_mem_alloc) != NULL)
72 abort ();
73 p = (int *) omp_realloc (NULL, 2 * sizeof (int), omp_large_cap_mem_alloc, omp_null_allocator);
74 if ((((uintptr_t) p) % __alignof (int)) != 0)
75 abort ();
76 p[0] = 1;
77 p[1] = 2;
78 p = (int *) omp_realloc (p, 5 * sizeof (int), omp_large_cap_mem_alloc, omp_large_cap_mem_alloc);
79 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 1 || p[1] != 2)
80 abort ();
81 p[0] = 3;
82 p[1] = 4;
83 p[2] = 5;
84 p[3] = 6;
85 p[4] = 7;
86 omp_free (p, omp_null_allocator);
87 omp_set_default_allocator (omp_large_cap_mem_alloc);
88 if (omp_realloc (NULL, 0, omp_null_allocator, omp_null_allocator) != NULL)
89 abort ();
90 p = (int *) omp_alloc (sizeof (int), omp_null_allocator);
91 if ((((uintptr_t) p) % __alignof (int)) != 0)
92 abort ();
93 p[0] = 3;
94 p = (int *) omp_realloc (p, 3 * sizeof (int), omp_null_allocator, omp_null_allocator);
95 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] != 3)
96 abort ();
97 p[0] = 4;
98 p[1] = 5;
99 p[2] = 6;
100 if (omp_realloc (p, 0, omp_null_allocator, omp_get_default_allocator ()) != NULL)
101 abort ();
102 a = omp_init_allocator (omp_default_mem_space, 4, traits);
103 if (a == omp_null_allocator)
104 abort ();
105 p = (int *) omp_alloc (sizeof (int), a);
106 if ((((uintptr_t) p) % 64) != 0)
107 abort ();
108 p[0] = 7;
109 p = (int *) omp_realloc (p, 3072, a, a);
110 if ((((uintptr_t) p) % 64) != 0 || p[0] != 7)
111 abort ();
112 p[0] = 1;
113 p[3071 / sizeof (int)] = 2;
114 q = (int *) omp_alloc (sizeof (int), a);
115 if ((((uintptr_t) q) % 64) != 0)
116 abort ();
117 q[0] = 8;
118 if (omp_realloc (q, 3072, a, a) != NULL)
119 abort ();
120 omp_free (p, a);
121 omp_free (q, a);
122 p = (int *) omp_alloc (sizeof (int), a);
123 p[0] = 42;
124 p = (int *) omp_realloc (p, 3072, a, a);
125 if (p[0] != 42)
126 abort ();
127 p[0] = 3;
128 p[3071 / sizeof (int)] = 4;
129 omp_realloc (p, 0, omp_null_allocator, omp_null_allocator);
130 omp_set_default_allocator (a);
131 if (omp_get_default_allocator () != a)
132 abort ();
133 p = (int *) omp_alloc (31, omp_null_allocator);
134 if (p == NULL)
135 abort ();
136 p = (int *) omp_realloc (p, 3072, omp_null_allocator, omp_null_allocator);
137 if (p == NULL)
138 abort ();
139 q = (int *) omp_alloc (sizeof (int), omp_null_allocator);
140 if (q == NULL)
141 abort ();
142 if (omp_realloc (q, 3072, omp_null_allocator, omp_null_allocator) != NULL)
143 abort ();
144 omp_free (p, a);
145 omp_free (q, a);
146 omp_destroy_allocator (a);
148 a = omp_init_allocator (omp_large_cap_mem_space, 2, traits5);
149 if (a == omp_null_allocator)
150 abort ();
151 omp_set_default_allocator (a);
152 if (omp_get_default_allocator () != a)
153 abort ();
154 p = (int *) omp_alloc (3071, omp_null_allocator);
155 if (p == NULL)
156 abort ();
157 p = (int *) omp_realloc (p, 3072, omp_null_allocator, omp_null_allocator);
158 if (p == NULL)
159 abort ();
160 q = (int *) omp_alloc (sizeof (int), omp_null_allocator);
161 if (q == NULL)
162 abort ();
163 if (omp_realloc (q, 3072, omp_null_allocator, omp_null_allocator) != NULL)
164 abort ();
165 omp_free (p, a);
166 omp_free (q, a);
167 omp_destroy_allocator (a);
169 a = omp_init_allocator (omp_default_mem_space,
170 sizeof (traits2) / sizeof (traits2[0]),
171 traits2);
172 if (a == omp_null_allocator)
173 abort ();
174 if (traits3[5].key != omp_atk_fb_data)
175 abort ();
176 traits3[5].value = (uintptr_t) a;
177 a2 = omp_init_allocator (omp_default_mem_space,
178 sizeof (traits3) / sizeof (traits3[0]),
179 traits3);
180 if (a2 == omp_null_allocator)
181 abort ();
182 p = (int *) omp_alloc (sizeof (int), a2);
183 if ((((uintptr_t) p) % 32) != 0)
184 abort ();
185 p[0] = 84;
186 p = (int *) omp_realloc (p, 380, a2, a2);
187 if ((((uintptr_t) p) % 32) != 0 || p[0] != 84)
188 abort ();
189 p[0] = 5;
190 p[379 / sizeof (int)] = 6;
191 q = (int *) omp_alloc (sizeof (int), a2);
192 if ((((uintptr_t) q) % 32) != 0)
193 abort ();
194 q[0] = 42;
195 q = (int *) omp_realloc (q, 768, a2, a2);
196 if ((((uintptr_t) q) % 16) != 0 || q[0] != 42)
197 abort ();
198 q[0] = 7;
199 q[767 / sizeof (int)] = 8;
200 r = (int *) omp_realloc (NULL, 512, a2, omp_null_allocator);
201 if ((((uintptr_t) r) % __alignof (int)) != 0)
202 abort ();
203 r[0] = 9;
204 r[511 / sizeof (int)] = 10;
205 omp_free (p, omp_null_allocator);
206 omp_free (q, a2);
207 omp_free (r, omp_null_allocator);
208 p = (int *) omp_alloc (sizeof (int), a2);
209 if ((((uintptr_t) p) % 32) != 0)
210 abort ();
211 p[0] = 85;
212 p = (int *) omp_realloc (p, 320, a, a2);
213 if ((((uintptr_t) p) % 16) != 0 || p[0] != 85)
214 abort ();
215 p[0] = 5;
216 p[319 / sizeof (int)] = 6;
217 q = (int *) omp_alloc (sizeof (int), a);
218 if ((((uintptr_t) q) % 16) != 0)
219 abort ();
220 q[0] = 43;
221 q = (int *) omp_realloc (q, 320, a2, a);
222 if ((((uintptr_t) q) % 32) != 0 || q[0] != 43)
223 abort ();
224 q[0] = 44;
225 q[319 / sizeof (int)] = 8;
226 q = (int *) omp_realloc (q, 568, a2, a2);
227 if ((((uintptr_t) q) % 16) != 0 || q[0] != 44)
228 abort ();
229 q[0] = 7;
230 q[567 / sizeof (int)] = 8;
231 omp_free (p, omp_null_allocator);
232 omp_free (q, a2);
233 omp_destroy_allocator (a2);
234 omp_destroy_allocator (a);
236 a = omp_init_allocator (omp_large_cap_mem_space,
237 sizeof (traits4) / sizeof (traits4[0]),
238 traits4);
239 if (a == omp_null_allocator)
240 abort ();
241 if (traits3[5].key != omp_atk_fb_data)
242 abort ();
243 traits3[5].value = (uintptr_t) a;
244 a2 = omp_init_allocator (omp_default_mem_space,
245 sizeof (traits3) / sizeof (traits3[0]),
246 traits3);
247 if (a2 == omp_null_allocator)
248 abort ();
249 omp_set_default_allocator (a2);
250 #ifdef __cplusplus
251 p = static_cast <int *> (omp_realloc (NULL, 420));
252 #else
253 p = (int *) omp_realloc (NULL, 420, omp_null_allocator, omp_null_allocator);
254 #endif
255 if ((((uintptr_t) p) % 32) != 0)
256 abort ();
257 p[0] = 5;
258 p[419 / sizeof (int)] = 6;
259 q = (int *) omp_realloc (NULL, sizeof (int), omp_null_allocator, omp_null_allocator);
260 if ((((uintptr_t) q) % 32) != 0)
261 abort ();
262 q[0] = 99;
263 q = (int *) omp_realloc (q, 700, omp_null_allocator, omp_null_allocator);
264 if ((((uintptr_t) q) % 128) != 0 || q[0] != 99)
265 abort ();
266 q[0] = 7;
267 q[699 / sizeof (int)] = 8;
268 if (omp_realloc (NULL, 768, omp_null_allocator, omp_null_allocator) != NULL)
269 abort ();
270 #ifdef __cplusplus
271 omp_free (p);
272 if (omp_realloc (q, 0) != NULL)
273 abort ();
274 omp_free (NULL);
275 #else
276 omp_free (p, omp_null_allocator);
277 if (omp_realloc (q, 0, omp_null_allocator, omp_null_allocator) != NULL)
278 abort ();
279 omp_free (NULL, omp_null_allocator);
280 #endif
281 omp_free (NULL, omp_null_allocator);
282 omp_destroy_allocator (a2);
283 omp_destroy_allocator (a);
284 return 0;