简体   繁体   English

多处理python

[英]multiprocessing python

What are the simplest way to use all cores off a computer for a python program ? 使用计算机上的所有内核进行python程序的最简单方法是什么? In particular, I would want to parallelize a numpy function (which already exists). 特别是,我想要并行化一个numpy函数(已经存在)。 Is there something like openmp under fortran in python ? 在python中有没有像fortmp一样的openmp?

Check out the multiprocessing library. 查看多处理库。 It even allows to spread work across multiple computers. 它甚至允许在多台计算机上传播工作。

It depends on what you want to do and how numpy is compiled on your machine (in some cases, some multicore use will be automatic). 这取决于你想要做什么以及如何在你的机器上编译numpy(在某些情况下,一些多核使用将是自动的)。 See this page for details. 有关详情,请参阅此页面

It may or may not fit to your specific problem you want to solve, but I personally find the ipython shell's parallel infrastructure quite attractive. 它可能适合您想要解决的特定问题,也可能不适合,但我个人认为ipython shell的并行基础设施非常有吸引力。 It is relatively easy to set up an ipcluster on localhost (see in the manual ). 在localhost上设置ipcluster相对容易(参见手册 )。

You can wrap your function you wish to evaluate into a @parallel decorator for example and its evaluation will be distributed among many cores (see the Quick and easy parallelism section of the manual) 例如,您可以将要评估的函数包装到@parallel装饰器中,并将其评估分布在多个核心中(请参阅本手册的快速简单并行部分)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM