openmp: Handle reduction clauses on host teams construct [PR96459]
authorJakub Jelinek <jakub@redhat.com>
Wed, 5 Aug 2020 08:40:10 +0000 (10:40 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 5 Aug 2020 08:40:10 +0000 (10:40 +0200)
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.

gcc/omp-low.c
libgomp/testsuite/libgomp.c-c++-common/for-14.c
libgomp/testsuite/libgomp.c-c++-common/for-2.h
libgomp/testsuite/libgomp.c/teams-3.c [new file with mode: 0644]

index 52c2cae..53efe5f 100644 (file)
@@ -11236,7 +11236,7 @@ lower_omp_taskreg (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   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
index 56440ab..d2e3be8 100644 (file)
@@ -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;
index 91a604a..f637fd3 100644 (file)
@@ -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);
diff --git a/libgomp/testsuite/libgomp.c/teams-3.c b/libgomp/testsuite/libgomp.c/teams-3.c
new file mode 100644 (file)
index 0000000..34a9aa0
--- /dev/null
@@ -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;
+}