1 | // RUN: %libomp-compile-and-run |
2 | |
3 | #include <stdio.h> |
4 | #include <omp.h> |
5 | |
6 | int main() |
7 | { |
8 | omp_alloctrait_t at[2]; |
9 | omp_allocator_handle_t a; |
10 | omp_allocator_handle_t f_a; |
11 | void *ptr[2]; |
12 | void *nptr[2]; |
13 | at[0].key = omp_atk_pool_size; |
14 | at[0].value = 2*1024*1024; |
15 | at[1].key = omp_atk_fallback; |
16 | at[1].value = omp_atv_default_mem_fb; |
17 | |
18 | a = omp_init_allocator(omp_large_cap_mem_space, 2, at); |
19 | f_a = omp_init_allocator(omp_default_mem_space, 2, at); |
20 | printf("allocator large created: %p\n" , (void *)a); |
21 | printf("allocator default created: %p\n" , (void *)f_a); |
22 | |
23 | #pragma omp parallel num_threads(2) |
24 | { |
25 | int i = omp_get_thread_num(); |
26 | ptr[i] = omp_alloc(0, f_a); |
27 | #pragma omp barrier |
28 | nptr[i] = omp_realloc(ptr[i], 1024 * 1024, a, f_a); |
29 | #pragma omp barrier |
30 | printf(format: "th %d, nptr %p\n" , i, nptr[i]); |
31 | omp_free(nptr[i], a); |
32 | } |
33 | |
34 | // Both ptr pointers should be NULL |
35 | if (ptr[0] != NULL || ptr[1] != NULL) { |
36 | printf(format: "failed: pointers %p %p\n" , ptr[0], ptr[1]); |
37 | return 1; |
38 | } |
39 | // Both nptr pointers should be non-NULL |
40 | if (nptr[0] == NULL || nptr[1] == NULL) { |
41 | printf(format: "failed: pointers %p %p\n" , nptr[0], nptr[1]); |
42 | return 1; |
43 | } |
44 | printf(format: "passed\n" ); |
45 | return 0; |
46 | } |
47 | |