Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29341 Discussions

Segmentation fault + subroutine vs function interface

diedro
Beginner
559 Views

Dear all,

I have a Segmentation fault (core dumped) problem.

When I run my code and I use a function I get a segmentation fault, but only when I use a matrix and a vector with more than 90 elements. I have checked the code but I am not able to find the problem. Could it be the interface problem. Because I allocate some vector and matrix directly in the function. This is my code:

MODULE MOD_SOLVE_COMPLEX_LINEAR_SYSTEM
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
INTERFACE
      FUNCTION SOLVE_COMPLEX_LINEAR_SYSTEM(A,B,m,n,trans) RESULT(X)
         USE lapack95
         IMPLICIT NONE
         COMPLEX , DIMENSION(M,N) , INTENT(IN) :: A      !matrix to solve
         COMPLEX , DIMENSION(N)   , INTENT(IN) :: B      !known term
         INTEGER,                   INTENT(IN) :: m      !
         INTEGER,                   INTENT(IN) :: n      !
         CHARACTER*1,               INTENT(IN) :: trans  !type solver
         COMPLEX , DIMENSION(N)                :: X      !solution
      ENDFUNCTION
ENDINTERFACE
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
ENDMODULE MOD_SOLVE_COMPLEX_LINEAR_SYSTEM
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
!------------------------------------------------------------------------------
FUNCTION SOLVE_COMPLEX_LINEAR_SYSTEM(A,B,m,n,trans) RESULT(X)
USE MOD_SOLVE_COMPLEX_LINEAR_SYSTEM
USE lapack95
IMPLICIT NONE
COMPLEX , DIMENSION(M,N) , INTENT(IN) :: A      !matrix to solve
COMPLEX , DIMENSION(N)   , INTENT(IN) :: B      !known term
INTEGER,                   INTENT(IN) :: m      !
INTEGER,                   INTENT(IN) :: n      !
CHARACTER*1,               INTENT(IN) :: trans  !type solver
COMPLEX , DIMENSION(N)                :: X      !solution

INTEGER, DIMENSION(N)   :: IPIV
COMPLEX, DIMENSION(M,N) :: LA
INTEGER   :: info
 
 LA=A
 X=B

! some operations......

ENDFUNCTION

What do you think? 

Thanks a lot

 

 

0 Kudos
3 Replies
Kevin_D_Intel
Employee
559 Views

Probably the automatic arrays IPIV and LA are exhausting the available stack space. You could try the -heap-arrays option or convert those into alloctable arrays and allocate them at the start of the routine and deallocate at the end.

INTEGER, ALLOCATABLE, DIMENSION(:)   :: IPIV  
COMPLEX, ALLOCATABLE, DIMENSION(:,:) :: LA  
…
ALLOCATE(IPIV(N)
ALLOCATE(LA(M,N)
…

You can refer to Determining Root Cause of Segmentation Faults SIGSEGV or SIGBUS errors for additional information about using -heap-arrays and other possible causes/solutions of segmentation faults.

A couple of links in the article are current broken, the corrected links are included below:

The Doctor Fortran article Don’t Blow Your Stack!
The PDF presentation on Fortran Compiler Use of Temporaries

0 Kudos
mecej4
Honored Contributor III
559 Views

Apparently, you are using the large local array LA (and B) to guard against the overwriting of A by its L-U factors by the actual solver called in the function SOLVE_COMPLEX_LINEAR_SYSTEM (actual code not shown). If so, consider allocating these arrays in the caller of SOLVE_COMPLEX_LINEAR_SYSTEM, setting LA=A and X=B in that caller, and calling the actual solver with these copies as arguments.

0 Kudos
diedro
Beginner
559 Views

Dear all,

thanks a lot.

I have created a subroutine ad as suggested I preallocate IPIV and LA.

Thanks a lot

0 Kudos
Reply