I’m experiencing a problem using implicit dos (in a write statement) with allocatable arrays (allocated in a subroutine). For instance:
Program Main
Implicit None
Real*8 CoorIn(3,23)
Integer i,j
Do j=1,Size(CoorIn,1)
Do i=1,Size(CoorIn,2)
CoorIn(j,i) = DBLE(i)
End Do
End Do
Call PrintCoor(CoorIn,Size(CoorIn,2))
End Program
Subroutine PrintCoor(CoorIn,n)
Implicit None
Integer n
Real*8 CoorIn(3,n)
interface mma_allocate
subroutine dmma_allo_2D(buffer,n1,n2,label)
real*8, allocatable :: buffer(:,:)
integer :: n1, n2
character (len=*), optional :: label
end subroutine
end interface
interface mma_deallocate
subroutine dmma_free_2D(buffer)
real*8, allocatable :: buffer(:,:)
end subroutine
end interface
Real*8, Dimension(:,:), Allocatable :: Coor
Integer :: i,j
Call mma_allocate(Coor,3,n)
Do j=1,3
Do i=1,n
Coor(j,i) = CoorIn(j,i)*DBLE(j)
End Do
End Do
Write(6,*) 'Explicit loop'
Do i=1,n
Write (6,'(19X,3F11.5)') Coor(1,i),Coor(2,i),Coor(3,i)
End Do
Write(6,*) 'Implict loop'
Write (6,'(19X,3F11.5)') ((Coor(j,i),j=1,3),i=1,n)
Call mma_deallocate(Coor)
Return
End Subroutine
subroutine dmma_allo_2D(buffer,n1,n2,label)
implicit none
real*8, allocatable :: buffer(:,:)
integer :: n1, n2
character (len=*), optional :: label
allocate(buffer(n1,n2))
end subroutine
subroutine dmma_free_2D(buffer)
implicit none
real*8, allocatable :: buffer(:,:)
deallocate(buffer)
end subroutine
Compiling this code with “pgfortran test.f -i8” causes (when running the resulting binary):
Implict loop
PGFIO-F-235/formatted write/unit=6/edit descriptor does not match item type.
File name = stdout formatted, sequential access record = 26
In source file test.f, at line number 44
Removing “-i8” or adding “-gopt” gets rid of the problem. A simplified version that does not have “printcoor” as a subroutine, but as the main program, causes segmentation faults. This happens with versions 14.7-0 and 16.7-0 at least.
Is there something intrinsically wrong with the code or is this a compiler bug? Other compilers like gfortran do not seem to have a problem with it.