Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OpenMP] Add omp_calloc implementation
This patch adds omp_calloc implementation according to OpenMP 5.1 specification. Differential Revision: https://reviews.llvm.org/D90967
- Loading branch information
Showing
8 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// RUN: %libomp-compile-and-run | ||
|
||
#include <stdio.h> | ||
#include <omp.h> | ||
|
||
int main() { | ||
omp_alloctrait_t at[2]; | ||
omp_allocator_handle_t a; | ||
void *p[2]; | ||
at[0].key = omp_atk_pool_size; | ||
at[0].value = 2 * 1024 * 1024; | ||
at[1].key = omp_atk_fallback; | ||
at[1].value = omp_atv_default_mem_fb; | ||
a = omp_init_allocator(omp_large_cap_mem_space, 2, at); | ||
printf("allocator large created: %p\n", a); | ||
#pragma omp parallel num_threads(2) | ||
{ | ||
int i = omp_get_thread_num(); | ||
p[i] = omp_calloc(1024, 1024, a); | ||
#pragma omp barrier | ||
printf("th %d, ptr %p\n", i, p[i]); | ||
omp_free(p[i], a); | ||
} | ||
// Both pointers should be non-NULL | ||
if (p[0] != NULL && p[1] != NULL) { | ||
printf("passed\n"); | ||
return 0; | ||
} else { | ||
printf("failed: pointers %p %p\n", p[0], p[1]); | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// RUN: %libomp-compile-and-run | ||
|
||
#include <stdio.h> | ||
#include <omp.h> | ||
|
||
int main() | ||
{ | ||
omp_alloctrait_t at[2]; | ||
omp_allocator_handle_t a; | ||
void *p[2]; | ||
at[0].key = omp_atk_pool_size; | ||
at[0].value = 2*1024*1024; | ||
at[1].key = omp_atk_fallback; | ||
at[1].value = omp_atv_default_mem_fb; | ||
a = omp_init_allocator(omp_large_cap_mem_space, 2, at); | ||
printf("allocator large created: %p\n", a); | ||
#pragma omp parallel num_threads(2) | ||
{ | ||
int i = omp_get_thread_num(); | ||
p[i] = omp_calloc(1024, 0, a); | ||
#pragma omp barrier | ||
printf("th %d, ptr %p\n", i, p[i]); | ||
omp_free(p[i], a); | ||
} | ||
// Both pointers should be NULL | ||
if (p[0] == NULL && p[1] == NULL) { | ||
printf("passed\n"); | ||
return 0; | ||
} else { | ||
printf("failed: pointers %p %p\n", p[0], p[1]); | ||
return 1; | ||
} | ||
} |