[Cython] CEP: prange for parallel loops

Dag Sverre Seljebotn d.s.seljebotn at astro.uio.no
Tue Apr 5 17:02:26 CEST 2011

On 04/05/2011 04:58 PM, Dag Sverre Seljebotn wrote:
> On 04/05/2011 04:53 PM, Robert Bradshaw wrote:
>> On Tue, Apr 5, 2011 at 3:51 AM, Stefan Behnel<stefan_ml at behnel.de>  
>> wrote:
>>> mark florisson, 04.04.2011 21:26:
>>>> For clarity, I'll add an example:
>>>> def f(np.ndarray[double] x, double alpha):
>>>>      cdef double s = 0
>>>>      cdef double tmp = 2
>>>>      cdef double other = 6.6
>>>>      with nogil:
>>>>          for i in prange(x.shape[0]):
>>>>              # reading 'tmp' makes it firstprivate in addition to
>>>> lastprivate
>>>>              # 'other' is only ever read, so it's shared
>>>>              printf("%lf %lf %lf\n", tmp, s, other)
>>> So, adding a printf() to your code can change the semantics of your
>>> variables? That sounds like a really bad design to me.
>> That's what I was thinking. Basically, if you do an inlace operation,
>> then it's a reduction variable, no matter what else you do to it
>> (including possibly a direct assignment, though we could make that a
>> compile-time error).
> -1, I think that's too obscure. Not being able to use inplace 
> operators for certain variables will be at the very least be nagging.
> I think we need to explicitly declare something. Either a simple 
> prange(..., reduce="s:+"), or all-out declaration of thread-local 
> variables.

Sorry: prange(..., reduce="s"), or perhaps &s or cython.address(s). The 
+ is of course still specified in code.

Dag Sverre

More information about the cython-devel mailing list