python并行化for循环

时间:2016-03-03 20:46:47

标签: python mpi python-2.x message-passing mpi4py

我有一个时间密集的代码,我希望并行化以在多个处理器上运行。这甚至可能吗?

import numpy as np
def f_big(A, k, std_A, std_k, mean_A=10, mean_k=0.2, hh=100):
    return ( 1 / (std_A * std_k * 2 * np.pi) ) * A * (hh/50) ** k * np.exp( -1*(k - mean_k)**2 / (2 * std_k **2 ) - (A - mean_A)**2 / (2 * std_A**2))

outer_sum = 0
dk = 0.00001
for k in np.arange(dk,0.4, dk):
    inner_sum = 0
    for A in np.arange(dk, 20, dk):
        inner_sum += dk * f_big(A, k, 1e-5, 1e-5)
    outer_sum += inner_sum * dk

print piter_sum

0 个答案:

没有答案