I'm fairly new to Fortran and I am having trouble understanding why a subroutine is working fine with a matrix defined statically at compile time, but is not working for a similar matrix created with allocate at runtime.
For all I can tell, the matrices should be very similar: same type, size, sizeof and values. The question is not so much about this specific example, but about why and when they would behalve differently at all.
A 'minimum' working example at pastebin (updated here!), and what I think is the essential part here:
! static 'allocation'
real(dp), dimension(fN, fN) :: fH
! static call
call ZHPADM(pade_deg, fN, dt, fH, fN, fwsp, flwsp, fipiv, iexph, ns, f)
! dynamic allocation
real(dp), allocatable, dimension(:, :) :: dH
allocate(dH(dN, dN))
! dynamic call
call ZHPADM(pade_deg, dN, dt, dH, dN, dwsp, dlwsp, dipiv, iexph, ns, f) ! full dynamic call
call ZHPADM(pade_deg, fN, dt, dH, fN, fwsp, flwsp, fipiv, iexph, ns, f) ! only fH->dH to show that it is the matrix that causes the error
Making any of the other (0D/1D) paramters dynamic works just fine. The routine is ZHPADM from expokit and the error Program received signal 8 (SIGFPE): Floating-point exception. but as said, a general explanation is preferred.
EDIT 1: I forgot to mention some info, sorry for that! Calling ZHPADM with all relevant argument dynamic gives the same error. I just changed some back to static to show that it is the matrix being dynamic that causes the problem. A few lines near the end became inconsistent because of this, sorry. The values for the static and dynamic variables are the same.
EDIT 2: The exception occurs in line 77 in the new pastebin, the dynamic ZHPADM call (commenting that line stops the exception). I'm using gfortran 4.6.3 on Ubuntu like this gfortran demo.f90 -lexpokit -lblas -llapack (and usually some warning flags).
dPP = reshape(dwsp(iexph:iexph+dN**2-1), [dN, dN]):dwspis not initialized! AredNandfNthe same? Don't you need to resetfipiv? Apart from that it's too little information! Please, use all debugging options of your compiler to fix your code until you get no more complaints, and then give the full error description including the line where the exception occured.allocate.dPP =part was based on callingZHPADMwith all dynamic arguments, but I later found out that onlydHgives a problem, so changed it to be minimal. Should have removed the dPP line.