diff options
Diffstat (limited to 'final/runtime/test/api')
-rw-r--r-- | final/runtime/test/api/has_openmp.c | 23 | ||||
-rw-r--r-- | final/runtime/test/api/kmp_aligned_malloc.c | 62 | ||||
-rw-r--r-- | final/runtime/test/api/kmp_set_defaults_lock_bug.c | 53 | ||||
-rw-r--r-- | final/runtime/test/api/omp_get_num_threads.c | 39 | ||||
-rw-r--r-- | final/runtime/test/api/omp_get_wtick.c | 24 | ||||
-rw-r--r-- | final/runtime/test/api/omp_get_wtime.c | 33 | ||||
-rw-r--r-- | final/runtime/test/api/omp_in_parallel.c | 39 |
7 files changed, 273 insertions, 0 deletions
diff --git a/final/runtime/test/api/has_openmp.c b/final/runtime/test/api/has_openmp.c new file mode 100644 index 0000000..da95f59 --- /dev/null +++ b/final/runtime/test/api/has_openmp.c @@ -0,0 +1,23 @@ +// RUN: %libomp-compile-and-run +#include <stdio.h> +#include <stdlib.h> +#include "omp_testsuite.h" + +int test_has_openmp() +{ + int rvalue = 0; +#ifdef _OPENMP + rvalue = 1; +#endif + return (rvalue); +} + +int main() +{ + int i; + int num_failed=0; + if(!test_has_openmp()) { + num_failed++; + } + return num_failed; +} diff --git a/final/runtime/test/api/kmp_aligned_malloc.c b/final/runtime/test/api/kmp_aligned_malloc.c new file mode 100644 index 0000000..5302fec --- /dev/null +++ b/final/runtime/test/api/kmp_aligned_malloc.c @@ -0,0 +1,62 @@ +// RUN: %libomp-compile-and-run +#include <stdio.h> +#include <stdint.h> +#include <omp.h> +#include "omp_testsuite.h" + +int alignments[] = {64, 128, 256, 512, 1024, 2048, 4096}; + +unsigned aligned_by(uint64_t addr) { + uint64_t alignment = 1; + while((addr & (alignment-1)) == 0) { + alignment <<= 1; + } + return (alignment >> 1); +} + +int test_kmp_aligned_malloc() +{ + int err = 0; + #pragma omp parallel shared(err) + { + int i; + int* ptr; + uint64_t addr; + int tid = omp_get_thread_num(); + + for(i = 0; i < sizeof(alignments)/sizeof(int); i++) { + int alignment = alignments[i]; + // allocate 64 bytes with 64-byte alignment + // allocate 128 bytes with 128-byte alignment, etc. + ptr = (int*)kmp_aligned_malloc(alignment, alignment); + addr = (uint64_t)ptr; + if(addr & (alignment-1)) { + printf("thread %d: addr = %p (aligned to %u bytes) but expected " + " alignment = %d\n", tid, ptr, aligned_by(addr), alignment); + err = 1; + } + kmp_free(ptr); + } + + ptr = kmp_aligned_malloc(128, 127); + if (ptr != NULL) { + printf("thread %d: kmp_aligned_malloc() didn't return NULL when " + "alignment was not power of 2\n", tid); + err = 1; + } + } /* end of parallel */ + return !err; +} + +int main() +{ + int i; + int num_failed=0; + + for(i = 0; i < REPETITIONS; i++) { + if(!test_kmp_aligned_malloc()) { + num_failed++; + } + } + return num_failed; +} diff --git a/final/runtime/test/api/kmp_set_defaults_lock_bug.c b/final/runtime/test/api/kmp_set_defaults_lock_bug.c new file mode 100644 index 0000000..73a7afb --- /dev/null +++ b/final/runtime/test/api/kmp_set_defaults_lock_bug.c @@ -0,0 +1,53 @@ +// RUN: %libomp-compile-and-run +#include <stdio.h> +#include "omp_testsuite.h" +/* The bug occurs if the lock table is reallocated after + kmp_set_defaults() is called. If the table is reallocated, + then the lock will not point to a valid lock object after the + kmp_set_defaults() call.*/ +omp_lock_t lock; + +int test_kmp_set_defaults_lock_bug() +{ + /* checks that omp_get_num_threads is equal to the number of + threads */ + int nthreads_lib; + int nthreads = 0; + + nthreads_lib = -1; + + #pragma omp parallel + { + omp_set_lock(&lock); + nthreads++; + omp_unset_lock(&lock); + #pragma omp single + { + nthreads_lib = omp_get_num_threads (); + } /* end of single */ + } /* end of parallel */ + kmp_set_defaults("OMP_NUM_THREADS"); + #pragma omp parallel + { + omp_set_lock(&lock); + nthreads++; + omp_unset_lock(&lock); + } /* end of parallel */ + + return (nthreads == 2*nthreads_lib); +} + +int main() +{ + int i; + int num_failed=0; + omp_init_lock(&lock); + + for(i = 0; i < REPETITIONS; i++) { + if(!test_kmp_set_defaults_lock_bug()) { + num_failed++; + } + } + omp_destroy_lock(&lock); + return num_failed; +} diff --git a/final/runtime/test/api/omp_get_num_threads.c b/final/runtime/test/api/omp_get_num_threads.c new file mode 100644 index 0000000..daf286d --- /dev/null +++ b/final/runtime/test/api/omp_get_num_threads.c @@ -0,0 +1,39 @@ +// RUN: %libomp-compile-and-run +#include <stdio.h> +#include "omp_testsuite.h" + +int test_omp_get_num_threads() +{ + /* checks that omp_get_num_threads is equal to the number of + threads */ + int nthreads_lib; + int nthreads = 0; + + nthreads_lib = -1; + + #pragma omp parallel + { + #pragma omp critical + { + nthreads++; + } /* end of critical */ + #pragma omp single + { + nthreads_lib = omp_get_num_threads (); + } /* end of single */ + } /* end of parallel */ + return (nthreads == nthreads_lib); +} + +int main() +{ + int i; + int num_failed=0; + + for(i = 0; i < REPETITIONS; i++) { + if(!test_omp_get_num_threads()) { + num_failed++; + } + } + return num_failed; +} diff --git a/final/runtime/test/api/omp_get_wtick.c b/final/runtime/test/api/omp_get_wtick.c new file mode 100644 index 0000000..8b35226 --- /dev/null +++ b/final/runtime/test/api/omp_get_wtick.c @@ -0,0 +1,24 @@ +// RUN: %libomp-compile-and-run +#include <stdio.h> +#include "omp_testsuite.h" + +int test_omp_get_wtick() +{ + double tick; + tick = -1.; + tick = omp_get_wtick (); + return ((tick > 0.0) && (tick < 0.01)); +} + +int main() +{ + int i; + int num_failed=0; + + for(i = 0; i < REPETITIONS; i++) { + if(!test_omp_get_wtick()) { + num_failed++; + } + } + return num_failed; +} diff --git a/final/runtime/test/api/omp_get_wtime.c b/final/runtime/test/api/omp_get_wtime.c new file mode 100644 index 0000000..b309440 --- /dev/null +++ b/final/runtime/test/api/omp_get_wtime.c @@ -0,0 +1,33 @@ +// RUN: %libomp-compile-and-run +#include <stdio.h> +#include <stdlib.h> +#include "omp_testsuite.h" +#include "omp_my_sleep.h" + +int test_omp_get_wtime() +{ + double start; + double end; + double measured_time; + double wait_time = 5.0; + start = 0; + end = 0; + start = omp_get_wtime(); + my_sleep (wait_time); + end = omp_get_wtime(); + measured_time = end-start; + return ((measured_time > 0.97 * wait_time) && (measured_time < 1.03 * wait_time)) ; +} + +int main() +{ + int i; + int num_failed=0; + + for(i = 0; i < REPETITIONS; i++) { + if(!test_omp_get_wtime()) { + num_failed++; + } + } + return num_failed; +} diff --git a/final/runtime/test/api/omp_in_parallel.c b/final/runtime/test/api/omp_in_parallel.c new file mode 100644 index 0000000..d09313e --- /dev/null +++ b/final/runtime/test/api/omp_in_parallel.c @@ -0,0 +1,39 @@ +// RUN: %libomp-compile-and-run +#include <stdio.h> +#include "omp_testsuite.h" + +/* + * Checks that false is returned when called from serial region + * and true is returned when called within parallel region. + */ +int test_omp_in_parallel() +{ + int serial; + int isparallel; + + serial = 1; + isparallel = 0; + serial = omp_in_parallel(); + + #pragma omp parallel + { + #pragma omp single + { + isparallel = omp_in_parallel(); + } + } + return (!(serial) && isparallel); +} + +int main() +{ + int i; + int num_failed=0; + + for(i = 0; i < REPETITIONS; i++) { + if(!test_omp_in_parallel()) { + num_failed++; + } + } + return num_failed; +} |