I am using this awesome numba package for some experiments I have. However, I am looking at parallelizing some certain processes, and I want to know whether a certain code snippets yield a race condition when I parallelize it (this is a bit of a noob question).
# original_vectors is (n,d) # new_vectors is (m, d) # index_vectors is (n, k) where every entry is and index in new_vectors @njit(nopython=True, parallel=True, target="cpu") def generate_vectors(original_vectors, new_vectors, indexes): # Loop through the walks for ii in prange(indexes.shape): for jj in prange(indexes.shape): new_vectors[indexes[ii, jj]] += original_vectors[ii] return original_vectors
According to this tutorial, using indexes of a vector in a parallel for-loop can risk yielding a race condition.
However, when I test this, it yields the same output vector, no matter if I use parallel and prange or not. However, I manage to parallelize and speed it up by a factor of 2, so it would be nice if it did not yield a race condition.