aboutsummaryrefslogtreecommitdiff
path: root/final/runtime/test/lock
diff options
context:
space:
mode:
Diffstat (limited to 'final/runtime/test/lock')
-rw-r--r--final/runtime/test/lock/omp_init_lock.c42
-rw-r--r--final/runtime/test/lock/omp_lock.c47
-rw-r--r--final/runtime/test/lock/omp_nest_lock.c45
-rw-r--r--final/runtime/test/lock/omp_test_lock.c47
-rw-r--r--final/runtime/test/lock/omp_test_nest_lock.c47
5 files changed, 228 insertions, 0 deletions
diff --git a/final/runtime/test/lock/omp_init_lock.c b/final/runtime/test/lock/omp_init_lock.c
new file mode 100644
index 0000000..24b60d1
--- /dev/null
+++ b/final/runtime/test/lock/omp_init_lock.c
@@ -0,0 +1,42 @@
+// RUN: %libomp-compile-and-run
+#include "omp_testsuite.h"
+#include <stdio.h>
+
+// This should be slightly less than KMP_I_LOCK_CHUNK, which is 1024
+#define LOCKS_PER_ITER 1000
+#define ITERATIONS (REPETITIONS + 1)
+
+// This tests concurrently using locks on one thread while initializing new
+// ones on another thread. This exercises the global lock pool.
+int test_omp_init_lock() {
+ int i;
+ omp_lock_t lcks[ITERATIONS * LOCKS_PER_ITER];
+#pragma omp parallel for schedule(static) num_threads(NUM_TASKS)
+ for (i = 0; i < ITERATIONS; i++) {
+ int j;
+ omp_lock_t *my_lcks = &lcks[i * LOCKS_PER_ITER];
+ for (j = 0; j < LOCKS_PER_ITER; j++) {
+ omp_init_lock(&my_lcks[j]);
+ }
+ for (j = 0; j < LOCKS_PER_ITER * 100; j++) {
+ omp_set_lock(&my_lcks[j % LOCKS_PER_ITER]);
+ omp_unset_lock(&my_lcks[j % LOCKS_PER_ITER]);
+ }
+ }
+ // Wait until all repititions are done. The test is exercising growth of
+ // the global lock pool, which does not shrink when no locks are allocated.
+ {
+ int j;
+ for (j = 0; j < ITERATIONS * LOCKS_PER_ITER; j++) {
+ omp_destroy_lock(&lcks[j]);
+ }
+ }
+
+ return 0;
+}
+
+int main() {
+ // No use repeating this test, since it's exercising a private global pool
+ // which is not reset between test iterations.
+ return test_omp_init_lock();
+}
diff --git a/final/runtime/test/lock/omp_lock.c b/final/runtime/test/lock/omp_lock.c
new file mode 100644
index 0000000..1301f27
--- /dev/null
+++ b/final/runtime/test/lock/omp_lock.c
@@ -0,0 +1,47 @@
+// RUN: %libomp-compile-and-run
+// RUN: env KMP_LOCK_KIND=tas KMP_SPIN_BACKOFF_PARAMS=2048,200 %libomp-run
+// RUN: env KMP_LOCK_KIND=futex %libomp-run
+#include <stdio.h>
+#include "omp_testsuite.h"
+
+omp_lock_t lck;
+
+int test_omp_lock()
+{
+ int nr_threads_in_single = 0;
+ int result = 0;
+ int nr_iterations = 0;
+ int i;
+
+ omp_init_lock(&lck);
+ #pragma omp parallel shared(lck)
+ {
+ #pragma omp for
+ for(i = 0; i < LOOPCOUNT; i++) {
+ omp_set_lock(&lck);
+ #pragma omp flush
+ nr_threads_in_single++;
+ #pragma omp flush
+ nr_iterations++;
+ nr_threads_in_single--;
+ result = result + nr_threads_in_single;
+ omp_unset_lock(&lck);
+ }
+ }
+ omp_destroy_lock(&lck);
+
+ return ((result == 0) && (nr_iterations == LOOPCOUNT));
+}
+
+int main()
+{
+ int i;
+ int num_failed=0;
+
+ for(i = 0; i < REPETITIONS; i++) {
+ if(!test_omp_lock()) {
+ num_failed++;
+ }
+ }
+ return num_failed;
+}
diff --git a/final/runtime/test/lock/omp_nest_lock.c b/final/runtime/test/lock/omp_nest_lock.c
new file mode 100644
index 0000000..33d7c6a
--- /dev/null
+++ b/final/runtime/test/lock/omp_nest_lock.c
@@ -0,0 +1,45 @@
+// RUN: %libomp-compile-and-run
+#include <stdio.h>
+#include "omp_testsuite.h"
+
+omp_nest_lock_t lck;
+
+int test_omp_nest_lock()
+{
+ int nr_threads_in_single = 0;
+ int result = 0;
+ int nr_iterations = 0;
+ int i;
+
+ omp_init_nest_lock(&lck);
+ #pragma omp parallel shared(lck)
+ {
+ #pragma omp for
+ for(i = 0; i < LOOPCOUNT; i++) {
+ omp_set_nest_lock(&lck);
+ #pragma omp flush
+ nr_threads_in_single++;
+ #pragma omp flush
+ nr_iterations++;
+ nr_threads_in_single--;
+ result = result + nr_threads_in_single;
+ omp_unset_nest_lock(&lck);
+ }
+ }
+ omp_destroy_nest_lock(&lck);
+
+ return ((result == 0) && (nr_iterations == LOOPCOUNT));
+}
+
+int main()
+{
+ int i;
+ int num_failed=0;
+
+ for(i = 0; i < REPETITIONS; i++) {
+ if(!test_omp_nest_lock()) {
+ num_failed++;
+ }
+ }
+ return num_failed;
+}
diff --git a/final/runtime/test/lock/omp_test_lock.c b/final/runtime/test/lock/omp_test_lock.c
new file mode 100644
index 0000000..c512055
--- /dev/null
+++ b/final/runtime/test/lock/omp_test_lock.c
@@ -0,0 +1,47 @@
+// RUN: %libomp-compile-and-run
+// RUN: env KMP_LOCK_KIND=tas %libomp-run
+// RUN: env KMP_LOCK_KIND=futex %libomp-run
+#include <stdio.h>
+#include "omp_testsuite.h"
+
+omp_lock_t lck;
+
+int test_omp_test_lock()
+{
+ int nr_threads_in_single = 0;
+ int result = 0;
+ int nr_iterations = 0;
+ int i;
+
+ omp_init_lock (&lck);
+ #pragma omp parallel shared(lck)
+ {
+ #pragma omp for
+ for (i = 0; i < LOOPCOUNT; i++) {
+ while (!omp_test_lock (&lck))
+ {};
+ #pragma omp flush
+ nr_threads_in_single++;
+ #pragma omp flush
+ nr_iterations++;
+ nr_threads_in_single--;
+ result = result + nr_threads_in_single;
+ omp_unset_lock (&lck);
+ }
+ }
+ omp_destroy_lock(&lck);
+ return ((result == 0) && (nr_iterations == LOOPCOUNT));
+}
+
+int main()
+{
+ int i;
+ int num_failed=0;
+
+ for(i = 0; i < REPETITIONS; i++) {
+ if(!test_omp_test_lock()) {
+ num_failed++;
+ }
+ }
+ return num_failed;
+}
diff --git a/final/runtime/test/lock/omp_test_nest_lock.c b/final/runtime/test/lock/omp_test_nest_lock.c
new file mode 100644
index 0000000..2fa6fd2
--- /dev/null
+++ b/final/runtime/test/lock/omp_test_nest_lock.c
@@ -0,0 +1,47 @@
+// RUN: %libomp-compile-and-run
+#include <stdio.h>
+#include "omp_testsuite.h"
+
+static omp_nest_lock_t lck;
+
+int test_omp_test_nest_lock()
+{
+ int nr_threads_in_single = 0;
+ int result = 0;
+ int nr_iterations = 0;
+ int i;
+
+ omp_init_nest_lock (&lck);
+ #pragma omp parallel shared(lck)
+ {
+ #pragma omp for
+ for (i = 0; i < LOOPCOUNT; i++)
+ {
+ /*omp_set_lock(&lck);*/
+ while(!omp_test_nest_lock (&lck))
+ {};
+ #pragma omp flush
+ nr_threads_in_single++;
+ #pragma omp flush
+ nr_iterations++;
+ nr_threads_in_single--;
+ result = result + nr_threads_in_single;
+ omp_unset_nest_lock (&lck);
+ }
+ }
+ omp_destroy_nest_lock (&lck);
+ return ((result == 0) && (nr_iterations == LOOPCOUNT));
+}
+
+int main()
+{
+ int i;
+ int num_failed=0;
+
+ for(i = 0; i < REPETITIONS; i++) {
+ if(!test_omp_test_nest_lock()) {
+ num_failed++;
+ }
+ }
+ return num_failed;
+}