Skip to content

Loop incorrectly parallelised by ParallelLoopTrans #3225

@mn416

Description

@mn416

While working on PR #3213 I found the following example where ParallelLoopTrans incorrectly parallelises a loop:

module main_mod
  implicit none

  type :: Box
    integer :: arr(10)
  end type
contains
  subroutine main()
    type(Box) :: b
    integer :: i

    do i = 1, size(b%arr)
      b%arr(i) = i
      call modify(b)
    end do
  end subroutine

  pure subroutine modify(b)
    type(Box), intent(inout) :: b
    b%arr(1) = 0
  end subroutine
end module

Here is a small script to demonstrate the issue:

from psyclone.psyir.transformations import OMPLoopTrans, TransformationError
from psyclone.psyir.nodes import Loop, Routine

def trans(psyir):
    for loop in psyir.walk(Loop):
        OMPLoopTrans(omp_directive="paralleldo").apply(loop)

Note that DependencyTools actually reports a SCALAR_WRITTEN_ONCE dependency but ParallelLoopTrans explicitly ignores it (for reasons I don't understand). Still, as DependencyTools explores scalar conflicts and array conflicts independently, it never considers the write to b and the write to b%arr(i) to be conflicting, which feels wrong.

@hiker may be interested in this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions