Parfor for Python

前端 未结 8 1391
死守一世寂寞
死守一世寂寞 2020-12-07 17:46

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

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

8条回答
  •  无人及你
    2020-12-07 18:12

    I tried all solutions here, but found that the simplest way and closest equivalent to matlabs parfor is numba's prange.

    Essentially you change a single letter in your loop, range to prange:

    from numba import autojit, prange
    
    @autojit
    def parallel_sum(A):
        sum = 0.0
        for i in prange(A.shape[0]):
            sum += A[i]
    
        return sum
    

提交回复
热议问题