[SciPy-User] Wrapping a lapack function (attempt results seg fault)

Skipper Seabold jsseabold@gmail....
Sat Feb 6 17:12:53 CST 2010


On Sat, Feb 6, 2010 at 6:07 PM,  <josef.pktd@gmail.com> wrote:
> On Sat, Feb 6, 2010 at 6:02 PM, Skipper Seabold <jsseabold@gmail.com> wrote:
>> On Sat, Feb 6, 2010 at 5:45 PM,  <josef.pktd@gmail.com> wrote:
>>> On Sat, Feb 6, 2010 at 3:10 PM, Skipper Seabold <jsseabold@gmail.com> wrote:
>>>> All,
>>>>
>>>> I'm trying to wrap the lapack function dtgsen for the ordered generalized
>>>> Schur decomposition given real valued arrays
>>>> <http://linux.die.net/man/l/dtgsen>.  However, I'm getting a segmentation
>>>> fault, and I have no idea why.  I was hoping someone might look at my work
>>>> and see where I've gone wrong, as this is my first attempt at trying to do
>>>> something like this.  One specific thing I wasn't sure about is when the
>>>> lapack function calls for a LOGICAL type can this just be
>>>>
>>>> from ctypes import c_bool
>>>> logical_true = c_bool(True)
>>>>
>>>> ?
>>>>
>>>> I've attached my functions and arrays that make a self-contained example.
>>>>  Just put the two files in a directory and run.  When I do a gdb backtrace I
>>>> receive the following output.
>>>>
>>>> (gdb) run ordqztest.py
>>>>
>>>> Starting program: /usr/bin/python ordqztest.py
>>>>
>>>> [Thread debugging using libthread_db enabled]
>>>>
>>>>
>>>> Program received signal SIGSEGV, Segmentation fault.
>>>> 0x00007ffff5015d7d in dtgsen_ () from /usr/lib/liblapack.so
>>>> (gdb) backtrace
>>>> #0  0x00007ffff5015d7d in dtgsen_ () from /usr/lib/liblapack.so
>>>> #1  0x00007ffff6da8bec in ffi_call_unix64 ()
>>>>    at
>>>> /build/buildd/python2.6-2.6.4/Modules/_ctypes/libffi/src/x86/unix64.S:75
>>>> #2  0x00007ffff6da82d3 in ffi_call (cif=0x7fffffffd810, fn=<value optimized
>>>> out>,
>>>>    rvalue=<value optimized out>, avalue=<value optimized out>)
>>>>
>>>>    at
>>>> /build/buildd/python2.6-2.6.4/Modules/_ctypes/libffi/src/x86/ffi64.c:430
>>>> #3  0x00007ffff6da2d64 in _call_function_pointer (pProc=<value optimized
>>>> out>,
>>>>    argtuple=<value optimized out>, flags=<value optimized out>,
>>>> argtypes=<value optimized out>,
>>>>    restype=<value optimized out>, checker=<value optimized out>)
>>>>
>>>>    at /build/buildd/python2.6-2.6.4/Modules/_ctypes/callproc.c:816
>>>>
>>>> #4  _CallProc (pProc=<value optimized out>, argtuple=<value optimized out>,
>>>>
>>>>    flags=<value optimized out>, argtypes=<value optimized out>,
>>>> restype=<value optimized out>,
>>>>    checker=<value optimized out>) at
>>>> /build/buildd/python2.6-2.6.4/Modules/_ctypes/callproc.c:1163
>>>> #5  0x00007ffff6d9abf7 in CFuncPtr_call (self=0xc2c2c0, inargs=0x18,
>>>> kwds=<value optimized out>)
>>>>    at /build/buildd/python2.6-2.6.4/Modules/_ctypes/_ctypes.c:3860
>>>>
>>>> #6  0x000000000041d6e7 in PyObject_Call (func=0xc2c2c0, arg=0xcb8360,
>>>> kw=0xc63520)
>>>>    at ../Objects/abstract.c:2492
>>>>
>>>> #7  0x00000000004a199c in do_call (f=0xcb98c0, throwflag=<value optimized
>>>> out>)
>>>>    at ../Python/ceval.c:3924
>>>>
>>>> #8  call_function (f=0xcb98c0, throwflag=<value optimized out>) at
>>>> ../Python/ceval.c:3729
>>>> #9  PyEval_EvalFrameEx (f=0xcb98c0, throwflag=<value optimized out>) at
>>>> ../Python/ceval.c:2389
>>>> #10 0x00000000004a40e0 in PyEval_EvalCodeEx (co=0x7ffff7f01f30,
>>>> globals=<value optimized out>,
>>>>    locals=<value optimized out>, args=0x9, argcount=<value optimized out>,
>>>> kws=<value optimized out>,
>>>>    kwcount=2, defs=0x7ffff7f0a7f8, defcount=4, closure=0x0) at
>>>> ../Python/ceval.c:2968
>>>> #11 0x00000000004a245f in fast_function (f=0xcb9660, throwflag=<value
>>>> optimized out>)
>>>>    at ../Python/ceval.c:3802
>>>>
>>>> #12 call_function (f=0xcb9660, throwflag=<value optimized out>) at
>>>> ../Python/ceval.c:3727
>>>> ---Type <return> to continue, or q <return> to quit---
>>>>
>>>> #13 PyEval_EvalFrameEx (f=0xcb9660, throwflag=<value optimized out>) at
>>>> ../Python/ceval.c:2389
>>>> #14 0x00000000004a40e0 in PyEval_EvalCodeEx (co=0x7ffff7f026c0,
>>>> globals=<value optimized out>,
>>>>    locals=<value optimized out>, args=0x8, argcount=<value optimized out>,
>>>> kws=<value optimized out>,
>>>>    kwcount=2, defs=0x7ffff3ea9e78, defcount=3, closure=0x0) at
>>>> ../Python/ceval.c:2968
>>>> #15 0x00000000004a245f in fast_function (f=0x928e00, throwflag=<value
>>>> optimized out>)
>>>>    at ../Python/ceval.c:3802
>>>> #16 call_function (f=0x928e00, throwflag=<value optimized out>) at
>>>> ../Python/ceval.c:3727
>>>> #17 PyEval_EvalFrameEx (f=0x928e00, throwflag=<value optimized out>) at
>>>> ../Python/ceval.c:2389
>>>> #18 0x00000000004a40e0 in PyEval_EvalCodeEx (co=0x7ffff7f02378,
>>>> globals=<value optimized out>,
>>>>    locals=<value optimized out>, args=0x0, argcount=<value optimized out>,
>>>> kws=<value optimized out>,
>>>>    kwcount=0, defs=0x0, defcount=0, closure=0x0) at ../Python/ceval.c:2968
>>>> #19 0x00000000004a41b2 in PyEval_EvalCode (co=0x0, globals=0xcb8360,
>>>> locals=0xc63520)
>>>>    at ../Python/ceval.c:522
>>>> #20 0x00000000004c33a0 in run_mod (fp=0x919900, filename=<value optimized
>>>> out>,
>>>>    start=<value optimized out>, globals=<value optimized out>,
>>>> locals=0x8b9270, closeit=1,
>>>>    flags=0x7fffffffe100) at ../Python/pythonrun.c:1335
>>>> #21 PyRun_FileExFlags (fp=0x919900, filename=<value optimized out>,
>>>> start=<value optimized out>,
>>>>    globals=<value optimized out>, locals=0x8b9270, closeit=1,
>>>> flags=0x7fffffffe100)
>>>>    at ../Python/pythonrun.c:1321
>>>> #22 0x00000000004c3564 in PyRun_SimpleFileExFlags (fp=<value optimized out>,
>>>>    filename=0x7fffffffe518 "ordqztest.py", closeit=1, flags=0x7fffffffe100)
>>>>    at ../Python/pythonrun.c:931
>>>> #23 0x0000000000418ab7 in Py_Main (argc=-135384960, argv=<value optimized
>>>> out>) at ../Modules/main.c:599
>>>> #24 0x00007ffff6fd0abd in __libc_start_main (main=<value optimized out>,
>>>> argc=<value optimized out>,
>>>>    ubp_av=<value optimized out>, init=<value optimized out>, fini=<value
>>>> optimized out>,
>>>>    rtld_fini=<value optimized out>, stack_end=0x7fffffffe218) at
>>>> libc-start.c:220
>>>> #25 0x0000000000417ca9 in _start () at ../sysdeps/x86_64/elf/start.S:113
>>>>
>>>> Any help or pointers would be appreciated, as I am a bit out of my depth.
>>>>
>>>> -Skipper
>>>>
>>>> _______________________________________________
>>>> SciPy-User mailing list
>>>> SciPy-User@scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>>
>>>>
>>>
>>> according to http://www.netlib.org/lapack/double/dtgsen.f  you are
>>> missing alphai  in the argument list.
>>>
>>
>> Ah, that is true.  I wonder why it didn't complain about my arguments
>> list.  I originally tried to do the complex version, but then realized
>> I didn't need it as of yet.  Still seg faults though.
>>
>>> I don't have (or find) c_bool in python 2.5, so my tries are also unsuccessful.
>>>
>>
>> This is where I think it might be tripping up, but I don't know if
>> LOGICAL type can just be a c_int.
>
> I tried this, but it wasn't successful, and I have no idea about these types
>
>>
>>> Maybe wrapping with f2py like the routines in scipy.linalg might be a
>>> better choice than ctypes? However, I haven't seen a recipe how to do
>>> it.
>>>
>>
>> I guess I do have the fortran source file.  I will try this.  I think
>> I should just have to add the f2py directives for the inputs/outputs
>> and (fingers-crossed) it will work.
>
> I didn't look carefully, but the netlib with dependencies has a lot of
> files, so it might not be so easy to do it standalone.
>

As I just discovered...

> Here is a open ticket that wraps a new function
>
> http://projects.scipy.org/scipy/ticket/964
>
> maybe good for inspiration
>
> Josef
>
>>
>> Skipper
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list