[Cython] OpenMP support

mark florisson markflorisson88 at gmail.com
Sat Mar 12 13:12:26 CET 2011


On 11 March 2011 12:13, Sturla Molden <sturla at molden.no> wrote:
> Den 11.03.2011 01:46, skrev Robert Bradshaw:
>>
>> On a slightly higher level, are we just trying to use OpenMP from
>> Cython, or are we trying to build it into the language?
>
> 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__.
>
> - Have cpdefs that are callable without the GIL?
>
> This would certainly make OpenMP syntax look cleaner.
>
>
> Sturla
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>

The reason I wanted to support OpenMP as a compiler modification is
exactly that you can use Pythonic syntax without actually dealing with
for instance, context managers. You'd just rewrite the WithStatNode in
a Transform. By additionally stubbing the context managers in the
Shadow module you get normal, sequential behaviour when running
directly in the python interpreter (provided that Cython is installed
or the Shadow module is shipped as cython.py).


More information about the cython-devel mailing list