使用f2py的分段错误 [英] Segmentation faults using f2py

查看:132
本文介绍了使用f2py的分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里提出的问题的跟进工作... 如何使用f2py分配输入数组?

This is a follow up to a question I asked here... How do I allocate input arrays with f2py?

为了回应评论,我对问题进行了重新设计.最初的问题尚不清楚,而且时间太长.请参阅下面的评论1.

I've reworked the question in response to comments. The original question was unclear and too lengthy. See comment 1 below.

我正在尝试使用f2py封装各种fortran子例程/函数,以读取以fortran 77编写的各种原子物理学代码的数据输出.我在Ubuntu 14.04上使用Anaconda python发行版(python 3.4 64 bit)( 64位)和gnu编译器套件(gcc,gfortran等)

I am trying to use f2py to wrap various fortran subroutines/functions for reading the data output from a variety of atomic physics codes written in fortran 77. I am using the Anaconda python distribution (python 3.4 64 bit) on Ubuntu 14.04 (64 bit) with the gnu compiler suite (gcc, gfortran, etc.)

我在尝试在python中预分配数组时遇到问题.我最初的问题涉及分配字符数组.原来我的体形不对.我已经修复了该问题(我认为),现在正在处理细分错误.我已经使用--debug-capi标志使用f2py编译了fortran子例程,以启用详细的错误报告.

I am having issues trying to preallocate the arrays in python. My original question dealt with allocating a character array. Turns out I had the wrong shape. I've fixed that (I think), and am now dealing with a segmentation fault. I've compiled the fortran subroutine with f2py using the --debug-capi flag to enable verbose error reporting.

这是我运行python脚本时获得的终端输出的相关部分.

Here is the relevant portion of the terminal output I get when I run my python script.

debug-capi:Python C/API function adf04_2py.xxdata_04(iunit,titled,iz,iz0,iz1,bwno,npl,bwnoa,lbseta,prtwta,cprta,il,qdorb,lqdorb,qdn,iorb,ia,cstrga,isa,ila,xja,wa,cpla,npla,ipla,zpla,nv,scef,itran,maxlev,tcode,i1a,i2a,aval,scom,beth,iadftyp,lprn,lcpl,lorb,lbeth,letyp,lptyp,lrtyp,lhtyp,lityp,lstyp,lltyp,itieactn,ltied,ndlev=len(ia),ndtrn=shape(tcode,0),ndmet=len(bwnoa),ndqdn=len(qdn),nvmax=len(scef))
debug-capi:int lltyp=:input,required,scalar
debug-capi:lltyp=0

        ####### omitted ##########

debug-capi:int ndmet=len(bwnoa):input,optional,scalar
debug-capi:ndmet=1
debug-capi:Checking `len(bwnoa)>=ndmet'
debug-capi:int ndqdn=len(qdn):input,optional,scalar
debug-capi:ndqdn=1
debug-capi:Checking `len(qdn)>=ndqdn'
debug-capi:int ndlev=len(ia):input,optional,scalar
debug-capi:ndlev=1
debug-capi:Checking `len(ia)>=ndlev'
debug-capi:int lqdorb=:input,required,array,dims((ndqdn*(ndqdn+1))/2|(ndqdn*(ndqdn+1))/2)
debug-capi:string cprta=:input,required,array,string array,dims(ndmet|ndmet,9|9)
debug-capi:double prtwta=:input,required,array,dims(ndmet|ndmet)
debug-capi:double beth=:input,required,array,dims(ndtrn|ndtrn)
debug-capi:string cstrga=:input,required,array,string array,dims(ndlev|ndlev,(*)|(*))
debug-capi:double zpla=:input,required,array,dims(ndmet|ndmet,ndlev|ndlev)
debug-capi:int ltied=:input,required,array,dims(ndlev|ndlev)
debug-capi:int npla=:input,required,array,dims(ndlev|ndlev)
debug-capi:int i2a=:input,required,array,dims(ndtrn|ndtrn)
debug-capi:int lbseta=:input,required,array,dims(ndmet|ndmet)
debug-capi:int i1a=:input,required,array,dims(ndtrn|ndtrn)
debug-capi:int ila=:input,required,array,dims(ndlev|ndlev)
debug-capi:double scom=:input,required,array,dims(nvmax|nvmax,ndtrn|ndtrn)
debug-capi:double qdorb=:input,required,array,dims((ndqdn*(ndqdn+1))/2|(ndqdn*(ndqdn+1))/2)
debug-capi:string cpla=:input,required,array,string array,dims(ndlev|ndlev,1|1)
debug-capi:int isa=:input,required,array,dims(ndlev|ndlev)
debug-capi:double wa=:input,required,array,dims(ndlev|ndlev)
debug-capi:int ipla=:input,required,array,dims(ndmet|ndmet,ndlev|ndlev)
debug-capi:double xja=:input,required,array,dims(ndlev|ndlev)
debug-capi:Fortran subroutine `xxdata_04(&iunit,&ndlev,&ndtrn,&ndmet,&ndqdn,&nvmax,titled,&iz,&iz0,&iz1,&bwno,&npl,bwnoa,lbseta,prtwta,cprta,&il,qdorb,lqdorb,qdn,&iorb,ia,cstrga,isa,ila,xja,wa,cpla,npla,ipla,zpla,&nv,scef,&itran,&maxlev,tcode,i1a,i2a,aval,scom,beth,&iadftyp,&lprn,&lcpl,&lorb,&lbeth,&letyp,&lptyp,&lrtyp,&lhtyp,&lityp,&lstyp,&lltyp,&itieactn,ltied,slen(titled),flen(cstrga))'
Segmentation fault (core dumped)

我的第一个问题是这个.是否可以从调试输出中确切地知道是什么段错误?我不知道如何.

My first question is this. Is it possible to tell from the debug output exactly what segfaulted? I don't see how.

作为第二个问题,如果您查看调试输出的开始,您将看到类似于函数调用的内容,我相信这是python从共享库中调用函数的内容.在调试输出的末尾,您会看到几乎相同的内容,但被标记为"fortran子例程". fortran子例程中的变量与python函数的顺序不同.共享库由f2py根据原始的fortran代码自动创建.有谁知道为什么这些变量的顺序不同?

As a second question, if you look at the beginning of the debug output, you will see something that looks like a function call, which I believe is python calling the function from the shared object. At the end of the debug output you see something almost identical, but is labelled as a 'fortran sub-routine'. The variables in the fortran subroutine are not in the same order as the python function. The shared object was automatically created by f2py from the original fortran code. Any one know why these variables are in a different order?

预先感谢

推荐答案

不确定我是否应该回答这样的问题.如果这违反了协议,那么我会从栈交换能力中得到宽恕.

No sure if I'm supposed to be answering my own questions like this. If this is against protocol then I beg forgiveness from the stack exchange powers that be.

调试输出中包含的所有信息IS(到目前为止).在将"scef"变量分配为适当大小/形状/类型的numpy数组后,segfault消失了.

All the information IS (so far) contained in the debug output. After allocating the 'scef' variabale as a numpy array of the proper size/shape/type the segfault went away.

我仍然遇到进一步的错误,但是到目前为止,使用--debug-capi通过终端输出并仔细调整任何不正确形状/尺寸/类型的大小似乎可以解决这些问题.

I am still getting further errors, but so far going through the terminal output using --debug-capi and carefully resizing anything that is not the correct shape/size/type seems to be fixing them.

如果其他任何人遇到这些问题,我希望这会有所帮助.

If any one else is experiencing these issues, I hope this helps.

这篇关于使用f2py的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆