I'm experiencing some problems which appear to be from memory handling in my code. I've managed to isolate the problem in the following example. It returns a segmentation fault (core dumped)
at iteration 1024 (that's why I started the loop at 1000) when compiling it with intel but not with gfortran. If the call to the function is commented out, the call to the subroutine will keep working at least to the end of the loop. The theory is that when calling the function, gfortran is fetching the memory for Dmat from the heap, whereas intel is fetching it from the stack.
Is this the case? Is something else happening? This would mean that in order for my code to scale adequately and support intel compilation, I have to define all my procedures as subroutines and just give up on functions?
Test case:
module auxmod
implicit none
contains
function matmul3_fun( Amat, Bmat, Cmat ) result( Dmat )
implicit none
real*8, intent(in) :: Amat(:,:)
real*8, intent(in) :: Bmat(:,:)
real*8, intent(in) :: Cmat(:,:)
real*8 :: Dmat( size(Bmat,1), size(Bmat,2) )
real*8, allocatable :: Emat(:,:)
allocate( Emat( size(Bmat,1), size(Bmat,2) ) )
Emat = matmul( Amat, Bmat )
Dmat = matmul( Emat, Cmat )
end function matmul3_fun
subroutine matmul3_sub( Amat, Bmat, Cmat, Dmat)
implicit none
real*8, intent(in) :: Amat(:,:)
real*8, intent(in) :: Bmat(:,:)
real*8, intent(in) :: Cmat(:,:)
real*8, intent(out) :: Dmat( size(Bmat,1), size(Bmat,2) )
real*8, allocatable :: Emat(:,:)
allocate( Emat( size(Bmat,1), size(Bmat,2) ) )
Emat = matmul( Amat, Bmat )
Dmat = matmul( Emat, Cmat )
end subroutine matmul3_sub
end module auxmod
program size_overflow
use auxmod
implicit none
real*8, allocatable :: Amat(:,:)
real*8, allocatable :: Bmat(:,:)
real*8, allocatable :: Cmat(:,:)
real*8, allocatable :: Dmat(:,:)
integer :: kk
do kk=1000, 2000
allocate ( Amat(kk,kk), Bmat(kk,kk), Cmat(kk,kk), Dmat(kk,kk) )
Amat(:,:) = 1.d0
Bmat(:,:) = 2.d0
Cmat(:,:) = 3.d0
call matmul3_sub( Amat, Bmat, Cmat, Dmat )
write(*,*) "SUB works for size = ", kk
Dmat = matmul3_fun( Amat, Bmat, Cmat )
write(*,*) "FUN works for size = ", kk
deallocate( Amat, Bmat, Cmat, Dmat )
end do
end program size_overflow