fortran - gfortran error: zgesvd in lapack -


i doing svd decomposition of square matrix a, a=u s vdag, , in fortran code, line reads

lwork = -1  call zgesvd( 'a', 'a', a%d, a%d, a%m, a%d, s, u%m, u%d, vdag%m, vdag%d,work, lwork, rwork, info )  lwork = int(work(1));deallocate(work); allocate(work(lwork))  call zgesvd( 'a', 'a', a%d, a%d, a%m, a%d, s, u%m, u%d, vdag%m, vdag%d,work, lwork, rwork, info ) 

when compiled gfortran, went through no error or warning. when run program, shows error message:

" ** on entry zgesvd parameter number 11 had illegal value "

i not figure out went wrong.

for reference, definitions of parameters:

type cmatrix    integer(4) d    complex(8), allocatable :: m(:,:) end type  type (cmatrix) a,u,vdag  allocate(a%m(dim,dim),u%m(dim,dim),vdag%m(dim,dim))  a%d = dim; u%m = dim; vdag%d = dim  real(8) s(dim) 

thanks in advance! xiaoyu

p.s. should mentioned such program runs smoothly when compiled ifort, gfortran gives runtime error shown above

--- problem solved!

it seems issue lies in how ifortran , gfortran allocates memory. defined in code usv type which:

type usv    integer is_alloc    type (cmatrix) u,v    real(8), allocatable :: s(:) end usv 

when initializing

type(usv) test_usv(:)  allocate(test_usv(3)),  

the value of is_alloc 0 using intel fortran compiler, while arbitrary number gfortran. need use value criterion allocating u v matrices:

if (is_alloc.eq.0)     allocate(u%m(dim,dim))  end if 

the fundamental problem not difference between ifort , gfortran. approach initialization of variables isn't valid fortran. unless initialize variable declaration, assignment statement, etc., value undefined. 1 way fix add default initialization type definition:

type usv    integer is_alloc = 0    type (cmatrix) u,v    real(8), allocatable :: s(:) end usv 

another approach not track allocation status , rely upon intrinsic function fortran provides purpose:

if (.not. allocated (u%m) ) allocate(u%m(dim,dim)) 

p.s. best practice not rely upon specific numeric values kinds. kind values arbitrary , not number of bytes of type. compilers use number of bytes, others don't. 1 method specify number of bytes , have portable code use types provided iso fortran environment:

use, intrinsic :: iso_fortran_env  integer(int32) :: d real(real64), allocatable :: s(:) 

the types named after number of bits. list of available types in "intrinsic modules" chapter of gfortran manual.


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -