[Cython] Cython 0.15rc2 and parallelization issue

mark florisson markflorisson88 at gmail.com
Wed Aug 3 14:57:33 CEST 2011


On 3 August 2011 14:33, Francesc Alted <faltet at pytables.org> wrote:
> Sure.  And I'm seeing a good speed-up on my 2-core machine indeed:
>
> Without parallel loop:
>
> real    0m0.923s
> user    0m0.875s
> sys     0m0.045s
>
> With parallel loop:
>
> real    0m0.544s
> user    0m0.876s
> sys     0m0.045s
>
> Which is pretty awesome, given the simplicity of Cython parallel
> implementation :)
>
> Thanks a lot Mark!
>

Glad you like it, nice speedup!

> 2011/8/3, mark florisson <markflorisson88 at gmail.com>:
>> On 3 August 2011 14:18, Francesc Alted <faltet at pytables.org> wrote:
>>> Hi,
>>>
>>> I'm trying to take advantage of the exciting new parallelizing
>>> capabilities recently introduced in forthcoming 0.15 version, but I'm
>>> having a small difficulty.  When I try to compile a small demo routing
>>> (attached), I'm getting this error:
>>>
>>> $ cython -a mandel.pyx
>>>
>>> Error compiling Cython file:
>>> ------------------------------------------------------------
>>> ...
>>>    for pix in prange(num_pixels, nogil=True, schedule="dynamic"):
>>>        x = pix % width
>>>        y = pix // width
>>>        cr = begin_r + (x * span_r / (width + 1.0))
>>>        ci = begin_i + (y * span_i / (height + 1.0))
>>>        n = MandelbrotCalculate(cr, ci, maxiter)
>>>                              ^
>>> ------------------------------------------------------------
>>>
>>> mandel.pyx:50:31: Calling gil-requiring function not allowed without gil
>>>
>>> While trying to figure out why MandelbrotCalculate does require GIL, I
>>> replaced the "for  prange", by a trivial "for range", and the
>>> annotated HTML source reveals that the only line in (light) yellow in
>>> this function is
>>>
>>>    return n
>>>
>>> which is translated as:
>>>
>>>  /* "mandel.pyx":22
>>>  *         ti = 2*zr*zi + ci
>>>  *         zr, zi = tr, ti
>>>  *     return n             # <<<<<<<<<<<<<<
>>>  *
>>>  * @cython.boundscheck(False)
>>>  */
>>>  __pyx_r = __pyx_v_n;
>>>  goto __pyx_L0;
>>>
>>>  __pyx_r = 0;
>>>  __pyx_L0:;
>>>  __Pyx_RefNannyFinishContext();
>>>  return __pyx_r;
>>> }
>>>
>>> My guess is that this __Pyx_RefNannyFinishContext() call is preventing
>>> to call the routing from the parallel loop.  Is that a bug, a
>>> limitation of current implementation or it is just that I'm missing
>>> something?
>>>
>>> Thanks,
>>>
>>> --
>>> Francesc Alted
>>>
>>> _______________________________________________
>>> cython-devel mailing list
>>> cython-devel at python.org
>>> http://mail.python.org/mailman/listinfo/cython-devel
>>>
>>>
>>
>> Hey Francesc!
>>
>> The problem is that you didn't declare MandelbrotCalculate 'nogil'.
>> You have to write
>>
>>     cdef long MandelbrotCalculate(double cr, double ci, long maxiter) nogil:
>>         ...
>>
>> That's all, and it will compile :)
>>
>> Cheers,
>>
>> Mark
>> _______________________________________________
>> cython-devel mailing list
>> cython-devel at python.org
>> http://mail.python.org/mailman/listinfo/cython-devel
>>
>
>
> --
> Francesc Alted
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>


More information about the cython-devel mailing list