[Numpy-discussion] Proposed fix for MKL and dynamic loading

Dag Sverre Seljebotn dagss@student.matnat.uio...
Thu Jan 21 06:29:50 CST 2010


Matthieu Brucher wrote:
>> try:
>>    import sys
>>    import ctypes
>>    _old_rtld = sys.getdlopenflags()
>>    sys.setdlopenflags(_old_rtld|ctypes.RTLD_GLOBAL)
>>    from numpy.linalg import lapack_lite
>> finally:
>>    sys.setdlopenflags(_old_rtld)
>>    del sys; del ctypes; del _old_rtld
>>     
>
> This also applies to scipy code that relies on BLAS as well. Lisandra
> Dalcin gave me a tip that is close to this one some months ago
> (http://matt.eifelle.com/2008/11/03/i-used-the-latest-mkl-with-numpy-and.../).
> The best official solution is to statically link against the MKL with
> Python.
>
>   
IIUC, it should be enough to load the .so-s in GLOBAL mode once. So it 
is probably enough to ensure NumPy is patched in a way so that SciPy 
loads NumPy which loads the .so-s in GLOBAL mode, so that a seperate 
patch for SciPy is not necesarry. (Remains to be tried, I'm moving on to 
building SciPy now.)

As for static linking, do you mean linking MKL into the Python 
interpreter itself? Or statically linking with NumPy?

In the former case....well, even if the above solution is a 
not-officially-supported hack, I'd prefer that to messing with the 
Python build as long as it actually works, which it seems to...requiring 
custom Python builds for MKL support is not something one should do if 
one could avoid it. (I build my own Python anyway, but I suppose many 
potential NumPy/MKL users don't.)

Dag Sverre




More information about the NumPy-Discussion mailing list