Bound remapping of contiguous multidimensional array in Fortran with ifort 16

Viewed 815

I have a problem with index remapping that occurs in ifort 16, but does not occur in ifort 14 or in gfortran (exact version numbers are listed below). The problem occurs in the following test program:

program remap_problem

  implicit none

  type :: tp
    real, dimension(:,:,:), allocatable :: trg_in
  end type tp

  real, dimension(:,:,:), allocatable, target :: trg_out

  type(tp), target :: instance
  real, dimension(:,:), pointer :: ptr

  allocate(instance%trg_in(3,4,5))
  allocate(trg_out(3,4,5))

  ptr(0:2,0:3) => instance%trg_in(:,:,2)
  ptr(0:2,0:3) => trg_out(:,:,2)

end program remap_problem

There is a rule in Fortran that you can only redefine the indices (done with the 0:2,0:3) if the target is contiguous or rank one. In this example, the target subarray is contiguous because the last index is the slowest in Fortran.

With ifort 14 or gfortran, it compiles as normal. But ifort 16 complains that the target array in the derived type is not contiguous and I get the following error:

error #8527: If a bound remapping list is specified, data target must be simply contiguous or of rank one.   [TRG_IN]

But, the error does not occur for trg_out. So, somehow, ifort 16 does not recognize the instance%trg_in(:,:,2) as contiguous because it is in a derived type. I tried adding the keyword contiguous here and there and replace allocatable with pointer, but nothing seems to work.

A workaround is:

  ptr(0:2,-4:3) => instance%trg_in

which put the desired elements on the correct indices, but that is dirty. Is there a correct way to fix this issue, or do I have to wait for a compiler update.

The versions of my iforts and gfortran are:

ifort (IFORT) 14.0.2 20140120
ifort (IFORT) 16.0.0 20150815
GNU Fortran (Debian 4.9.2-10) 4.9.2

0 Answers
Related