Ipyparallel和numba(jit)

2024-09-30 06:15:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用ipyparallel运行一个代码。但是,由于我的一些函数通过jit。最后在ipython控制台中什么都不做,而且冻结了。举个例子:

import time
import numpy
from numba import jit

from ipyparallel import Client
client = Client()  # create client and direct view to all engines available
dview = client[:]
dview.block = True


with dview.sync_imports():
    import numpy

@jit
def TestingFnc(x):
    a=x[0]
    b=x[1]
    c=x[2]
    Result=0
    for i in range(100000):
        Result = Result + ((a+i)**2 + (b-i)**3) /(c+i)**3
    return numpy.array([Result,1])

d=numpy.array([[0.,0.,0.],[0.,0.,1.],[0.,0.,2]])
Results = dview.map(TestingFnc, d)

如果没有@jit,代码将并行运行。你知道吗


Tags: 函数代码fromimportnumpyclientipythonresult

热门问题