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