Include .so modules generated with f2py from fortran script
Hello to everyone, I'm new to python and especially to pypy. I have developed a code in Cpython with some modules, that were the bottle-neck, in fortran thanks to f2py. I'm translating the code as pypy could run (changing def that uses numpy not supported by numpypy) but I'm stuck in finding a way to ingest the .so module into pypy. I have tried with CFFI but with no luck. I have also considered to write the fortran modules (which basically solves linear equation and find the eigenvalues) in pypy but linalg is missing in numpypy. Could you help me? Thanks in advance for your time Fabio
Hi Fabio, On Tue, May 14, 2013 at 12:04 PM, Fabio D'Orta <fabio88.dorta@gmail.com> wrote:
stuck in finding a way to ingest the .so module into pypy. I have tried with CFFI but with no luck.
This is what I would recommend you to try: CFFI. We cannot help you more without any more information about what the problem is, though. A bientôt, Armin.
Hi Armin, thanks for your reply. The problem with CFFI regards the "undefined symbol: PyMem_Free" when I use ffi.dlopen. Trying to import the f2py builted up library 'libprovaf2py.so' from pypy shell, I obtain the following error:
from cffi import FFI ffi = FFI() import ctypes.util # Verifying if ctypes find libprovaf2py.so ctypes.util.find_library('provaf2py') 'libprovaf2py.so' # Trying to open libprovaf2py.so ffi.dlopen('provaf2py') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/fabio/Desktop/PyPy2.0/pypy-2.0/lib_pypy/cffi/api.py", line 111, in dlopen lib, function_cache = _make_ffi_library(self, name, flags) File "/home/fabio/Desktop/PyPy2.0/pypy-2.0/lib_pypy/cffi/api.py", line 365, in _make_ffi_library backendlib = backend.load_library(path, flags) OSError: cannot load library libprovaf2py.so: /usr/lib/x86_64-linux-gnu/libprovaf2py.so: undefined symbol: PyMem_Free
I'm using pypy 2.0 which includes CFFI on ubuntu 12.04 LTS. Don't know if may help, on linux shell (bash) the comand "nm libprovaf2py.so" show me that PyMem_Free is undefined. However, the same module imported directly without CFFI in CPython works. PS: the library 'libprovaf2py.so' is a simple test fortran90 subroutine which accept an integer input and print it to screen. Thanks again. A presto, Fabio 2013/5/14 Armin Rigo <arigo@tunes.org>
Hi Fabio,
On Tue, May 14, 2013 at 12:04 PM, Fabio D'Orta <fabio88.dorta@gmail.com> wrote:
stuck in finding a way to ingest the .so module into pypy. I have tried with CFFI but with no luck.
This is what I would recommend you to try: CFFI. We cannot help you more without any more information about what the problem is, though.
A bientôt,
Armin.
Hi Fabio, On Tue, May 14, 2013 at 5:31 PM, Fabio D'Orta <fabio88.dorta@gmail.com> wrote:
thanks for your reply. The problem with CFFI regards the "undefined symbol: PyMem_Free" when I use ffi.dlopen.
Ah, you're trying to import an .so that is a CPython C extension module. That's not what CFFI is for. With CFFI you can connect directly to C (and probably Fortran) code that is not specifically written for Python (i.e. doesn't contain "#include <Python.h>"). You can call C code from Python with CFFI; this C code may be living in its own (Python-independent) .so file, or may just be more sources that will be compiled along during the call to ffi.verify() if you use "sources=[...]". Look up http://cffi.readthedocs.org for more information. A bientôt, Armin.
Hi Armin, Thank you for the explanation. Knowing nothing about C (difficult syntax to understand) I will try the way to connect Fortran code. Have a nice day, Fabio 2013/5/14 Armin Rigo <arigo@tunes.org>
Hi Fabio,
On Tue, May 14, 2013 at 5:31 PM, Fabio D'Orta <fabio88.dorta@gmail.com> wrote:
thanks for your reply. The problem with CFFI regards the "undefined symbol: PyMem_Free" when I use ffi.dlopen.
Ah, you're trying to import an .so that is a CPython C extension module. That's not what CFFI is for. With CFFI you can connect directly to C (and probably Fortran) code that is not specifically written for Python (i.e. doesn't contain "#include <Python.h>").
You can call C code from Python with CFFI; this C code may be living in its own (Python-independent) .so file, or may just be more sources that will be compiled along during the call to ffi.verify() if you use "sources=[...]". Look up http://cffi.readthedocs.org for more information.
A bientôt,
Armin.
participants (2)
-
Armin Rigo -
Fabio D'Orta