public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Fortran/OpenMP: Fix detecting not perfectly nested loops
@ 2020-08-04 15:54 Tobias Burnus
  2020-08-04 16:14 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2020-08-04 15:54 UTC (permalink / raw)
  To: gcc-patches, Jakub Jelinek, fortran

[-- Attachment #1: Type: text/plain, Size: 669 bytes --]

I am not sure whether the following code is supposed
to work but the "x = 5" is never converted into
tree-code in gfc_trans_omp_do – hence, it makes sense
to error out. (I have the feeling that this needs to
be revisited for OpenMP 5.x.)

(The equivalent C/C++ code is rejected, see PR.)

    !$omp parallel do collapse(3)
    do i = 1, 8
       do j = 1, 8
         do k = 1, 8
         end do
         x = 5  ! <<<
       end do
    end do

OK?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

[-- Attachment #2: omp-collapsed.diff --]
[-- Type: text/x-patch, Size: 2772 bytes --]

Fortran/OpenMP: Fix detecting not perfectly nested loops

gcc/fortran/ChangeLog:

	* openmp.c (resolve_omp_do): Detect not perfectly
	nested loop with innermost collapse.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/collapse1.f90: Add dg-error.
	* gfortran.dg/gomp/collapse2.f90: New test.

 gcc/fortran/openmp.c                         |  4 +---
 gcc/testsuite/gfortran.dg/gomp/collapse1.f90 |  2 +-
 gcc/testsuite/gfortran.dg/gomp/collapse2.f90 | 32 ++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index ec116206a5c..f402febc211 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -6201,18 +6201,16 @@ resolve_omp_do (gfc_code *code)
 		}
 	      do_code2 = do_code2->block->next;
 	    }
 	}
-      if (i == collapse)
-	break;
       for (c = do_code->next; c; c = c->next)
 	if (c->op != EXEC_NOP && c->op != EXEC_CONTINUE)
 	  {
 	    gfc_error ("collapsed %s loops not perfectly nested at %L",
 		       name, &c->loc);
 	    break;
 	  }
-      if (c)
+      if (i == collapse || c)
 	break;
       do_code = do_code->block;
       if (do_code->op != EXEC_DO && do_code->op != EXEC_DO_WHILE)
 	{
diff --git a/gcc/testsuite/gfortran.dg/gomp/collapse1.f90 b/gcc/testsuite/gfortran.dg/gomp/collapse1.f90
index f16a780ad99..1a06eaba823 100644
--- a/gcc/testsuite/gfortran.dg/gomp/collapse1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/collapse1.f90
@@ -30,9 +30,9 @@ subroutine collapse1
   !$omp parallel do collapse(2)
     do i = 1, 3
       do j = 4, 6
       end do
-      k = 4
+      k = 4  ! { dg-error "loops not perfectly nested" }
     end do
   !$omp parallel do collapse(2)
     do i = 1, 3
       do			! { dg-error "cannot be a DO WHILE or DO without loop control" }
diff --git a/gcc/testsuite/gfortran.dg/gomp/collapse2.f90 b/gcc/testsuite/gfortran.dg/gomp/collapse2.f90
new file mode 100644
index 00000000000..1ab934e3d0d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/collapse2.f90
@@ -0,0 +1,32 @@
+program p
+   integer :: i, j, k
+   real :: x
+   !$omp parallel do collapse(3)
+   do i = 1, 8
+      do j = 1, 8
+        do k = 1, 8
+        end do
+        x = 5  ! { dg-error "loops not perfectly nested" }
+      end do
+   end do
+   !$omp parallel do ordered(3)
+   do i = 1, 8
+      do j = 1, 8
+        do k = 1, 8
+        end do
+      end do
+      x = 5  ! { dg-error "loops not perfectly nested" }
+   end do
+   !$omp parallel do collapse(2)  ! { dg-error "not enough DO loops for collapsed" }
+   do i = 1, 8
+      x = 5
+      do j = 1, 8
+      end do
+   end do
+   !$omp parallel do ordered(2)  ! { dg-error "not enough DO loops for collapsed" }
+   do i = 1, 8
+      x = 5
+      do j = 1, 8
+      end do
+   end do
+end

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch] Fortran/OpenMP: Fix detecting not perfectly nested loops
  2020-08-04 15:54 [Patch] Fortran/OpenMP: Fix detecting not perfectly nested loops Tobias Burnus
@ 2020-08-04 16:14 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2020-08-04 16:14 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, fortran

On Tue, Aug 04, 2020 at 05:54:18PM +0200, Tobias Burnus wrote:
> I am not sure whether the following code is supposed
> to work but the "x = 5" is never converted into
> tree-code in gfc_trans_omp_do – hence, it makes sense
> to error out. (I have the feeling that this needs to
> be revisited for OpenMP 5.x.)

Yes 5.0 allows this, but we don't handle that yet.
And I'm afraid I have quite a few questions that need to be discussed :(

> (The equivalent C/C++ code is rejected, see PR.)
> 
>    !$omp parallel do collapse(3)
>    do i = 1, 8
>       do j = 1, 8
>         do k = 1, 8
>         end do
>         x = 5  ! <<<
>       end do
>    end do
> 
> OK?

Ok, thanks.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-04 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-04 15:54 [Patch] Fortran/OpenMP: Fix detecting not perfectly nested loops Tobias Burnus
2020-08-04 16:14 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).