Fortran: invalid bounds in forall

I have encountered some issues with the following code (using PGI 19.10 on Linux):

  program forall_matmul
      implicit none
      real, dimension(3,3,3,3) :: C, r
      real, dimension(3,3)     :: F
      integer :: i,j
      ! compile with -Mbounds to get a runtime error
        r(i,j,1:3,1:3) = matmul(F,C(i,j,1:3,1:3))
      print*, r                ! all r should be 3 (some 2 appear)

  end program forall_matmul

Compiling with


gives the following error message during runtime

0: Subscript out of range for array c (forall_matmul.f90: 12)
    subscript=32766, lower bound=1, upper bound=3, dimension=1

Sorry, I’ve just realized that I’ve already reported this issue and it was recorded as problem report TPR#27034.

No worries. I took a look at FS#27034 and one engineer suggested that you could try replacing “forall” with a “do concurrent” as a work around.