diff mbox series

[committed] openmp: Handle reduction clauses on host teams construct [PR96459]

Message ID 20200805085935.GR2375@tucnak
State New
Headers show
Series [committed] openmp: Handle reduction clauses on host teams construct [PR96459] | expand

Commit Message

Jakub Jelinek Aug. 5, 2020, 8:59 a.m. UTC
Hi!

As the new testcase shows, we weren't actually performing reductions on
host teams construct.  And fixing that revealed a flaw in the for-14.c testcase.
The problem is that the tests perform also initialization and checking around the
calls to the functions with the OpenMP constructs.  In that testcase, all the
tests have been spawned from a teams construct but only the tested loops were
distribute, which means the initialization and checking has been performed
redundantly and racily in each team.  Fixed by performing the initialization
and checking outside of host teams and only do the calls to functions with
the tested constructs inside of host teams.                                                                                                    

2020-08-05  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/96459
	* omp-low.c (lower_omp_taskreg): Call lower_reduction_clauses even in
	for host teams.

	* testsuite/libgomp.c/teams-3.c: New test.
	* testsuite/libgomp.c-c++-common/for-2.h (OMPTEAMS): Define to nothing
	if not defined yet.
	(N(test)): Use it before all N(f*) calls.
	* testsuite/libgomp.c-c++-common/for-14.c (DO_PRAGMA, OMPTEAMS): Define.
	(main): Don't call all test_* functions from within
	#pragma omp teams reduction(|:err), call them directly.


	Jakub
diff mbox series

Patch

--- gcc/omp-low.c.jj	2020-08-03 22:54:51.433531450 +0200
+++ gcc/omp-low.c	2020-08-04 16:29:49.269885408 +0200
@@ -11236,7 +11236,7 @@  lower_omp_taskreg (gimple_stmt_iterator
   gimple_seq par_rlist = NULL;
   lower_rec_input_clauses (clauses, &par_ilist, &par_olist, ctx, NULL);
   lower_omp (&par_body, ctx);
-  if (gimple_code (stmt) == GIMPLE_OMP_PARALLEL)
+  if (gimple_code (stmt) != GIMPLE_OMP_TASK)
     lower_reduction_clauses (clauses, &par_rlist, NULL, ctx);
 
   /* Declare all the variables created by mapping and the variables
--- libgomp/testsuite/libgomp.c/teams-3.c.jj	2020-08-04 16:44:54.063734515 +0200
+++ libgomp/testsuite/libgomp.c/teams-3.c	2020-08-04 16:52:38.961983329 +0200
@@ -0,0 +1,20 @@ 
+/* PR middle-end/96459 */
+
+#include <stdlib.h>
+
+int
+main ()
+{
+  int niters = 0, i, j, k;
+  #pragma omp teams reduction(+:niters)
+  {
+    #pragma omp distribute collapse(3)
+    for (i = 0; i < 3; i++)
+      for (j = 0; j < 8; j += 2)
+	for (k = 0; k < 25; k += 3)
+	  niters++;
+  }
+  if (niters != 108)
+    abort ();
+  return 0;
+}
--- libgomp/testsuite/libgomp.c-c++-common/for-2.h.jj	2020-01-12 11:54:39.027373971 +0100
+++ libgomp/testsuite/libgomp.c-c++-common/for-2.h	2020-08-05 10:19:05.171118863 +0200
@@ -14,6 +14,9 @@  noreturn (void)
 #ifndef OMPTGT
 #define OMPTGT
 #endif
+#ifndef OMPTEAMS
+#define OMPTEAMS
+#endif
 #ifndef OMPTO
 #define OMPTO(v) do {} while (0)
 #endif
@@ -214,31 +217,37 @@  N(test) (void)
   for (i = 0; i < 1500; i++)
     a[i] = i - 25;
   OMPTO (a);
+  OMPTEAMS
   N(f0) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 23)
       return 1;
+  OMPTEAMS
   N(f1) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 25)
       return 1;
+  OMPTEAMS
   N(f2) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 29)
       return 1;
+  OMPTEAMS
   N(f3) (1500LL - 1 - 23 - 48, -1LL + 25 - 48, 1LL);
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 22)
       return 1;
+  OMPTEAMS
   N(f3) (1500LL - 1 - 23 - 48, 1500LL - 1, 7LL);
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 22)
       return 1;
+  OMPTEAMS
   N(f4) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
@@ -249,6 +258,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	b[i][j][k] = i - 2.5 + 1.5 * j - 1.5 * k;
   OMPTO (b);
+  OMPTEAMS
   N(f5) (0, 10, 0, 15, 0, 10, 1, 1, 1);
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -256,6 +266,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f5) (0, 10, 30, 15, 0, 10, 4, 5, 6);
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -263,6 +274,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f6) (9, -1, 29, 0, 9, -1, -1, -2, -1);
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -270,6 +282,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i - 4.5 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f7) ();
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -277,6 +290,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f8) ();	  
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -284,9 +298,13 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f9) ();
+  OMPTEAMS
   N(f10) ();
+  OMPTEAMS
   N(f11) (10);
+  OMPTEAMS
   N(f12) (12);
   OMPFROM (a);
   OMPFROM (b);
@@ -298,7 +316,9 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f13) ();
+  OMPTEAMS
   N(f14) ();
   OMPFROM (a);
   OMPFROM (b);
@@ -507,26 +527,31 @@  N(test) (void)
   for (i = 0; i < 1500; i++)
     a[i] = i - 25;
   OMPTO (a);
+  OMPTEAMS
   N(f20) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 23)
       return 1;
+  OMPTEAMS
   N(f21) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 25)
       return 1;
+  OMPTEAMS
   N(f22) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 29)
       return 1;
+  OMPTEAMS
   N(f23) (1500LL - 1 - 23 - 48, -1LL + 25 - 48);
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
     if (a[i] != i - 22)
       return 1;
+  OMPTEAMS
   N(f24) ();
   OMPFROM (a);
   for (i = 0; i < 1500; i++)
@@ -537,6 +562,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	b[i][j][k] = i - 2.5 + 1.5 * j - 1.5 * k;
   OMPTO (b);
+  OMPTEAMS
   N(f25) (0, 10, 0, 15, 0, 10, 1);
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -544,6 +570,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f25) (0, 10, 30, 15, 0, 10, 5);
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -551,6 +578,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f26) (9, -1, 29, 0, 9, -1, -2);
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -558,6 +586,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i - 4.5 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f27) ();
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -565,6 +594,7 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f28) ();
   OMPFROM (b);
   for (i = 0; i < 10; i++)
@@ -572,9 +602,13 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f29) ();
+  OMPTEAMS
   N(f30) ();
+  OMPTEAMS
   N(f31) (20);
+  OMPTEAMS
   N(f32) (12);
   OMPFROM (a);
   OMPFROM (b);
@@ -586,7 +620,9 @@  N(test) (void)
       for (k = 0; k < 10; k++)
 	if (b[i][j][k] != i + 1.0 + 1.5 * j - 1.5 * k)
 	  return 1;
+  OMPTEAMS
   N(f33) ();
+  OMPTEAMS
   N(f34) ();
   OMPFROM (a);
   OMPFROM (b);
--- libgomp/testsuite/libgomp.c-c++-common/for-14.c.jj	2020-01-12 11:54:39.027373971 +0100
+++ libgomp/testsuite/libgomp.c-c++-common/for-14.c	2020-08-05 10:20:26.034937370 +0200
@@ -6,6 +6,8 @@  extern
 #endif
 void abort ();
 
+#define DO_PRAGMA(x) _Pragma (#x)
+#define OMPTEAMS DO_PRAGMA (omp teams)
 #define M(x, y, z) O(x, y, z)
 #define O(x, y, z) x ## _ ## y ## _ ## z
 
@@ -77,33 +79,30 @@  int
 main ()
 {
   int err = 0;
-  #pragma omp teams reduction(|:err)
-    {
-      err |= test_d_normal ();
-      err |= test_d_ds128_normal ();
-      err |= test_ds_normal ();
-      err |= test_ds_ds128_normal ();
-      err |= test_dpf_static ();
-      err |= test_dpf_static32 ();
-      err |= test_dpf_auto ();
-      err |= test_dpf_guided32 ();
-      err |= test_dpf_runtime ();
-      err |= test_dpf_ds128_static ();
-      err |= test_dpf_ds128_static32 ();
-      err |= test_dpf_ds128_auto ();
-      err |= test_dpf_ds128_guided32 ();
-      err |= test_dpf_ds128_runtime ();
-      err |= test_dpfs_static ();
-      err |= test_dpfs_static32 ();
-      err |= test_dpfs_auto ();
-      err |= test_dpfs_guided32 ();
-      err |= test_dpfs_runtime ();
-      err |= test_dpfs_ds128_static ();
-      err |= test_dpfs_ds128_static32 ();
-      err |= test_dpfs_ds128_auto ();
-      err |= test_dpfs_ds128_guided32 ();
-      err |= test_dpfs_ds128_runtime ();
-    }
+  err |= test_d_normal ();
+  err |= test_d_ds128_normal ();
+  err |= test_ds_normal ();
+  err |= test_ds_ds128_normal ();
+  err |= test_dpf_static ();
+  err |= test_dpf_static32 ();
+  err |= test_dpf_auto ();
+  err |= test_dpf_guided32 ();
+  err |= test_dpf_runtime ();
+  err |= test_dpf_ds128_static ();
+  err |= test_dpf_ds128_static32 ();
+  err |= test_dpf_ds128_auto ();
+  err |= test_dpf_ds128_guided32 ();
+  err |= test_dpf_ds128_runtime ();
+  err |= test_dpfs_static ();
+  err |= test_dpfs_static32 ();
+  err |= test_dpfs_auto ();
+  err |= test_dpfs_guided32 ();
+  err |= test_dpfs_runtime ();
+  err |= test_dpfs_ds128_static ();
+  err |= test_dpfs_ds128_static32 ();
+  err |= test_dpfs_ds128_auto ();
+  err |= test_dpfs_ds128_guided32 ();
+  err |= test_dpfs_ds128_runtime ();
   if (err)
     abort ();
   return 0;