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. */
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
} };
41 int *volatile p
= (int *) omp_alloc (3 * sizeof (int), omp_default_mem_alloc
);
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)
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)
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)
71 if (omp_realloc (p
, 0, omp_null_allocator
, omp_high_bw_mem_alloc
) != NULL
)
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)
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)
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
)
90 p
= (int *) omp_alloc (sizeof (int), omp_null_allocator
);
91 if ((((uintptr_t) p
) % __alignof (int)) != 0)
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)
100 if (omp_realloc (p
, 0, omp_null_allocator
, omp_get_default_allocator ()) != NULL
)
102 a
= omp_init_allocator (omp_default_mem_space
, 4, traits
);
103 if (a
== omp_null_allocator
)
105 p
= (int *) omp_alloc (sizeof (int), a
);
106 if ((((uintptr_t) p
) % 64) != 0)
109 p
= (int *) omp_realloc (p
, 3072, a
, a
);
110 if ((((uintptr_t) p
) % 64) != 0 || p
[0] != 7)
113 p
[3071 / sizeof (int)] = 2;
114 q
= (int *) omp_alloc (sizeof (int), a
);
115 if ((((uintptr_t) q
) % 64) != 0)
118 if (omp_realloc (q
, 3072, a
, a
) != NULL
)
122 p
= (int *) omp_alloc (sizeof (int), a
);
124 p
= (int *) omp_realloc (p
, 3072, a
, a
);
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
)
133 p
= (int *) omp_alloc (31, omp_null_allocator
);
136 p
= (int *) omp_realloc (p
, 3072, omp_null_allocator
, omp_null_allocator
);
139 q
= (int *) omp_alloc (sizeof (int), omp_null_allocator
);
142 if (omp_realloc (q
, 3072, omp_null_allocator
, omp_null_allocator
) != NULL
)
146 omp_destroy_allocator (a
);
148 a
= omp_init_allocator (omp_large_cap_mem_space
, 2, traits5
);
149 if (a
== omp_null_allocator
)
151 omp_set_default_allocator (a
);
152 if (omp_get_default_allocator () != a
)
154 p
= (int *) omp_alloc (3071, omp_null_allocator
);
157 p
= (int *) omp_realloc (p
, 3072, omp_null_allocator
, omp_null_allocator
);
160 q
= (int *) omp_alloc (sizeof (int), omp_null_allocator
);
163 if (omp_realloc (q
, 3072, omp_null_allocator
, omp_null_allocator
) != NULL
)
167 omp_destroy_allocator (a
);
169 a
= omp_init_allocator (omp_default_mem_space
,
170 sizeof (traits2
) / sizeof (traits2
[0]),
172 if (a
== omp_null_allocator
)
174 if (traits3
[5].key
!= omp_atk_fb_data
)
176 traits3
[5].value
= (uintptr_t) a
;
177 a2
= omp_init_allocator (omp_default_mem_space
,
178 sizeof (traits3
) / sizeof (traits3
[0]),
180 if (a2
== omp_null_allocator
)
182 p
= (int *) omp_alloc (sizeof (int), a2
);
183 if ((((uintptr_t) p
) % 32) != 0)
186 p
= (int *) omp_realloc (p
, 380, a2
, a2
);
187 if ((((uintptr_t) p
) % 32) != 0 || p
[0] != 84)
190 p
[379 / sizeof (int)] = 6;
191 q
= (int *) omp_alloc (sizeof (int), a2
);
192 if ((((uintptr_t) q
) % 32) != 0)
195 q
= (int *) omp_realloc (q
, 768, a2
, a2
);
196 if ((((uintptr_t) q
) % 16) != 0 || q
[0] != 42)
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)
204 r
[511 / sizeof (int)] = 10;
205 omp_free (p
, omp_null_allocator
);
207 omp_free (r
, omp_null_allocator
);
208 p
= (int *) omp_alloc (sizeof (int), a2
);
209 if ((((uintptr_t) p
) % 32) != 0)
212 p
= (int *) omp_realloc (p
, 320, a
, a2
);
213 if ((((uintptr_t) p
) % 16) != 0 || p
[0] != 85)
216 p
[319 / sizeof (int)] = 6;
217 q
= (int *) omp_alloc (sizeof (int), a
);
218 if ((((uintptr_t) q
) % 16) != 0)
221 q
= (int *) omp_realloc (q
, 320, a2
, a
);
222 if ((((uintptr_t) q
) % 32) != 0 || q
[0] != 43)
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)
230 q
[567 / sizeof (int)] = 8;
231 omp_free (p
, omp_null_allocator
);
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]),
239 if (a
== omp_null_allocator
)
241 if (traits3
[5].key
!= omp_atk_fb_data
)
243 traits3
[5].value
= (uintptr_t) a
;
244 a2
= omp_init_allocator (omp_default_mem_space
,
245 sizeof (traits3
) / sizeof (traits3
[0]),
247 if (a2
== omp_null_allocator
)
249 omp_set_default_allocator (a2
);
251 p
= static_cast <int *> (omp_realloc (NULL
, 420));
253 p
= (int *) omp_realloc (NULL
, 420, omp_null_allocator
, omp_null_allocator
);
255 if ((((uintptr_t) p
) % 32) != 0)
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)
263 q
= (int *) omp_realloc (q
, 700, omp_null_allocator
, omp_null_allocator
);
264 if ((((uintptr_t) q
) % 128) != 0 || q
[0] != 99)
267 q
[699 / sizeof (int)] = 8;
268 if (omp_realloc (NULL
, 768, omp_null_allocator
, omp_null_allocator
) != NULL
)
272 if (omp_realloc (q
, 0) != NULL
)
276 omp_free (p
, omp_null_allocator
);
277 if (omp_realloc (q
, 0, omp_null_allocator
, omp_null_allocator
) != NULL
)
279 omp_free (NULL
, omp_null_allocator
);
281 omp_free (NULL
, omp_null_allocator
);
282 omp_destroy_allocator (a2
);
283 omp_destroy_allocator (a
);