LLVM OpenMP 19.0.0git
omp_alloc_null_fb.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run
2
3#include <stdio.h>
4#include <omp.h>
5
6int main() {
9 void *p[2];
10 at[0].key = omp_atk_pool_size;
11 at[0].value = 2 * 1024 * 1024;
12 at[1].key = omp_atk_fallback;
13 at[1].value = omp_atv_null_fb;
14 a = omp_init_allocator(omp_default_mem_space, 2, at);
15 printf("allocator created: %p\n", (void *)a);
16#pragma omp parallel num_threads(2)
17 {
18 int i = omp_get_thread_num();
19 #pragma omp barrier
20 p[i] = omp_alloc(1024 * 1024, a);
21 #pragma omp barrier
22 printf("th %d, ptr %p\n", i, p[i]);
23 omp_free(p[i], a);
24 }
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}
void const char const char int ITT_FORMAT __itt_group_sync p
omp_memspace_handle_t const omp_default_mem_space
Definition: kmp_global.cpp:331
void * omp_allocator_handle_t
Definition: kmp.h:1088
@ omp_atk_fallback
Definition: kmp.h:1044
@ omp_atk_pool_size
Definition: kmp.h:1043
@ omp_atv_null_fb
Definition: kmp.h:1063
void omp_free(void *ptr, omp_allocator_handle_t allocator)
void * omp_alloc(size_t size, omp_allocator_handle_t allocator)
#define i
Definition: kmp_stub.cpp:87
int a
int main()
omp_alloctrait_key_t key
Definition: kmp.h:1084
omp_uintptr_t value
Definition: kmp.h:1085