title: How to determine if numba's prange actually works correctly?
body: <p>In another Q+A (<a href="https://stackoverflow.com/q/54208023/5393381">Can I perform dynamic cumsum of rows in pandas?</a>) I made a comment regarding the correctness of using <code>prange</code> about this code (of <a href="https://stackoverflow.com/a/54208168/5393381">this answer</a>):</p>
  
  <pre><code>from numba import njit, prange
  
  @njit
  def dynamic_cumsum(seq, index, max_value):
      cumsum = []
      running = 0
      for i in prange(len(seq)):
          if running &gt; max_value:
              cumsum.append([index[i], running])
              running = 0
          running += seq[i] 
      cumsum.append([index[-1], running])
  
      return cumsum
  </code></pre>
  
  <p>The comment was:</p>
  
  <blockquote>
    <p>I wouldn't recommend parallelizing a loop that isn't pure. In this case the <code>running</code> variable makes it impure. There are 4 possible outcomes: (1)numba decides that it cannot parallelize it and just process the loop as if it was <code>cumsum</code> instead of <code>prange</code> (2)it can lift the variable outside the loop and use parallelization on the remainder (3)numba incorrectly inserts synchronization between the parallel executions and the result may be bogus (4)numba inserts the necessary synchronizations around running which may impose more overhead than you gain by parallelizing it in the first place</p>
  </blockquote>
  
  <p>And the later addition:</p>
  
  <blockquote>
    <p>Of course both the <code>running</code> and <code>cumsum</code> variable make the loop "impure", not just the running variable as stated in the previous comment</p>
  </blockquote>
  
  <p>Then I was asked: </p>
  
  <blockquote>
    <p>This might sound like a silly question, but how can I figure out which of the 4 things it did and improve it? I would really like to become better with numba! </p>
  </blockquote>
  
  <p>Given that it could be useful for future readers I decided to create a self-answered Q+A here. Spoiler: I cannot really answer the question which of the 4 outcomes is produced (or if numba produces a totally different outcome) so I highly encourage other answers.</p>