from numpy import inf, array, int32, float64, amin, full
import numba as nb
from numba import prange
@jit(nopython=True, parallel=True)
def _iterate_parallel(
capy_idxs, indptr, indices, # read only, ndarray[int32]
heat_src, capy, # read only, ndarray[float64]
condc, # read only, ndarray[float64, float64]
temp, # read and write from all threads, ndarray[float64]
dt): # read only float64
has_forced_static = False # should be shared by all threads
tau = full(capy_idxs.size, inf, dtype=float64) # should be shared by all threads
# the idea is to run only the following loop in parallel,
# therefore use the prange function
for c in prange(capy_idxs.size):
# i, sum_condc, ap, b and j should be private inside prange
i = capy_idxs[c]
sum_condc = 0.
ap = heat_src[i]
# is this loop parallelized in the context of the loop above?
for j in range(indptr[i], indptr[i + 1]):
# removed the += reduction operator for the two lines below
# because these are no reductions in the context of the prange loop
sum_condc = sum_condc + condc[i, indices[j]]
ap = ap + condc[i, indices[j]] * temp[indices[j]]
if sum_condc == 0:
continue
if capy[i] == 0.:
b = 1.
else:
tau[c] = capy[i] / sum_condc
b = dt / tau[c]
if b > 1.:
b = 1.
has_forced_static = True
temp[i] = temp[i] - b*(temp[i] - ap/sum_condc)
# temp array is also changed, must it also be returned?
return amin(tau), has_forced_static