[Numpy-discussion] Use numpy.distutils to build fortran with BLAS

Kyle Mandli kyle.mandli@gmail....
Thu Aug 29 11:38:36 CDT 2013


In the Clawpack projects (specifically the Riemann solvers) we compile
against LAPACK and the BLAS using f2py via the `--link-lapack_opt` flag.
 This does cause some problems in terms of portability though, Aron Ahmadia
might be able to shed some light on this as he has looked into it most
recently.


On Wed, Aug 28, 2013 at 5:08 AM, Matt Hoffman <hoffmanm@cs.ubc.ca> wrote:

> I have some fortran code that I would like to build and make accessible
> from python which needs to call a few BLAS routines. Building it in a
> one-off manner is not a problem, but I can't seem to find a good way to
> distribute it in a way that just works.
>
> So really I'm wondering if there is a "correct" way use numpy.distutils in
> order to link against the same BLAS libraries used by numpy. I'll paste my
> current approach below, but I'm not sure that this is the
> best/most-portable way to do it. (And it certainly breaks on MacOS due to
> the weird way that macs use rpath.)
>
> Anyway my setup contains something like:
>
>     from numpy.distutils.core import setup
>     from numpy.distutils.system_info import get_info, NotFoundError
>     from numpy.distutils.misc_util import Configuration
>
>     sources = ['foo.f']
>     extra_info = {}
>     extra_link_args = []
>
>     try:
>         extra_info = get_info('mkl', 2)
>         extra_link_args = ['-Wl,-rpath,'+path for path in
> extra_info['library_dirs']],
>
>     except NotFoundError:
>         try:
>             extra_info = get_info('blas', 2)
>             extra_link_args = ['-Wl,-rpath,'+path for path in
> extra_info['library_dirs']],
>
>         except NotFoundError:
>             # couldn't find anything. just fall back to building the
> functions we need ourselves.
>             sources += ['ddot.f']
>
>     config = Configuration()
>     config.add_extension(
>         sources=sources,
>         extra_info=extra_info,
>         extra_link_args=extra_link_args
>         )
>     setup(**config.todict())
>
> Thanks!
> -matt
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130829/c8981024/attachment.html 


More information about the NumPy-Discussion mailing list