summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/test/api
diff options
context:
space:
mode:
Diffstat (limited to 'openmp/runtime/test/api')
-rw-r--r--openmp/runtime/test/api/has_openmp.c23
-rw-r--r--openmp/runtime/test/api/omp_get_num_threads.c39
-rw-r--r--openmp/runtime/test/api/omp_get_wtick.c24
-rw-r--r--openmp/runtime/test/api/omp_get_wtime.c33
-rw-r--r--openmp/runtime/test/api/omp_in_parallel.c39
5 files changed, 158 insertions, 0 deletions
diff --git a/openmp/runtime/test/api/has_openmp.c b/openmp/runtime/test/api/has_openmp.c
new file mode 100644
index 00000000000..da95f595fb9
--- /dev/null
+++ b/openmp/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/openmp/runtime/test/api/omp_get_num_threads.c b/openmp/runtime/test/api/omp_get_num_threads.c
new file mode 100644
index 00000000000..38a1434a031
--- /dev/null
+++ b/openmp/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/openmp/runtime/test/api/omp_get_wtick.c b/openmp/runtime/test/api/omp_get_wtick.c
new file mode 100644
index 00000000000..8b35226a01f
--- /dev/null
+++ b/openmp/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/openmp/runtime/test/api/omp_get_wtime.c b/openmp/runtime/test/api/omp_get_wtime.c
new file mode 100644
index 00000000000..f7be1faef5a
--- /dev/null
+++ b/openmp/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 = 0.25;
+ start = 0;
+ end = 0;
+ start = omp_get_wtime();
+ my_sleep (wait_time);
+ end = omp_get_wtime();
+ measured_time = end-start;
+ return ((measured_time > 0.99 * wait_time) && (measured_time < 1.01 * 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/openmp/runtime/test/api/omp_in_parallel.c b/openmp/runtime/test/api/omp_in_parallel.c
new file mode 100644
index 00000000000..40cc3859c50
--- /dev/null
+++ b/openmp/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;
+}
OpenPOWER on IntegriCloud