aboutsummaryrefslogtreecommitdiff
path: root/libgomp
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-05-02 22:03:38 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2006-05-02 22:03:38 +0200
commit8ca5b2a2d4d6e210374f933c4c09895912d5e4ac (patch)
treeeb02e1dd8220b3599be8ae1486c225f960b5ccf3 /libgomp
parenta3428e070102b16998dacc499781306137b9f787 (diff)
downloadgcc-8ca5b2a2d4d6e210374f933c4c09895912d5e4ac.zip
gcc-8ca5b2a2d4d6e210374f933c4c09895912d5e4ac.tar.gz
gcc-8ca5b2a2d4d6e210374f933c4c09895912d5e4ac.tar.bz2
re PR c++/26943 ([gomp] firstprivate + lastprivate uses inefficient barrier)
PR c++/26943 * omp-low.c (maybe_lookup_decl_in_outer_ctx): New function. (build_outer_var_ref): Use maybe_lookup_decl_in_outer_ctx to find if var will be a global variable even in the nested context. (omp_copy_decl): Only check for global variable at the end, it might be overridden in outer contexts. (scan_sharing_clauses): For global variables don't create a field. (lower_rec_input_clauses): Do nothing for global shared variables. Emit a barrier at the end of ILIST if there were any decls in both firstprivate and lastprivate clauses. (lower_send_clauses): Do nothing for global variables except for COPYIN. * testsuite/libgomp.c/pr26943-1.c: New test. * testsuite/libgomp.c/pr26943-2.c: New test. * testsuite/libgomp.c/pr26943-3.c: New test. * testsuite/libgomp.c/pr26943-4.c: New test. * testsuite/libgomp.c++/pr27337.C: Remove barrier. * testsuite/libgomp.c++/pr26943.C: New test. From-SVN: r113483
Diffstat (limited to 'libgomp')
-rw-r--r--libgomp/ChangeLog10
-rw-r--r--libgomp/testsuite/libgomp.c++/pr26943.C62
-rw-r--r--libgomp/testsuite/libgomp.c++/pr27337.C6
-rw-r--r--libgomp/testsuite/libgomp.c/pr26943-1.c24
-rw-r--r--libgomp/testsuite/libgomp.c/pr26943-2.c47
-rw-r--r--libgomp/testsuite/libgomp.c/pr26943-3.c56
-rw-r--r--libgomp/testsuite/libgomp.c/pr26943-4.c61
7 files changed, 261 insertions, 5 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 754d0f9..76d5631 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,5 +1,15 @@
2006-05-02 Jakub Jelinek <jakub@redhat.com>
+ PR c++/26943
+ * testsuite/libgomp.c/pr26943-1.c: New test.
+ * testsuite/libgomp.c/pr26943-2.c: New test.
+ * testsuite/libgomp.c/pr26943-3.c: New test.
+ * testsuite/libgomp.c/pr26943-4.c: New test.
+ * testsuite/libgomp.c++/pr27337.C: Remove barrier.
+ * testsuite/libgomp.c++/pr26943.C: New test.
+
+2006-05-02 Jakub Jelinek <jakub@redhat.com>
+
PR middle-end/27337
* testsuite/libgomp.c++/pr27337.C: New test.
diff --git a/libgomp/testsuite/libgomp.c++/pr26943.C b/libgomp/testsuite/libgomp.c++/pr26943.C
new file mode 100644
index 0000000..07b7b5d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/pr26943.C
@@ -0,0 +1,62 @@
+// PR c++/26943
+// { dg-do run }
+
+#include <assert.h>
+#include <unistd.h>
+
+struct S
+{
+ public:
+ int x;
+ S () : x(-1) { }
+ S (const S &);
+ S& operator= (const S &);
+ void test ();
+};
+
+static volatile int hold;
+
+S::S (const S &s)
+{
+ #pragma omp master
+ sleep (1);
+
+ assert (s.x == -1);
+ x = 0;
+}
+
+S&
+S::operator= (const S& s)
+{
+ assert (s.x == 1);
+ x = 2;
+ return *this;
+}
+
+void
+S::test ()
+{
+ assert (x == 0);
+ x = 1;
+}
+
+static S x;
+
+void
+foo ()
+{
+ #pragma omp sections firstprivate(x) lastprivate(x)
+ {
+ x.test();
+ }
+}
+
+int
+main ()
+{
+ #pragma omp parallel num_threads(2)
+ foo();
+
+ assert (x.x == 2);
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c++/pr27337.C b/libgomp/testsuite/libgomp.c++/pr27337.C
index c12154e..6db2465 100644
--- a/libgomp/testsuite/libgomp.c++/pr27337.C
+++ b/libgomp/testsuite/libgomp.c++/pr27337.C
@@ -48,11 +48,7 @@ foo ()
#pragma omp parallel for firstprivate (ret) lastprivate (ret) \
schedule (static, 1) num_threads (4)
for (i = 0; i < 4; i++)
- {
- ret.i += omp_get_thread_num ();
- // FIXME: The following barrier should be unnecessary.
-#pragma omp barrier
- }
+ ret.i += omp_get_thread_num ();
return ret;
}
diff --git a/libgomp/testsuite/libgomp.c/pr26943-1.c b/libgomp/testsuite/libgomp.c/pr26943-1.c
new file mode 100644
index 0000000..86c43f0
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr26943-1.c
@@ -0,0 +1,24 @@
+/* PR c++/26943 */
+/* { dg-do run } */
+
+extern void abort (void);
+extern void omp_set_dynamic (int);
+int n = 6;
+
+int
+main (void)
+{
+ int i, x = 0;
+ omp_set_dynamic (0);
+#pragma omp parallel for num_threads (16) firstprivate (n) lastprivate (n) \
+ schedule (static, 1) reduction (+: x)
+ for (i = 0; i < 16; i++)
+ {
+ if (n != 6)
+ ++x;
+ n = i;
+ }
+ if (x || n != 15)
+ abort ();
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/pr26943-2.c b/libgomp/testsuite/libgomp.c/pr26943-2.c
new file mode 100644
index 0000000..7780484
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr26943-2.c
@@ -0,0 +1,47 @@
+/* PR c++/26943 */
+/* { dg-do run } */
+
+extern int omp_set_dynamic (int);
+extern void abort (void);
+
+int a = 8, b = 12, c = 16, d = 20, j = 0;
+char e[10] = "a", f[10] = "b", g[10] = "c", h[10] = "d";
+
+int
+main (void)
+{
+ int i;
+ omp_set_dynamic (0);
+#pragma omp parallel for shared (a, e) firstprivate (b, f) \
+ lastprivate (c, g) private (d, h) \
+ schedule (static, 1) num_threads (4) \
+ reduction (+:j)
+ for (i = 0; i < 4; i++)
+ {
+ if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
+ j++;
+#pragma omp barrier
+#pragma omp atomic
+ a += i;
+ b += i;
+ c = i;
+ d = i;
+#pragma omp atomic
+ e[0] += i;
+ f[0] += i;
+ g[0] = 'g' + i;
+ h[0] = 'h' + i;
+#pragma omp barrier
+ if (a != 8 + 6 || b != 12 + i || c != i || d != i)
+ j += 8;
+ if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
+ j += 64;
+ if (h[0] != 'h' + i)
+ j += 512;
+ }
+ if (j || a != 8 + 6 || b != 12 || c != 3 || d != 20)
+ abort ();
+ if (e[0] != 'a' + 6 || f[0] != 'b' || g[0] != 'g' + 3 || h[0] != 'd')
+ abort ();
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/pr26943-3.c b/libgomp/testsuite/libgomp.c/pr26943-3.c
new file mode 100644
index 0000000..be93cb4
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr26943-3.c
@@ -0,0 +1,56 @@
+/* PR c++/26943 */
+/* { dg-do run } */
+
+extern int omp_set_dynamic (int);
+extern int omp_get_thread_num (void);
+extern void abort (void);
+
+int a = 8, b = 12, c = 16, d = 20, j = 0, l = 0;
+char e[10] = "a", f[10] = "b", g[10] = "c", h[10] = "d";
+volatile int k;
+
+int
+main (void)
+{
+ int i;
+ omp_set_dynamic (0);
+ omp_set_nested (1);
+#pragma omp parallel num_threads (2) reduction (+:l)
+ if (k == omp_get_thread_num ())
+ {
+#pragma omp parallel for shared (a, e) firstprivate (b, f) \
+ lastprivate (c, g) private (d, h) \
+ schedule (static, 1) num_threads (4) \
+ reduction (+:j)
+ for (i = 0; i < 4; i++)
+ {
+ if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
+ j++;
+#pragma omp barrier
+#pragma omp atomic
+ a += i;
+ b += i;
+ c = i;
+ d = i;
+#pragma omp atomic
+ e[0] += i;
+ f[0] += i;
+ g[0] = 'g' + i;
+ h[0] = 'h' + i;
+#pragma omp barrier
+ if (a != 8 + 6 || b != 12 + i || c != i || d != i)
+ j += 8;
+ if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
+ j += 64;
+ if (h[0] != 'h' + i)
+ j += 512;
+ }
+ if (j || a != 8 + 6 || b != 12 || c != 3 || d != 20)
+ ++l;
+ if (e[0] != 'a' + 6 || f[0] != 'b' || g[0] != 'g' + 3 || h[0] != 'd')
+ l += 8;
+ }
+ if (l)
+ abort ();
+ return 0;
+}
diff --git a/libgomp/testsuite/libgomp.c/pr26943-4.c b/libgomp/testsuite/libgomp.c/pr26943-4.c
new file mode 100644
index 0000000..33d3685
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr26943-4.c
@@ -0,0 +1,61 @@
+/* PR c++/26943 */
+/* { dg-do run } */
+
+extern int omp_set_dynamic (int);
+extern int omp_get_thread_num (void);
+extern void abort (void);
+
+int a = 8, b = 12, c = 16, d = 20, j = 0, l = 0;
+char e[10] = "a", f[10] = "b", g[10] = "c", h[10] = "d";
+volatile int k;
+
+int
+main (void)
+{
+ int i;
+ omp_set_dynamic (0);
+ omp_set_nested (1);
+#pragma omp parallel num_threads (2) reduction (+:l) \
+ firstprivate (a, b, c, d, e, f, g, h, j)
+ if (k == omp_get_thread_num ())
+ {
+#pragma omp parallel for shared (a, e) firstprivate (b, f) \
+ lastprivate (c, g) private (d, h) \
+ schedule (static, 1) num_threads (4) \
+ reduction (+:j)
+ for (i = 0; i < 4; i++)
+ {
+ if (a != 8 || b != 12 || e[0] != 'a' || f[0] != 'b')
+ j++;
+#pragma omp barrier
+#pragma omp atomic
+ a += i;
+ b += i;
+ c = i;
+ d = i;
+#pragma omp atomic
+ e[0] += i;
+ f[0] += i;
+ g[0] = 'g' + i;
+ h[0] = 'h' + i;
+#pragma omp barrier
+ if (a != 8 + 6 || b != 12 + i || c != i || d != i)
+ j += 8;
+ if (e[0] != 'a' + 6 || f[0] != 'b' + i || g[0] != 'g' + i)
+ j += 64;
+ if (h[0] != 'h' + i)
+ j += 512;
+ }
+ if (j || a != 8 + 6 || b != 12 || c != 3 || d != 20)
+ ++l;
+ if (e[0] != 'a' + 6 || f[0] != 'b' || g[0] != 'g' + 3 || h[0] != 'd')
+ l += 8;
+ }
+ if (l)
+ abort ();
+ if (a != 8 || b != 12 || c != 16 || d != 20)
+ abort ();
+ if (e[0] != 'a' || f[0] != 'b' || g[0] != 'c' || h[0] != 'd')
+ abort ();
+ return 0;
+}