[Cython] Nested prange loops - (was: [cython-users] Converting to Python objects with nogil (inside prange for loop))

Stefan Behnel stefan_ml at behnel.de
Fri Jul 15 03:45:37 EDT 2022


Hi,

nested prange loops seem to be a common gotcha for users. I can't say if 
there is ever a reason to do this, but at least I can't think of any. For 
me, this sounds like we should turn it into a compile time error – unless 
someone can think of a use case? Even in that case, I'd still emit a 
warning since it seems so unlikely to be intended.

Please reply to the cython-users list to facilitate user feedback.

Stefan



-------- Forwarded Message --------
Subject: Re: [cython-users] Converting to Python objects with nogil (inside 
prange for loop)
Date: Fri, 15 Jul 2022 07:43:26 +0100


> with nogil, parallel():
>   for i in prange(N):
>     for j in prange(km.BatchSize):

You usually only want one loop in a set of nested loops to be prange. 
Typically the outer loop, but in this case it might be easier to 
parallelize the inner loop.



More information about the cython-devel mailing list