I hope to modify a NumPy array element in a parallel computing, by using njit as follows.
def get_indice():
....
return new_indice
@njit()
def myfunction(arr):
for i in prange(100):
indices = get_indice()
arr[indices] += 1
But it seems that modifying the array element is unsafe due to the race condition. So I am thinking to make a list of the indices, and modify the arr later, something like
@njit()
def myfunction(arr):
index_list = []
for i in orange(100):
indices = get_indice()
index_list.append(indices)
arr[index_list] += 1
But the list.append()
is also not safe as stated here. Obviously, I don't mind the order in the list. Is there any way to work around for this problem?