用于Python的Parfor [英] Parfor for Python

查看:192
本文介绍了用于Python的Parfor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找MATLAB的Python for parfor(Scipy,Numpy)的确切答案.

I am looking for a definitive answer to MATLAB's parfor for Python (Scipy, Numpy).

有没有类似于parfor的解决方案?如果没有,创建一个副本的复杂性是什么?

Is there a solution similar to parfor? If not, what is the complication for creating one?

更新:这是我需要加快速度的典型数值计算代码

UPDATE: Here is a typical numerical computation code that I need speeding up

import numpy as np

N = 2000
output = np.zeros([N,N])
for i in range(N):
    for j in range(N):
        output[i,j] = HeavyComputationThatIsThreadSafe(i,j)

繁重的计算功能的一个示例是:

An example of a heavy computation function is:

import scipy.optimize

def HeavyComputationThatIsThreadSafe(i,j):
    n = i * j

    return scipy.optimize.anneal(lambda x: np.sum((x-np.arange(n)**2)), np.random.random((n,1)))[0][0,0]

推荐答案

有许多用于并行计算的Python框架.我最喜欢的一个是 IPython ,但是我对其他任何一个都不了解.在IPython中,parfor的一个类似物是client.MultiEngineClient.map()有关快速简便的并行性的文档.

There are many Python frameworks for parallel computing. The one I happen to like most is IPython, but I don't know too much about any of the others. In IPython, one analogue to parfor would be client.MultiEngineClient.map() or some of the other constructs in the documentation on quick and easy parallelism.

这篇关于用于Python的Parfor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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