summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c/loop-1.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libgomp/testsuite/libgomp.c/loop-1.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libgomp/testsuite/libgomp.c/loop-1.c')
-rw-r--r--libgomp/testsuite/libgomp.c/loop-1.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.c/loop-1.c b/libgomp/testsuite/libgomp.c/loop-1.c
new file mode 100644
index 000000000..11348dcfe
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/loop-1.c
@@ -0,0 +1,140 @@
+/* Test that all loop iterations are touched. This doesn't verify
+ scheduling order, merely coverage. */
+
+/* { dg-require-effective-target sync_int_long } */
+
+#include <omp.h>
+#include <string.h>
+#include <assert.h>
+#include "libgomp_g.h"
+
+
+#define N 10000
+static int S, E, INCR, CHUNK, NTHR;
+static int data[N];
+
+static void clean_data (void)
+{
+ memset (data, -1, sizeof (data));
+}
+
+static void test_data (void)
+{
+ int i, j;
+
+ for (i = 0; i < S; ++i)
+ assert (data[i] == -1);
+
+ for (j = 0; i < E; ++i, j = (j + 1) % INCR)
+ if (j == 0)
+ assert (data[i] != -1);
+ else
+ assert (data[i] == -1);
+
+ for (; i < N; ++i)
+ assert (data[i] == -1);
+}
+
+static void set_data (long i, int val)
+{
+ int old;
+ assert (i >= 0 && i < N);
+ old = __sync_lock_test_and_set (data+i, val);
+ assert (old == -1);
+}
+
+
+#define TMPL_1(sched) \
+static void f_##sched##_1 (void *dummy) \
+{ \
+ int iam = omp_get_thread_num (); \
+ long s0, e0, i; \
+ if (GOMP_loop_##sched##_start (S, E, INCR, CHUNK, &s0, &e0)) \
+ do \
+ { \
+ for (i = s0; i < e0; i += INCR) \
+ set_data (i, iam); \
+ } \
+ while (GOMP_loop_##sched##_next (&s0, &e0)); \
+ GOMP_loop_end (); \
+} \
+static void t_##sched##_1 (void) \
+{ \
+ clean_data (); \
+ GOMP_parallel_start (f_##sched##_1, NULL, NTHR); \
+ f_##sched##_1 (NULL); \
+ GOMP_parallel_end (); \
+ test_data (); \
+}
+
+TMPL_1(static)
+TMPL_1(dynamic)
+TMPL_1(guided)
+
+#define TMPL_2(sched) \
+static void f_##sched##_2 (void *dummy) \
+{ \
+ int iam = omp_get_thread_num (); \
+ long s0, e0, i; \
+ while (GOMP_loop_##sched##_next (&s0, &e0)) \
+ { \
+ for (i = s0; i < e0; i += INCR) \
+ set_data (i, iam); \
+ } \
+ GOMP_loop_end_nowait (); \
+} \
+static void t_##sched##_2 (void) \
+{ \
+ clean_data (); \
+ GOMP_parallel_loop_##sched##_start \
+ (f_##sched##_2, NULL, NTHR, S, E, INCR, CHUNK); \
+ f_##sched##_2 (NULL); \
+ GOMP_parallel_end (); \
+ test_data (); \
+}
+
+TMPL_2(static)
+TMPL_2(dynamic)
+TMPL_2(guided)
+
+static void test (void)
+{
+ t_static_1 ();
+ t_dynamic_1 ();
+ t_guided_1 ();
+ t_static_2 ();
+ t_dynamic_2 ();
+ t_guided_2 ();
+}
+
+int main()
+{
+ omp_set_dynamic (0);
+
+ NTHR = 4;
+
+ S = 0, E = N, INCR = 1, CHUNK = 4;
+ test ();
+
+ S = 0, E = N, INCR = 2, CHUNK = 4;
+ test ();
+
+ S = 1, E = N-1, INCR = 1, CHUNK = 5;
+ test ();
+
+ S = 1, E = N-1, INCR = 2, CHUNK = 5;
+ test ();
+
+ S = 2, E = 4, INCR = 1, CHUNK = 1;
+ test ();
+
+ S = 0, E = N, INCR = 1, CHUNK = 0;
+ t_static_1 ();
+ t_static_2 ();
+
+ S = 1, E = N-1, INCR = 1, CHUNK = 0;
+ t_static_1 ();
+ t_static_2 ();
+
+ return 0;
+}