[SciPy-User] Fwd: f2py segfault

Dag Sverre Seljebotn dagss@student.matnat.uio...
Mon Jan 18 09:56:42 CST 2010


Dag Sverre Seljebotn wrote:
> Juan wrote:
>> Hi, thanks for the advice. I did not notice that the integer division 
>> could be a
>> source for trouble. Now I changed all the routines. However, I still 
>> have the
>> same segmentation fault.
>>
>>
>> debug-capi:Python C/API function
>> mymod.sub0(state,ndim=shape(state,0),ntrajectories=shape(state,1))
>> debug-capi:double
>> state=:inoutput,required,array,dims(ndim|ndim,ntrajectories|ntrajectories) 
>>
>> debug-capi:int ndim=shape(state,0):input,optional,scalar
>> debug-capi:ndim=24
>> debug-capi:Checking `shape(state,0)==ndim'
>> debug-capi:int ntrajectories=shape(state,1):input,optional,scalar
>> debug-capi:ntrajectories=100
>> debug-capi:Checking `shape(state,1)==ntrajectories'
>> debug-capi:Fortran subroutine `sub0(state,&ndim,&ntrajectories)'
>> debug-capi:ndim=24
>> debug-capi:ntrajectories=100
>> debug-capi:Building return value.
>> debug-capi:Python C/API function mymod.sub0: successful.
>> debug-capi:Freeing memory.
>> debug-capi:Python C/API function
>> mymod.sub1(state,d_i,d_f,ndim=shape(state,0),ntrajectories=shape(state,1)) 
>>
>> debug-capi:double
>> state=:inoutput,required,array,dims(ndim|ndim,ntrajectories|ntrajectories) 
>>
>> Segmentation fault
>>
>> The working sub1 has two other arguments d_i and d_f which are real 
>> scalars, the
>> full signatures are:
>>
>>   subroutine sub0(state, Ndim, Ntrajectories)
>>     integer(I32), intent(IN) :: Ndim
>>     integer(I32), intent(IN) :: Ntrajectories
>>     real(R64), intent(INOUT), dimension(Ndim,Ntrajectories) :: state
>>     ...
>>   end subroutine sub0
>>
>>   subroutine sub1(state,d_i,d_f, Ndim,Ntrajectories)
>>     integer(4), intent(IN) :: Ndim
>>     integer(4), intent(IN) :: Ntrajectories
>>     real(8), intent(INOUT), dimension(Ndim, Ntrajectories) :: state
>>     real(8), intent(IN) :: d_i
>>     real(8), intent(IN) :: d_f
>>     print *, shape(state), Ndim, Ntrajectories
>>     ...
>>   end subroutine sub1
>>
>> and I am calling from my script as:
>>
>> import mymod
>> Ndim=24
>> Ntrajectories=10
>> di=0., df=10.
>> r= np.zeros((Ndim,Ntrajectories),dtype=np.float64, order='Fortran')
>>
>> mymod.sub0(r)
>> mymod.sub1(r, di, df)
>>
>> As it can be seen from the debug output, f2py is checking the 
>> arguments for sub0
>> but it segfault before checking the args in sub1 (with no very 
>> informative
>> messages).
>>
>> It may well be a problem related to theworkings of the routines but 
>> they work
>> when I use them in tests on pure fortran code. Additionally I get a 
>> very similar
>> error message if I call sub0 (mymod.sub0(r)) instead of sub1 
>> (mymod.sub1(r, di,
>> df)) the second time in the python script.
>>
>> Any ideas? Thanks again. Juan
>>   
> Did you say which Fortran compiler you were using? f2py makes some 
> blatant assumptions about the Fortran compiler which is nowhere in any 
> standard. If you don't use gfortran you may get problems.
>
> Dag Sverre
>
Actually, other compilers may work very well -- I just don't know 
myself, but know that that is a possible source of problems...

Dag Sverre



More information about the SciPy-User mailing list