有没有办法为基本的numpy操作启用自动并行化,比如数组的元素乘法和基本的numpy函数,如np.sum和np.average?
我知道blas / lapack函数是可能的,正如此线程中针对scipy.linalg.solve所讨论的那样:
Is it possible to know which SciPy / NumPy functions run on multiple cores?
我设法通过MKL本地并行运行此代码:
import numpy
def test():
n = 5000
data = numpy.random.random((n, n))
result = numpy.linalg.inv(data)
test();
但我需要同时运行这样的东西:
N = 1024
A = np.zeros((N,N,N),dtype='float32')
B = np.zeros((N,N,N),dtype='float32')
C = np.zeros((N,N,N),dtype='float32')
A[:,:,:] = 1
B[:,:,:] = 2
# this is the part I want parallel
C[:,:,:] = A[:,:,:]*B[:,:,:]
# also this:
avgC = np.average(C)
否则,对这些目标操作进行并列化的最简单方法是什么?
答案 0 :(得分:0)
有几个automatic parallelization tools for Python,但我不确定它们是否与Numpy兼容。可以通过将Python-to-C++ translator与automatic parallelization tool for C++组合来并行化这些操作。