[capi-sig] Extension module with meschach library and numpy.i (SWIG)

Juan David Hernandez juandhv at yahoo.com
Thu Aug 7 05:20:42 CEST 2008


Hi everybody,

I'm working on some functions to calculate the
response of some physics models. Initially, I coded with C,
nevertheless, I had to connect the physics toolbox to some graphics
tools; for that reason, I decided to use python; actually python is
controlling the high level interface but I decided to keep the physics
core with C(performance); I'm using SWIG to connect my python high level interface with the C physics. I use numpy on python to the define the inputs and outputs for my physics toolbox. To improve the calculation time I use the meschach vectors and matrices library.

This is my setup.py
---
from distutils.core import setup, Extension

import numpy

try:
    numpy_include = numpy.get_include()
except AttributeError:
    numpy_include = numpy.get_numpy_include()

 _cmd_wrapper = Extension("_cmd_wrapper",
                      ["cmd_source1.c","cmd_source2.c",...],
                      include_dirs = [numpy_include,'../mesch12b'],
                      extra_objects=['../mesch12b/meschach.a'],
                      libraries=['m'],
                     )

setup (name = "cmd_wrapper",
       description = "CMD wrapper",
       version = "0.1",
       author = "juandhv",
       py_modules = ["cmd_wrapper"],
       ext_modules = [_cmd_wrapper]
       )

----
When I try to import the result module, import cmd_wrapper, I got this error:

import _cmd_wrapper
ImportError: /ModCMD/_cmd_wrapper.so: failed to map segment from shared object: Cannot allocate memory

There are 3 things that I'd like to know:
1. Is this the correct way to include the meschach library ? extra_objects=['../mesch12b/meschach.a'] 
2. Is there any problem if Meschach use malloc, calloc and realloc?
3. Is there any problem if I declare some variables as static? e.g. static MAT *M1;

I'm running this on a virtual machine over ubuntu with 512MB of RAM, I know that's not too much, but I think
is enough for a module (My module is not bigger than numpy!!). I can
import my module on MAC OS X with more RAM (even on linux with 1GB) but when I tried to import the
module with the complete sotware (others high level tools like graphics
and GUI) I get the same problem

Any help I'll be thankful
(sorry for any english mistake)

Juan David


      


More information about the capi-sig mailing list