This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp5] Allow OpenMP simd loop iter vars to be private or lastprivate


Hi!

In OpenMP 5.0, although the simd loop iteration vars are still predetermined
linear (for non-collapsed loops or collapse(1)) or lastprivate (collapse>1),
one can explicitly make the iteration variable private or lastprivate;
especially the former is useful to make it clear nothing needs to be
propagated to the original list item.

Tested on x86_64-linux, committed to gomp-5_0-branch.

2018-06-04  Jakub Jelinek  <jakub@redhat.com>

	* gimplify.c (omp_is_private): Allow simd iterator to be lastprivate
	or private.  Fix up diagnostics if linear is used on collapse>1 simd
	iterator.

	* gcc.dg/gomp/simd-1.c: New test.
	* g++.dg/gomp/simd-2.C: New test.

	* testsuite/libgomp.c-c++-common/simd-1.c: New test.

--- gcc/gimplify.c.jj	2018-05-31 17:16:02.925643457 +0200
+++ gcc/gimplify.c	2018-06-04 12:40:32.232748770 +0200
@@ -7463,18 +7463,9 @@ omp_is_private (struct gimplify_omp_ctx
 	  else if ((n->value & GOVD_REDUCTION) != 0)
 	    error ("iteration variable %qE should not be reduction",
 		   DECL_NAME (decl));
-	  else if (simd == 0 && (n->value & GOVD_LINEAR) != 0)
+	  else if (simd != 1 && (n->value & GOVD_LINEAR) != 0)
 	    error ("iteration variable %qE should not be linear",
 		   DECL_NAME (decl));
-	  else if (simd == 1 && (n->value & GOVD_LASTPRIVATE) != 0)
-	    error ("iteration variable %qE should not be lastprivate",
-		   DECL_NAME (decl));
-	  else if (simd && (n->value & GOVD_PRIVATE) != 0)
-	    error ("iteration variable %qE should not be private",
-		   DECL_NAME (decl));
-	  else if (simd == 2 && (n->value & GOVD_LINEAR) != 0)
-	    error ("iteration variable %qE is predetermined linear",
-		   DECL_NAME (decl));
 	}
       return (ctx == gimplify_omp_ctxp
 	      || (ctx->region_type == ORT_COMBINED_PARALLEL
--- gcc/testsuite/gcc.dg/gomp/simd-1.c.jj	2018-06-04 14:32:12.406269289 +0200
+++ gcc/testsuite/gcc.dg/gomp/simd-1.c	2018-06-04 14:13:31.279028667 +0200
@@ -0,0 +1,21 @@
+int a[32], b[32];
+
+void
+foo (void)
+{
+  int i, j;
+  #pragma omp simd linear(i, j) collapse(2)	/* { dg-error "iteration variable 'i' should not be linear" } */
+  for (i = 0; i < 32; ++i)			/* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
+
+void
+bar (void)
+{
+  static int i, j;
+  #pragma omp for simd linear(i, j) collapse(2)	/* { dg-error "iteration variable 'i' should not be linear" } */
+  for (i = 0; i < 32; ++i)			/* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
--- gcc/testsuite/g++.dg/gomp/simd-2.C.jj	2018-06-04 14:32:28.938287583 +0200
+++ gcc/testsuite/g++.dg/gomp/simd-2.C	2018-06-04 14:37:43.931636150 +0200
@@ -0,0 +1,21 @@
+int a[32], b[32];
+
+void
+foo (void)
+{
+  int i, j;
+  #pragma omp simd linear(i, j) collapse(2)	// { dg-error "iteration variable 'i' should not be linear" }
+  for (i = 0; i < 32; ++i)			// { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 }
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
+
+void
+bar (void)
+{
+  static int i, j;
+  #pragma omp for simd linear(i, j) collapse(2)	// { dg-error "iteration variable 'i' should not be linear" "" { target *-*-* } .+1 }
+  for (i = 0; i < 32; ++i)			// { dg-error "iteration variable 'j' should not be linear" }
+    for (j = 0; j < 32; ++j)
+      a[i] += b[j];
+}
--- libgomp/testsuite/libgomp.c-c++-common/simd-1.c.jj	2018-06-04 14:18:27.803356796 +0200
+++ libgomp/testsuite/libgomp.c-c++-common/simd-1.c	2018-06-04 14:19:02.968395710 +0200
@@ -0,0 +1,71 @@
+// { dg-do run }
+// { dg-additional-options "-msse2" { target sse2_runtime } }
+// { dg-additional-options "-mavx" { target avx_runtime } }
+
+#define N 1024
+int a[N], b[N];
+
+int
+f1 (void)
+{
+  int i;
+  #pragma omp simd private (i)
+  for (i = 0; i < N; i++)
+    a[i] = b[i] * 2;
+  #pragma omp simd lastprivate (i)
+  for (i = 0; i < N; i++)
+    a[i] += b[i] * 2;
+  return i;
+}
+
+int
+f2 (void)
+{
+  int i, j;
+  #pragma omp simd private (i), collapse (2), lastprivate (j)
+  for (i = 0; i < 32; i++)
+    for (j = 0; j < 32; ++j)
+      a[i * 32 + j] += b[i * 32 + j] * 2;
+  return j;
+}
+
+int
+f3 (void)
+{
+  static int i;
+  #pragma omp for simd private (i)
+  for (i = 0; i < N; ++i)
+    a[i] = b[i] * 2;
+  #pragma omp for simd lastprivate (i)
+  for (i = 0; i < N; ++i)
+    a[i] += b[i] * 2;
+  return i;
+}
+
+int
+f4 (void)
+{
+  static int i, j;
+  #pragma omp for simd private (i)collapse (2)lastprivate (j)
+  for (i = 0; i < 32; ++i)
+    for (j = 0; j < 32; j++)
+      a[i * 32 + j] += b[i * 32 + j] * 2;
+  return j;
+}
+
+int
+main ()
+{
+  int i;
+  for (i = 0; i < N; ++i)
+    a[i] = b[i] = i;
+  if (f1 () != 1024 || f2 () != 32)
+    __builtin_abort ();
+  #pragma omp parallel num_threads(4)
+  if (f3 () != 1024 || f4 () != 32)
+    __builtin_abort ();
+  for (i = 0; i < N; ++i)
+    if (a[i] != 6 * i || b[i] != i)
+      __builtin_abort ();
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]