parallel.futures.ProcessPoolExecutor非常慢的并行化python

时间:2019-07-16 15:55:33

标签: python numpy parallel-processing concurrent.futures

我正在尝试并行化python中的一个简单函数,如下所示:

import numpy as np
import math
import concurrent.futures

def f(x):
    return x * math.sin(x) + x * x * math.cos(x)

xs = np.random.normal(0, 1, 100000)

#This takes about a second
ans1 = map(f, xs)

#This ran about 30 minutes before I gave up
with concurrent.futures.ProcessPoolExecutor() as executor:
    ans2 = executor.map(f, xs)

我知道此问题对于并行化而言可能很小,以至于实际上不起作用,但是我希望此问题的并行化版本大约需要几秒钟,而不是30分钟以上。怎么了?

0 个答案:

没有答案