【问题标题】:Cython prange fails with Fatal Python error: PyThreadState_Get: no current threadCython prange 因致命 Python 错误而失败:PyThreadState_Get:没有当前线程
【发布时间】:2017-02-09 08:50:51
【问题描述】:

我正在尝试使用 prange 并行化循环:

cdef fun(double [::1] someData)) nogil:
    #direct call to a external c function
    C_function(&someData[0])

#....
def parallelEvaluate(np.ndarray[np.double_t] largerArray):
    #....
    cdef np.ndarray[np.double_t] array
    cdef np.ndarray[np.int] arbitraryIndices
    for n in prange(loopLength, nogil=true):
        with gil:
            arbitraryIndices = # ... indices dependent on n
            array = np.copy( largerArray[ arbitraryIndices]  ) # copy of a non cont. array to the cont. 'array'
        fun(array)

但是,这失败了: 致命的 Python 错误:PyThreadState_Get:没有当前线程

这种行为的原因是什么?

谢谢!

【问题讨论】:

标签: multithreading parallel-processing cython


【解决方案1】:

好吧,想通了:

从 np.ndarray 的隐式转换不起作用;我用一个额外的 memoryview 切片解决了它。

【讨论】:

    猜你喜欢
    • 2017-06-08
    • 1970-01-01
    • 2018-06-15
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    相关资源
    最近更新 更多