title: Cython prange with function reading from numpy array (memoryview) freezes, why?
body: <p>I have to use the rows of a numpy array sequentially so I am doing that with a loop. I tried adding prange for speed but it ends up freezing. I am most likely doing something wrong, I may be misunderstanding the meaning of a race condition in this context. What can be done to fix the problem or to treat the array rows in parallel fashion correctly? Reproducible code below for IPython cells:</p>
  
  <pre><code>%load_ext cython
  import numpy as np
  </code></pre>
  
  <pre><code>%%cython --compile-args=-fopenmp --link-args=-fopenmp --force
  # if on Windows, replace line above with: %%cython --compile-args=/openmp --link-args=/openmp --force
  
  cimport cython
  from cython.parallel cimport prange
  
  @cython.boundscheck(False)
  @cython.wraparound(False)
  cdef double sum_row(double [:] arr) nogil:
      cdef int i
      cdef int size = arr.shape[0]
      cdef double s = 0
  
      for i in range(size):
          s += arr[i]
  
      return s
  
  @cython.boundscheck(False)
  @cython.wraparound(False)
  cpdef double sum_all_rows(double [:,:] arr) nogil:
      cdef int i
      cdef int n_rows = arr.shape[1] + 1
      cdef double s = 0
  
      for i in range(n_rows):
          s += sum_row(arr[i])
  
      return s
  
  @cython.boundscheck(False)
  @cython.wraparound(False)
  cpdef double sum_all_rows_parallel(double [:,:] arr) nogil:
      cdef int i
      cdef int n_rows = arr.shape[1] + 1
      cdef double s = 0
  
      for i in prange(n_rows):
          s += sum_row(arr[i])
  
      return s
  </code></pre>
  
  <pre><code>X = np.array([[3.14, 2.71, 0.002],
                [0.5, 1, 4.21],
                [0.001, 0.002, 0.003],
                [-0.1, -0.11, -0.12]])
  </code></pre>
  
  <pre><code>%timeit sum_all_rows(X)
  </code></pre>
  
  <p><em>754 ns ± 38.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)</em></p>
  
  <pre><code>sum_all_rows_parallel(X)
  </code></pre>
  
  <p>And it hangs... I stopped it after roughly 5 minutes. I did not observe any increasing memory usage nor CPU usage.</p>
  
  <p>I have used the toy examples of prange before seeing the expected speedups, so I am able to compile properly.</p>
  
  <p>Also, any suggested readings to better understand this kind of issue?</p>
  
  <p>Thank you for your help.</p>