[Cython] OpenMP support

Stefan Behnel stefan_ml at behnel.de
Fri Mar 11 12:43:30 CET 2011

Sturla Molden, 11.03.2011 12:13:
> OpenMP is a specification, not a particular implementation. Implementation
> for Cython should either be compiler pragmas or a library.
> I'd like it to be a library, as it should also be usable from Python. I
> have made some progress on the library route, depending on Cython's closures.
> nogil makes things feel a bit awkward, though.
> We could for example imagine code like this:
> with openmp.ordered(i):
>     <suite>
> Context managers are forbidden in nogil AFAIK. So we end up with ugly hacks
> like this:
> with nogil:
>     if openmp._ordered(i): # always returns 1, but will synchronize
>         <suite>
> Would it be possible to:
> - Make context managers that are allowed without the GIL? We don't need to
> worry about exceptions, but it should be possible to short-circuit from
> __enter__ to __exit__.

The two special methods are Python methods. There is no way to call them 
without holding the GIL. If we wanted to enable something like a context 
manager inside of a nogil block, it would necessarily be a different protocol.

> - Have cpdefs that are callable without the GIL?

"cpdef" functions are meant to be overridable from Python code, so, no, you 
cannot call them from within a nogil block as they may actually have been 

What's your use actual case for this?


More information about the cython-devel mailing list