This is simplified representation of the calculation I am trying to do. I know one could vectorize the function and resolve the issue, but I am using the cosine function as a standalone for an involved calculation.
@njit(cache=True,parallel=True)
def freeOH_cosine(cosAngle=np.array([]),is_allCosAngle=False):
_M=cosAngle.shape[0]
Angle=cos2Angle=cos3Angle=np.zeros((_M),dtype=np.float64)
#cos2Angle=np.zeros((_M),dtype=np.float64)
#cos3Angle=np.zeros((_M),dtype=np.float64)
for i in numba.prange(_M):
Angle[i]=np.arccos(cosAngle[i])
if is_allCosAngle:
cos2Angle[i]=cosAngle[i]**2
cos3Angle[i]=cosAngle[i]**3
if is_allCosAngle:
return cosAngle, cos2Angle, cos3Angle, Angle*180.0/np.pi
else:
return cosAngle, np.nan, np.nan, Angle*180.0/np.pi
With what I have read online, writing to an array in parallel can create a whole host of problems. So If we have a case where one needs to extract individual array elements, what should be done in that case? I am sorry if this seems elementary, but it is not exactly clear to me how can one extract granular information from a parallelized calculation if it is unsafe to write in parallel.