summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/test
diff options
context:
space:
mode:
Diffstat (limited to 'openmp/runtime/test')
-rw-r--r--openmp/runtime/test/api/omp_alloc.c81
-rw-r--r--openmp/runtime/test/api/omp_alloc_def_fb.c32
-rw-r--r--openmp/runtime/test/api/omp_alloc_hbw.c45
-rw-r--r--openmp/runtime/test/api/omp_alloc_null_fb.c35
4 files changed, 112 insertions, 81 deletions
diff --git a/openmp/runtime/test/api/omp_alloc.c b/openmp/runtime/test/api/omp_alloc.c
deleted file mode 100644
index 2002adbec57..00000000000
--- a/openmp/runtime/test/api/omp_alloc.c
+++ /dev/null
@@ -1,81 +0,0 @@
-// RUN: %libomp-compile-and-run
-
-// REQUIRES: openmp-5.0
-
-#include <stdio.h>
-#include <stdint.h>
-#include <omp.h>
-#include "omp_testsuite.h"
-
-#define ARRAY_SIZE 10000
-
-int test_omp_alloc() {
- int err;
- int i, j;
- int *shared_array;
- const omp_allocator_t *allocator;
- const omp_allocator_t *test_allocator;
- // Currently, only default memory allocator is implemented
- const omp_allocator_t *allocators[] = {
- omp_default_mem_alloc,
- };
-
- err = 0;
- for (i = 0; i < sizeof(allocators) / sizeof(allocators[0]); ++i) {
- allocator = allocators[i];
- printf("Using %p allocator\n", test_allocator);
- omp_set_default_allocator(allocator);
- test_allocator = omp_get_default_allocator();
- if (test_allocator != allocator) {
- printf("error: omp_set|get_default_allocator() not working\n");
- return 0;
- }
- shared_array = (int *)omp_alloc(sizeof(int) * ARRAY_SIZE, test_allocator);
- if (shared_array == NULL) {
- printf("error: shared_array is NULL\n");
- return 0;
- }
- for (j = 0; j < ARRAY_SIZE; ++j) {
- shared_array[j] = j;
- }
- #pragma omp parallel shared(shared_array)
- {
- int i;
- int tid = omp_get_thread_num();
- int *private_array =
- (int *)omp_alloc(sizeof(int) * ARRAY_SIZE, omp_default_mem_alloc);
- if (private_array == NULL) {
- printf("error: thread %d private_array is NULL\n", tid);
- #pragma omp atomic
- err++;
- }
- for (i = 0; i < ARRAY_SIZE; ++i) {
- private_array[i] = shared_array[i] + tid;
- }
- for (i = 0; i < ARRAY_SIZE; ++i) {
- if (private_array[i] != i + tid) {
- printf("error: thread %d element %d is %d instead of %d\n", tid, i,
- private_array[i], i + tid);
- #pragma omp atomic
- err++;
- }
- }
- omp_free(private_array, omp_default_mem_alloc);
- } /* end of parallel */
- omp_free(shared_array, test_allocator);
- }
-
- return !err;
-}
-
-int main() {
- int i;
- int num_failed = 0;
-
- for (i = 0; i < REPETITIONS; i++) {
- if (!test_omp_alloc()) {
- num_failed++;
- }
- }
- return num_failed;
-}
diff --git a/openmp/runtime/test/api/omp_alloc_def_fb.c b/openmp/runtime/test/api/omp_alloc_def_fb.c
new file mode 100644
index 00000000000..3795f0990f6
--- /dev/null
+++ b/openmp/runtime/test/api/omp_alloc_def_fb.c
@@ -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_alloc(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;
+ }
+}
diff --git a/openmp/runtime/test/api/omp_alloc_hbw.c b/openmp/runtime/test/api/omp_alloc_hbw.c
new file mode 100644
index 00000000000..e9445489670
--- /dev/null
+++ b/openmp/runtime/test/api/omp_alloc_hbw.c
@@ -0,0 +1,45 @@
+// 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_NULL_FB;
+ a = omp_init_allocator(omp_high_bw_mem_space, 2, at);
+ printf("allocator hbw created: %p\n", a);
+ #pragma omp parallel num_threads(2)
+ {
+ int i = omp_get_thread_num();
+ p[i] = omp_alloc(1024 * 1024, a);
+ #pragma omp barrier
+ printf("th %d, ptr %p\n", i, p[i]);
+ omp_free(p[i], a);
+ }
+ if (a != omp_null_allocator) {
+ // As an allocator has some small memory overhead
+ // exactly one of the two pointers should be NULL
+ // because of NULL fallback requested
+ if ((p[0] == NULL && p[1] != NULL) || (p[0] != NULL && p[1] == NULL)) {
+ printf("passed\n");
+ return 0;
+ } else {
+ printf("failed: pointers %p %p\n", p[0], p[1]);
+ return 1;
+ }
+ } else {
+ // NULL allocator should cause default allocations
+ 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;
+ }
+ }
+}
diff --git a/openmp/runtime/test/api/omp_alloc_null_fb.c b/openmp/runtime/test/api/omp_alloc_null_fb.c
new file mode 100644
index 00000000000..9528c46047a
--- /dev/null
+++ b/openmp/runtime/test/api/omp_alloc_null_fb.c
@@ -0,0 +1,35 @@
+// 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_NULL_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();
+ #pragma omp barrier
+ p[i] = omp_alloc(1024 * 1024, a);
+ #pragma omp barrier
+ printf("th %d, ptr %p\n", i, p[i]);
+ omp_free(p[i], a);
+ }
+ // As an allocator has some small memory overhead
+ // exactly one of the two pointers should be NULL
+ // because of NULL fallback requested
+ if ((p[0] == NULL && p[1] != NULL) || (p[0] != NULL && p[1] == NULL)) {
+ printf("passed\n");
+ return 0;
+ } else {
+ printf("failed: pointers %p %p\n", p[0], p[1]);
+ return 1;
+ }
+}
OpenPOWER on IntegriCloud