如何使用启用的OpenMP指令重新编译Numpy [英] How to recompile Numpy with enabled OpenMP directives

查看:160
本文介绍了如何使用启用的OpenMP指令重新编译Numpy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Multiprocessing.Pool makes Numpy matrix multiplication slower 的答案中,答案的作者在第二段中建议使用启用的OpenMP重新编译Numpy.指令. 所以我的问题是:

In this answer to Multiprocessing.Pool makes Numpy matrix multiplication slower the author of the answer recommends in the second paragraph to recompile Numpy with enabled OpenMP directives. So my questions are:

  1. 您如何做到的?
  2. 什么是负面副作用?
  3. 您会建议吗?
  1. How do you do that?
  2. What could be negative side effects?
  3. Would you recommend that?

我在下面的帖子 OpenMP和Python 中进行搜索,答案解释了为什么没有用由于GIL,因此适用于一般Python中的OpenMP.但是我认为Numpy是另外一个问题.

Searching SO I found following post OpenMP and Python, where the answers explain why there is no use for OpenMP in general Python due to the GIL. But I assume Numpy is a different issue.

推荐答案

虽然Python代码本身几乎无法从并行运行中受益,但NumPy并不是用Python编写的.实际上,它是Python的包装器,围绕着一些非常完善的数值计算库和其他数值算法,它们均以诸如Fortran和C的编译语言实现.这些库中的某些已经采用并行多线程版本(如Intel MKL和ATLAS,当用于在NumPy中提供BLAS和LAPACK实现.

While Python code itself hardly benefits from running in parallel, NumPy is not written in Python. It is in fact a pythonistic wrapper around some very well established numerical computational libraries and other numerical algorithms, both implemented in compiled languages like Fortran and C. Some of these libraries already come in parallel multithreaded versions (like Intel MKL and ATLAS, when used to provide BLAS and LAPACK implementations in NumPy).

这个想法是,在NumPy程序中,仅应将Python代码用于驱动计算,而所有繁重的工作都应在C或Fortran后端中完成.如果您的程序没有在NumPy例程中花费大部分运行时间,请阿姆达尔定律会阻止您使用并行NumPy获得合理的加速.

The idea is that in NumPy programs the Python code should only be used to drive the computations, while all the heavy lifting should be done in the C or Fortran backends. If your program doesn't spend most of its run time inside NumPy routines, then Amdahl's law will prevent you from getting a reasonable speed-up with parallel NumPy.

为了使NumPy支持OpenMP,必须具有启用了OpenMP的C编译器.如今,大多数C编译器都支持OpenMP,其中包括GCC,Intel C编译器,Oracle C编译器,甚至Microsoft Visual C编译器(尽管它停留在古老的OpenMP版本中).阅读安装手册以获取详细说明.

In order to get NumPy to support OpenMP, you must have an OpenMP-enabled C compiler. Most C compilers nowadays support OpenMP and this includes GCC, Intel C Compiler, Oracle C Compiler, and even Microsoft Visual C Compiler (although it is stuck at an ancient OpenMP version). Read the Installation Manual for detailed instructions.

这篇关于如何使用启用的OpenMP指令重新编译Numpy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆