我在ArchLinux
上运行,我的python版本为2.7.8
,并安装了BLAS
和LAPACK
:
% pacman -Qs blas; pacman -Qs lapack
local/blas 3.5.0-1
Basic Linear Algebra Subprograms
local/lapack 3.5.0-1
Linear Algebra PACKage
通过sudo pip2 install numpy
安装了Numpy,它确认它同时看到了BLAS
和LAPACK
:
>>> numpy.show_config()
blas_info:
libraries = ['blas']
library_dirs = ['/usr/lib64']
language = f77
lapack_info:
libraries = ['lapack']
library_dirs = ['/usr/lib64']
language = f77
atlas_threads_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['blas']
library_dirs = ['/usr/lib64']
language = f77
define_macros = [('NO_ATLAS_INFO', 1)]
atlas_blas_threads_info:
NOT AVAILABLE
openblas_info:
NOT AVAILABLE
lapack_opt_info:
libraries = ['lapack', 'blas']
library_dirs = ['/usr/lib64']
language = f77
define_macros = [('NO_ATLAS_INFO', 1)]
openblas_lapack_info:
NOT AVAILABLE
atlas_info:
NOT AVAILABLE
lapack_mkl_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
atlas_blas_info:
NOT AVAILABLE
mkl_info:
NOT AVAILABLE
然而我对np.dot
操作的速度测试超过30秒,当我知道在类似的机器上它在10秒内运行良好。如何解决速度问题?在使用BLAS
和LAPACK
支持安装numpy时,我是否遗漏了一些内容?
答案 0 :(得分:6)
好的,这是整个故事。首先,初始设置很慢,因为BLAS
是参考实现,其设计不是很快。我再说一遍,截至今天,ArchLinux Extra存储库中的包blas
是参考实现。有关详细信息,请参阅Presentation
部分here。
其次,有BLAS
的优化版本(实际上有很多版本:ATLAS,OpenBlas,Goto BLAS,MKL等等,毫无疑问)。它们安装起来相当棘手。我最终安装了OpenBlas,这是在ArchLinux上逐步完成的概述:
openblas-lapack
package from the AUR python2-numpy-openblas
package from the AUR据我所知,它与python2-numpy
配置文件的普通site.cfg
包不同,后者指示numpy
为搜索我们在步骤1中安装的openblas
库。这些动作为我解决了问题,速度现在好多了 - 我在问题中提到的测试时间不到1秒。 numpy显示它已经用openblas编译:
>>> np.show_config()
lapack_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib']
language = f77
blas_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib']
language = f77
openblas_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib']
language = f77
openblas_lapack_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/lib']
language = f77
blas_mkl_info:
NOT AVAILABLE
我认为为openblas
设置numpy
导向python3
的过程看起来非常相似。
答案 1 :(得分:0)
我的建议是从源代码构建'numpy'并将其与BLAS和LAPACK链接。