blob: d28a9b51f3871bfe77d614157bf61118296058bb [file] [log] [blame]
Jonathan Peytonebf18302019-04-08 17:59:28 +00001// RUN: %libomp-compile-and-run
2
3#include <stdio.h>
4#include <omp.h>
5
6int main() {
7 omp_alloctrait_t at[2];
8 omp_allocator_handle_t a;
9 void *p[2];
Kelvin Liad24cf22020-01-23 09:16:06 -050010 at[0].key = omp_atk_pool_size;
Jonathan Peytonebf18302019-04-08 17:59:28 +000011 at[0].value = 2 * 1024 * 1024;
Kelvin Liad24cf22020-01-23 09:16:06 -050012 at[1].key = omp_atk_fallback;
13 at[1].value = omp_atv_null_fb;
Jonathan Peytonebf18302019-04-08 17:59:28 +000014 a = omp_init_allocator(omp_high_bw_mem_space, 2, at);
15 printf("allocator hbw created: %p\n", a);
16 #pragma omp parallel num_threads(2)
17 {
18 int i = omp_get_thread_num();
19 p[i] = omp_alloc(1024 * 1024, a);
20 #pragma omp barrier
21 printf("th %d, ptr %p\n", i, p[i]);
22 omp_free(p[i], a);
23 }
24 if (a != omp_null_allocator) {
25 // As an allocator has some small memory overhead
26 // exactly one of the two pointers should be NULL
27 // because of NULL fallback requested
28 if ((p[0] == NULL && p[1] != NULL) || (p[0] != NULL && p[1] == NULL)) {
29 printf("passed\n");
30 return 0;
31 } else {
32 printf("failed: pointers %p %p\n", p[0], p[1]);
33 return 1;
34 }
35 } else {
36 // NULL allocator should cause default allocations
37 if (p[0] != NULL && p[1] != NULL) {
38 printf("passed\n");
39 return 0;
40 } else {
41 printf("failed: pointers %p %p\n", p[0], p[1]);
42 return 1;
43 }
44 }
45}