https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96668

            Bug ID: 96668
           Summary: [OpenMP] Re-mapping allocated but previously
                    unallocated allocatable does not work
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

The exact behaviour is not well specified in OpenMP 4.5 or 5.0 but at least
with 'always' the following is expected to map.
(See OpenMP Issue 2152 + upcoming OpenMP TR9 – which require the always
modifier. There is code which expects that implicit mapping and mapping without
always modifier also works.)

For pointers, at least OpenMP 5.0 seems to require that the POINTER target is
automatically mapped:

module m
implicit none
  integer, pointer :: p1 => null()
  integer, pointer :: p1 => null()
  integer, allocatable :: a1, a2(:)
  !$omp declare target(p1, p2, a1, a2)
end module m

use m
implicit none
  integer, pointer :: q1, q2(:)
  q1 => null()
  q2 => null()
  integer, allocatable :: b1, b2(:)
  allocate (a1, source=12)
  allocate (a2, source=[11,22,33])
  allocate (p1, source=42)
  allocate (p2, source=[1,3,5,7])

  !$omp target data map(b1, b2, q1, q2)
     allocate (b1, source=35)
     allocate (b2, source=[10,11,12,13,14])
     allocate (q1, source=4)
     allocate (q2, source=[9,8,7,6,5,4])

     ! allocatable, TR9 requires 'always' modifier:
     !$omp target map(always, tofrom: a1, a2, b1, b2)
       if (.not. allocated(a1)) stop 1
       if (.not. allocated(a2)) stop 1
       if (.not. allocated(b1)) stop 1
       if (.not. allocated(b2)) stop 1
       if (size(a2) /= 3) stop 1
       if (size(b2) /= 5) stop 1
       if (a1 /= 12) stop 1
       if (any (a2 /= [11,22,33])) stop 1
       if (b1 /= 42) stop 1
       if (any (b2 /= [10,11,12,13,14])) stop 1
       a1 = 3
       a2(:) = [44,55,66]
       b1 = 68
       b2(:) = [101, 102, 103, 104, 105]
     !$omp end target

     ! pointer: allegedly target is automatically mapped
     ! without requiring an explicit mapping or even the always modifier
     !$omp target  !! map(always, tofrom: p1, p2, q1, q2)
       if (.not. associated(p1)) stop 1
       if (.not. associated(p2)) stop 1
       if (.not. associated(q1)) stop 1
       if (.not. associated(q2)) stop 1
       if (size(p2) /= 4) stop 1
       if (size(q2) /= 6) stop 1
       if (p1 /= 42) stop 1
       if (any (p2 /= [1,3,5,7])) stop 1
       if (q1 /= 4) stop 1
       if (any (q2 /= [9,8,7,6,5,4])) stop 1
       p1 = 373
       p2(:) = [2,4,6,8]
       q1 = 497
       q2(:) = [-1, -2, -3, -4, -5, -6]
     !$omp end target
  !$omp end target data

  if (a1 /= 3) stop 1
  if (any (a2 /= [44,55,66])) stop 1
  if (b1 /= 68) stop 1
  if (any (b2 /= [10,11,12,13,14])) stop 1

  if (p1 /= 373) stop 1
  if (any (p2 /= [2,4,6,8])) stop 1
  if (q1 /= 397) stop 1
  if (any (q2 /= [-1, -2, -3, -4, -5, -6])) stop 1

  deallocate(a1, a2, b1, b2, p1, p2, q1, q2)
end

Reply via email to