aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgomp/testsuite/libgomp.c')
-rw-r--r--libgomp/testsuite/libgomp.c/cancel-for-2.c6
-rw-r--r--libgomp/testsuite/libgomp.c/task-reduction-1.c137
-rw-r--r--libgomp/testsuite/libgomp.c/task-reduction-2.c86
-rw-r--r--libgomp/testsuite/libgomp.c/teams-1.c27
-rw-r--r--libgomp/testsuite/libgomp.c/teams-2.c123
-rw-r--r--libgomp/testsuite/libgomp.c/thread-limit-4.c57
-rw-r--r--libgomp/testsuite/libgomp.c/thread-limit-5.c11
7 files changed, 444 insertions, 3 deletions
diff --git a/libgomp/testsuite/libgomp.c/cancel-for-2.c b/libgomp/testsuite/libgomp.c/cancel-for-2.c
index 30cfbb1..d1d6f86 100644
--- a/libgomp/testsuite/libgomp.c/cancel-for-2.c
+++ b/libgomp/testsuite/libgomp.c/cancel-for-2.c
@@ -20,7 +20,7 @@ foo (int *x)
#pragma omp for
for (i = 0; i < 1000; ++i)
{
- #pragma omp cancel for if (x[1])
+ #pragma omp cancel for if (cancel: x[1])
#pragma omp atomic
v++;
}
@@ -34,7 +34,7 @@ foo (int *x)
#pragma omp for
for (i = 0; i < 1000; ++i)
{
- #pragma omp cancel for if (x[3])
+ #pragma omp cancel for if ( cancel : x[3])
#pragma omp atomic
v += 2;
}
@@ -54,7 +54,7 @@ foo (int *x)
#pragma omp cancel for if (x[0])
abort ();
}
- #pragma omp cancel parallel if (omp_get_thread_num () == 2 && x[4])
+ #pragma omp cancel parallel if (cancel:omp_get_thread_num () == 2 && x[4])
#pragma omp for
for (i = 0; i < 1000; ++i)
{
diff --git a/libgomp/testsuite/libgomp.c/task-reduction-1.c b/libgomp/testsuite/libgomp.c/task-reduction-1.c
new file mode 100644
index 0000000..224d995
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/task-reduction-1.c
@@ -0,0 +1,137 @@
+typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+
+void
+bar (int *a, int *b, int *c, int (*d)[2], int (*e)[4], size_t n, int f[1][n], int g[1][n * 2])
+{
+ #pragma omp task in_reduction (*: a[:n], b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ a[0] *= 12;
+ a[1] *= 13;
+ b[3] *= 14;
+ b[4] *= 15;
+ c[n] *= 16;
+ c[n + 1] *= 17;
+ d[0][0] *= 18;
+ d[0][1] *= 19;
+ e[0][1] *= 20;
+ e[0][2] *= 21;
+ f[0][0] *= 22;
+ f[0][1] *= 23;
+ g[0][1] *= 24;
+ g[0][2] *= 25;
+ }
+}
+
+void
+foo (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2])
+{
+ int a[n], b[n + 3], c[2 * n];
+ int (*d)[n] = (int (*)[n]) x;
+ int (*e)[n * 2] = (int (*)[n * 2]) y;
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ a[i] = 1;
+ b[i + 3] = 1;
+ c[i + n] = 1;
+ d[0][i] = 1;
+ e[0][i + 1] = 1;
+ f[0][i] = 1;
+ g[0][i + 1] = 1;
+ }
+ #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g);
+ #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ a[0] *= 2;
+ a[1] *= 3;
+ b[3] *= 4;
+ b[4] *= 5;
+ c[n] *= 6;
+ c[n + 1] *= 7;
+ d[0][0] *= 8;
+ d[0][1] *= 9;
+ e[0][1] *= 10;
+ e[0][2] *= 11;
+ f[0][0] *= 12;
+ f[0][1] *= 13;
+ g[0][1] *= 14;
+ g[0][2] *= 15;
+ }
+ n = 0;
+ }
+ if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+ abort ();
+ if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+ abort ();
+ if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299)
+ abort ();
+ if (g[0][1] != 336 || g[0][2] != 375)
+ abort ();
+}
+
+void
+baz (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2])
+{
+ int a[n], b[n + 3], c[2 * n];
+ int (*d)[n] = (int (*)[n]) x;
+ int (*e)[n * 2] = (int (*)[n * 2]) y;
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ a[i] = 1;
+ b[i + 3] = 1;
+ c[i + n] = 1;
+ d[0][i] = 1;
+ e[0][i + 1] = 1;
+ f[0][i] = 1;
+ g[0][i + 1] = 1;
+ }
+ #pragma omp parallel num_threads(2)
+ #pragma omp master
+ #pragma omp taskgroup task_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g);
+ #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ a[0] *= 2;
+ a[1] *= 3;
+ b[3] *= 4;
+ b[4] *= 5;
+ c[n] *= 6;
+ c[n + 1] *= 7;
+ d[0][0] *= 8;
+ d[0][1] *= 9;
+ e[0][1] *= 10;
+ e[0][2] *= 11;
+ f[0][0] *= 12;
+ f[0][1] *= 13;
+ g[0][1] *= 14;
+ g[0][2] *= 15;
+ }
+ n = 0;
+ }
+ if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+ abort ();
+ if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+ abort ();
+ if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299)
+ abort ();
+ if (g[0][1] != 336 || g[0][2] != 375)
+ abort ();
+}
+
+int
+main ()
+{
+ int d[1][2], e[1][4], f[1][2], g[1][4];
+ volatile int two;
+ two = 2;
+ #pragma omp parallel num_threads (2)
+ #pragma omp master
+ foo (two, (void *) d, (void *) e, f, g);
+ baz (two, (void *) d, (void *) e, f, g);
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/task-reduction-2.c b/libgomp/testsuite/libgomp.c/task-reduction-2.c
new file mode 100644
index 0000000..f5d48c3
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/task-reduction-2.c
@@ -0,0 +1,86 @@
+typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+
+void
+bar (int *a, int *b, int *c, int (*d)[2], int (*e)[4], size_t n, int f[1][n], int g[1][n * 2])
+{
+ #pragma omp task in_reduction (*: a[:n], b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ a[0] *= 12;
+ a[1] *= 13;
+ b[3] *= 14;
+ b[4] *= 15;
+ c[n] *= 16;
+ c[n + 1] *= 17;
+ d[0][0] *= 18;
+ d[0][1] *= 19;
+ e[0][1] *= 20;
+ e[0][2] *= 21;
+ f[0][0] *= 22;
+ f[0][1] *= 23;
+ g[0][1] *= 24;
+ g[0][2] *= 25;
+ }
+}
+
+void
+baz (size_t n, void *x, void *y, int f[1][n], int g[1][n * 2])
+{
+ int a[n], b[n + 3], c[2 * n];
+ int (*d)[n] = (int (*)[n]) x;
+ int (*e)[n * 2] = (int (*)[n * 2]) y;
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ a[i] = 1;
+ b[i + 3] = 1;
+ c[i + n] = 1;
+ d[0][i] = 1;
+ e[0][i + 1] = 1;
+ f[0][i] = 1;
+ g[0][i + 1] = 1;
+ }
+ #pragma omp parallel num_threads(2) firstprivate (n) \
+ reduction (task, *: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ #pragma omp master
+ bar (a, b, c, (int (*)[2]) d, (int (*)[4]) e, n, f, g);
+ #pragma omp master
+ #pragma omp task in_reduction (*: a, b[3:n], c[n:n], d[0][:n], e[0][1:n], f[0][:], g[0][1:n])
+ {
+ a[0] *= 2;
+ a[1] *= 3;
+ b[3] *= 4;
+ b[4] *= 5;
+ c[n] *= 6;
+ c[n + 1] *= 7;
+ d[0][0] *= 8;
+ d[0][1] *= 9;
+ e[0][1] *= 10;
+ e[0][2] *= 11;
+ f[0][0] *= 12;
+ f[0][1] *= 13;
+ g[0][1] *= 14;
+ g[0][2] *= 15;
+ }
+ n = 0;
+ }
+ if (a[0] != 24 || a[1] != 39 || b[3] != 56 || b[4] != 75)
+ abort ();
+ if (c[2] != 96 || c[3] != 119 || d[0][0] != 144 || d[0][1] != 171)
+ abort ();
+ if (e[0][1] != 200 || e[0][2] != 231 || f[0][0] != 264 || f[0][1] != 299)
+ abort ();
+ if (g[0][1] != 336 || g[0][2] != 375)
+ abort ();
+}
+
+int
+main ()
+{
+ int d[1][2], e[1][4], f[1][2], g[1][4];
+ volatile int two;
+ two = 2;
+ baz (two, (void *) d, (void *) e, f, g);
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/teams-1.c b/libgomp/testsuite/libgomp.c/teams-1.c
new file mode 100644
index 0000000..c5df837
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/teams-1.c
@@ -0,0 +1,27 @@
+#include <omp.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+ #pragma omp teams thread_limit (2)
+ {
+ if (omp_in_parallel ()
+ || omp_get_level () != 0
+ || omp_get_ancestor_thread_num (0) != 0
+ || omp_get_ancestor_thread_num (1) != -1)
+ abort ();
+ omp_set_dynamic (0);
+ omp_set_nested (1);
+ #pragma omp parallel num_threads (2)
+ {
+ if (!omp_in_parallel ()
+ || omp_get_level () != 1
+ || omp_get_ancestor_thread_num (0) != 0
+ || omp_get_ancestor_thread_num (1) != omp_get_thread_num ()
+ || omp_get_ancestor_thread_num (2) != -1)
+ abort ();
+ }
+ }
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/teams-2.c b/libgomp/testsuite/libgomp.c/teams-2.c
new file mode 100644
index 0000000..2ddf508
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/teams-2.c
@@ -0,0 +1,123 @@
+#include <omp.h>
+#include <stdlib.h>
+
+__attribute__((noinline))
+void
+foo (int x, int y, int z, int *a, int *b)
+{
+ if (x == 0)
+ {
+ int i, j;
+ for (i = 0; i < 64; i++)
+ #pragma omp parallel for shared (a, b)
+ for (j = 0; j < 32; j++)
+ foo (3, i, j, a, b);
+ }
+ else if (x == 1)
+ {
+ int i, j;
+ #pragma omp distribute dist_schedule (static, 1)
+ for (i = 0; i < 64; i++)
+ #pragma omp parallel for shared (a, b)
+ for (j = 0; j < 32; j++)
+ foo (3, i, j, a, b);
+ }
+ else if (x == 2)
+ {
+ int j;
+ #pragma omp parallel for shared (a, b)
+ for (j = 0; j < 32; j++)
+ foo (3, y, j, a, b);
+ }
+ else
+ {
+ #pragma omp atomic
+ b[y] += z;
+ #pragma omp atomic
+ *a += 1;
+ }
+}
+
+__attribute__((noinline))
+int
+bar (int x, int y, int z)
+{
+ int a, b[64], i;
+ a = 8;
+ for (i = 0; i < 64; i++)
+ b[i] = i;
+ foo (x, y, z, &a, b);
+ if (x == 0)
+ {
+ if (a != 8 + 64 * 32)
+ return 1;
+ for (i = 0; i < 64; i++)
+ if (b[i] != i + 31 * 32 / 2)
+ return 1;
+ }
+ else if (x == 1)
+ {
+ int c = omp_get_num_teams ();
+ int d = omp_get_team_num ();
+ int e = d;
+ int f = 0;
+ for (i = 0; i < 64; i++)
+ if (i == e)
+ {
+ if (b[i] != i + 31 * 32 / 2)
+ return 1;
+ f++;
+ e = e + c;
+ }
+ else if (b[i] != i)
+ return 1;
+ if (a < 8 || a > 8 + f * 32)
+ return 1;
+ }
+ else if (x == 2)
+ {
+ if (a != 8 + 32)
+ return 1;
+ for (i = 0; i < 64; i++)
+ if (b[i] != i + (i == y ? 31 * 32 / 2 : 0))
+ return 1;
+ }
+ else if (x == 3)
+ {
+ if (a != 8 + 1)
+ return 1;
+ for (i = 0; i < 64; i++)
+ if (b[i] != i + (i == y ? z : 0))
+ return 1;
+ }
+ return 0;
+}
+
+int
+main ()
+{
+ int i, j, err = 0;
+ #pragma omp teams reduction(+:err)
+ err += bar (0, 0, 0);
+ if (err)
+ abort ();
+ #pragma omp teams reduction(+:err)
+ err += bar (1, 0, 0);
+ if (err)
+ abort ();
+ #pragma omp teams reduction(+:err)
+ #pragma omp distribute
+ for (i = 0; i < 64; i++)
+ err += bar (2, i, 0);
+ if (err)
+ abort ();
+ #pragma omp teams reduction(+:err)
+ #pragma omp distribute
+ for (i = 0; i < 64; i++)
+ #pragma omp parallel for reduction(+:err)
+ for (j = 0; j < 32; j++)
+ err += bar (3, i, j);
+ if (err)
+ abort ();
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/thread-limit-4.c b/libgomp/testsuite/libgomp.c/thread-limit-4.c
new file mode 100644
index 0000000..5642e6a
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/thread-limit-4.c
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+/* { dg-set-target-env-var OMP_THREAD_LIMIT "9" } */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <omp.h>
+
+int
+main ()
+{
+ if (omp_get_thread_limit () != 9)
+ return 0;
+ omp_set_dynamic (0);
+ #pragma omp parallel num_threads (8)
+ if (omp_get_num_threads () != 8)
+ abort ();
+ #pragma omp parallel num_threads (16)
+ if (omp_get_num_threads () > 9)
+ abort ();
+ #pragma omp teams thread_limit (6)
+ {
+ if (omp_get_thread_limit () > 6)
+ abort ();
+ if (omp_get_thread_limit () == 6)
+ {
+ omp_set_dynamic (0);
+ omp_set_nested (1);
+ #pragma omp parallel num_threads (3)
+ if (omp_get_num_threads () != 3)
+ abort ();
+ #pragma omp parallel num_threads (3)
+ if (omp_get_num_threads () != 3)
+ abort ();
+ #pragma omp parallel num_threads (8)
+ if (omp_get_num_threads () > 6)
+ abort ();
+ #pragma omp parallel num_threads (6)
+ if (omp_get_num_threads () != 6)
+ abort ();
+ int cnt = 0;
+ #pragma omp parallel num_threads (5)
+ #pragma omp parallel num_threads (5)
+ #pragma omp parallel num_threads (2)
+ {
+ int v;
+ #pragma omp atomic capture
+ v = ++cnt;
+ if (v > 6)
+ abort ();
+ usleep (10000);
+ #pragma omp atomic
+ --cnt;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/thread-limit-5.c b/libgomp/testsuite/libgomp.c/thread-limit-5.c
new file mode 100644
index 0000000..d3d22b1
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/thread-limit-5.c
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+#include <omp.h>
+
+int
+main ()
+{
+ #pragma omp teams thread_limit (1)
+ if (omp_get_thread_limit () != 1)
+ abort ();
+ return 0;
+}