Segmentation fault when calling a subroutine

Segmentation fault when calling a subroutine

I am calling the lapack subroutine DLAPMT in the following snippet of my code:

c    Permute matrix c_all according to IPERM1 

    do i=1, n_sources
        do k=1,g_layers
            do l=1,n_layers
            call DLAPMT (.TRUE., nsim, ndim, c_all(:,:,i,k,l), nsim, IPERM1)
            enddo
     
        enddo
    enddo

 

In this case n_sources is 2, g_layers is 1 and n_layers is 1.  Therefore it should call DLAPMT twice.  The first time it works fine.  The second time it reaches DLAPMT, it kills the process due to a segmentation error. I've checked and all the inputs are exactly the same the second time around.  What could be causing this problem?

 

Thanks

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello, for me DLAPMT works fine. Here is an extended (executable) version of your snippet with some randomly choosen values. 

program test

	    implicit none

	    integer :: i,k,l

	    integer :: n_sources, g_layers, n_layers

	    integer :: nsim, ndim

	    integer, dimension(:), allocatable :: IPERM1

	    integer, dimension(:,:,:,:,:), allocatable :: c_all

	    

	    n_sources = 2

	    g_layers = 1

	    n_layers = 1
    nsim = 3    ! rows

	    ndim = 9    ! columns - permuted
    allocate(c_all(nsim,ndim, n_sources,g_layers,n_layers))

	    allocate(IPERM1(ndim))

	    IPERM1 = [(i, i=1,ndim)]    ! identical permutation
    do i=1, n_sources

	    do k=1,g_layers

	    do l=1,n_layers

	        call DLAPMT(.TRUE., nsim, ndim, c_all(:,:,i,k,l), nsim, IPERM1)

	    enddo     

	    enddo

	    enddo

	end program

Compiled on ifort 14.0.1 with 'ifort -mkl test.f90' (no segfault)

I can see two possible problems with that call:

  • The array c_all is out of bounds for i = 2. This will definitely cause a segfault since lapack relies on the specified dimensions. Did you try to compile with the -check bounds option?
  • The permutation is not a valid permutation of [1,2,...,ndim]. You might check that by simply printing IPERM1.

Maybe the Fortran gurus here can come up with a solution if you provide your compiler / lapack version along with a small example program (ready to compile and run) to demonstrate the segfault. (At least, that's what they would ask me for, with similar problems)

Best regards, Ferdinand

Ok, this seems to be a duplicate of http://software.intel.com/en-us/forums/topic/495000 (solved there)

What are the dimensions of c_all?

IOW is it:  c_all(nsim, ndim, n_sources, g_layers, n_layers)

Jim Dempsey

www.quickthreadprogramming.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today