Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
parallel.prange loops producing random results #2316
This was originally found by @AshKelly in the context of his GSOC project with yt.
Take a look at this repo: https://github.com/ngoldbaum/cython-issue
You can build the .pyx file with
If you're on a machine with OpenMP support (e.g. on Linux, not MacOS), you'll see that
cimport numpy as np import numpy as np cimport cython from cython.parallel import prange def fun_sum(): cdef np.float64_t[:] result = np.zeros(1) cdef int j cdef np.float64_t a = 3.0 with nogil: for j in prange(0, 10000): result += a + j return np.array(result)
referenced this issue
Jul 16, 2018
@scoder so @AshKelly has come up with a way for cython to generate code that avoids the race condition. It seems cython is incorrectly not marking the array as a parallel reduction target. See the description in ngoldbaum/cython-issue#1 for details.
Unfortunately it looks like array reductions are only supported in relatively recent compilers (gcc 6 or newer, or any compiler that implements OpenMP 4.5 or newer). Out of curiosity what is the minimum supported OpenMP version for cython?