[Cython] OpenMP support

Sturla Molden sturla at molden.no
Tue Mar 8 20:18:10 CET 2011

Den 08.03.2011 18:50, skrev Stefan Behnel:
> Note that the queue is only needed to tell the thread what to work on. 
> A lot of things can be shared over the closure. So the queue may not 
> even be required in many cases.

Instead of putting a "#pragma omp parallel for" over the for loop, we 
put the for-loop inside a closure. That is about the same amount of 
extra code, positioned similarly in the code, achieving the same thing.

Private variables are passed as calling arguments to the closure, shared 
variables are shared over the closure. That is Python syntax, so we 
don't need specifiers for 'private' and 'shared' like OpenMP.

We still need sychonization and scheduling primitives similar to those 
in OpenMP. For example a special 'range' function that will share the 
workload of a for loop. But this is not a major programming task.

What I am trying to say is that the major argument for OpenMP in C and 
Fortran is lack of closures. That does not apply to Cython anymore (as I 
happily learned today). That is why I think this is a library and not a 
compiler issue.

I'll make an example on the wiki when I get som spare time. Possibly 
with an OpenMP example to show the similarty. One really has to look at 
it side-by-side to see that it's the same.

The same arguments holds for Apple's GCD as well. GCD makes the closure 
semantics explicit by an extension to objective-C.

We need to discourage Java inspired inheritance from threading.Thread, 
and encourage closures instead. And some very clear examples :-)


More information about the cython-devel mailing list