使用英特尔编译器和 MKL 构建 Numpy - CentOS 7

Building Numpy with Intel Compilers and MKL - CentOS 7

目前我正在尝试使用 CentOS 7 上的英特尔编译器为英特尔的 MKL 构建 Numpy-1.9.1。我安装了英特尔 Parallel XE Studio 2015 C++ 和 Linux 的 Fortran,在我的终端中我可以同时使用 'icc' 和 'ifort' 命令,它们都没有问题。我也有 运行:

$ source /opt/intel/composer_xe_2015/bin/compilervars.sh intel64

根据 Intel 网页上的这个指南来做我想做的事情:https://software.intel.com/en-us/articles/numpyscipy-with-intel-mkl,我尝试使用这个命令构建 numpy:

$ sudo python setup.py config --compiler=intelem build_clib --compiler=intelem build_ext --compiler=intelem install

生成的消息是:

Running from numpy source directory.
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'test_suite'
  warnings.warn(msg)
non-existing path in 'numpy/f2py': 'docs'
non-existing path in 'numpy/f2py': 'f2py.1'
F2PY Version 2
blas_opt_info:
blas_mkl_info:
  FOUND:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/composer_xe_2015/mkl/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/composer_xe_2015/mkl/include']

  FOUND:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/composer_xe_2015/mkl/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/composer_xe_2015/mkl/include']

non-existing path in 'numpy/lib': 'benchmarks'
lapack_opt_info:
openblas_lapack_info:
  libraries openblas not found in ['/usr/local/lib64', '/usr/local/lib', '/usr/lib64', '/usr/lib', '/usr/lib/']
  NOT AVAILABLE

lapack_mkl_info:
mkl_info:
  FOUND:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/composer_xe_2015/mkl/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/composer_xe_2015/mkl/include']

  FOUND:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/composer_xe_2015/mkl/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/composer_xe_2015/mkl/include']

  FOUND:
    libraries = ['mkl_rt', 'pthread']
    library_dirs = ['/opt/intel/composer_xe_2015/mkl/lib/intel64']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/opt/intel/composer_xe_2015/mkl/include']

/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'define_macros'
  warnings.warn(msg)
running config
running build_clib
running build_src
build_src
building py_modules sources
building library "npymath" sources
Could not locate executable icc
Could not locate executable ecc
customize Gnu95FCompiler
Found executable /usr/bin/gfortran
customize Gnu95FCompiler
customize Gnu95FCompiler using config
C compiler: icc -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -xhost

compile options: '-Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -Inumpy/core/include -I/usr/include/python2.7 -c'
icc: _configtest.c
sh: icc: command not found
sh: icc: command not found
failure.
removing: _configtest.c _configtest.o
Traceback (most recent call last):
  File "setup.py", line 251, in <module>
    setup_package()
  File "setup.py", line 243, in setup_package
    setup(**metadata)
  File "/home/myles/Downloads/numpy-1.9.1/numpy/distutils/core.py", line 169, in setup
    return old_setup(**new_attr)
  File "/usr/lib64/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/myles/Downloads/numpy-1.9.1/numpy/distutils/command/build_clib.py", line 63, in run
    self.run_command('build_src')
  File "/usr/lib64/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/myles/Downloads/numpy-1.9.1/numpy/distutils/command/build_src.py", line 153, in run
    self.build_sources()
  File "/home/myles/Downloads/numpy-1.9.1/numpy/distutils/command/build_src.py", line 164, in build_sources
    self.build_library_sources(*libname_info)
  File "/home/myles/Downloads/numpy-1.9.1/numpy/distutils/command/build_src.py", line 299, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
  File "/home/myles/Downloads/numpy-1.9.1/numpy/distutils/command/build_src.py", line 386, in generate_sources
    source = func(extension, build_dir)
  File "numpy/core/setup.py", line 686, in get_mathlib_info
    raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program

我使用 CentOS 7 作为我的操作系统。似乎由于某种原因构建脚本找不到 icc。

我需要使用 Intel 编译器构建 numpy,因为根据我收集到的信息,我需要使用 Intel 编译器和 Intel MKL 构建 numpy,以便自动卸载到 Xeon Phi 可用。如果有人构建了 numpy 以自动卸载到 Xeon Phi,或者只是在这个问题上使用 Intel 编译器构建了 numpy,我将不胜感激修复此错误的意见。

在 Unix/Linux 系统上,sudo 命令(SuperUser DO) 被设置为使用为 root 用户定义的环境变量,而不是 运行 执行该命令的用户。如果您在非标准位置安装程序,这可能会导致问题,然后需要 运行 它具有超级用户权限。例如,在 OS X 系统上(在 BSD Unix 上 运行),/usr/local/bin 默认情况下不包含在 PATH 环境变量中。您可以将您的用户帐户设置为将此目录包含在您的 PATH 中,但是如果您尝试将 sudo 与其中的程序一起使用,它将找不到,除非您修改 root的环境(或系统环境)在 PATH.

中包含 /usr/local/bin

这可能是您遇到问题的原因。 iccifort/opt/intel/bin and/or /opt/intel/composer_xe_2015/bin 中的 (IIRC) 中(一个可能与另一个链接),并且您至少添加了一个这些目录到您的 $PATH 环境变量,但是当使用 sudo 执行构建命令时,找不到程序。要解决此问题,请不要使用 sudo 进行构建。首先,要清除任何剩余的临时文件,运行

sudo make clean

然后 运行

python setup.py config --compiler=intelem 

并确认一切设置正确。接下来,运行

python setup.py build_clib --compiler=intelem build_ext --compiler=intelem

构建一切。如果成功且没有错误,可选择 运行

python setup.py test

(我认为您不需要此目标的 compiler 参数)来验证构建,然后 运行

sudo python setup.py install

将所有内容安装到系统的 site-packages 目录中。此处需要 sudo,因为 site-packagesroot 所有。