I can not call the same subroutine two time using pgf90 fortran complier on Linux environment. To call the subroutine for the 1st time is OK but calling it for the 2nd time, it gives Segmentation fault. Can some one give some suggestion, what is wrong with my code, As simple example is given as
P.S. with gfortran it is OK, even i tried it on the intel visual fortran and it is OK
program main
use module_Append_1DI
implicit none
integer, allocatable:: Arr(:)
integer::Brr(2)
Brr=[3, 4]
call Append_1DI(Arr,Brr)
write(*,*)Arr
call Append_1DI(Arr,Brr)
write(*,*)Arr
end program main
module module_Append_1DI
contains
subroutine Append_1DI(A,B)
implicit none
!================================================
integer, allocatable, intent(inout)::A(:)
integer, intent(in)::B(:)
integer, allocatable::temp(:)
integer::sizeA,sizeB,sizeN
!================================================
sizeA=size(A); sizeB=size(B); sizeN=sizeA+sizeB
allocate(temp(sizeN)); temp(1:sizeA)=A
call move_alloc(from=temp,to=A)
A(sizeA+1:sizeN)=B
end subroutine Append_1DI
end module module_Append_1DI
To be honest I’m amazed it works the first time you call it. That’s because A is not then allocated, and you are not allowed to use the size intrinsic on an unallocated allocatable array. In fact if you turn on all the checking flags ifort tells you this
gfortran is less clear, but still tells you something is wrong
And to pick another random compiler, that from Sun/oracle, again you get the same message
So the problem is the use of A before it is allocated.
Is the confusion that you think this is a zero size array? Well you need to get that out of your head – an unallocated alloctable array has no defined size at all, which is very different from allocated bu zero size array.
Ian