[Cython] OpenMP support
markflorisson88 at gmail.com
Tue Mar 8 17:10:20 CET 2011
On 8 March 2011 16:10, Sturla Molden <sturla at molden.no> wrote:
> Den 08.03.2011 11:34, skrev mark florisson:
>> However, considering that OpenMP has quite a few constructs,
> No, OpenMP has very few contructs, not quite a few. And most of them are not
> needed, nor wanted, because the functionality is covered by the Python
> language (such as scoping rules).
> I.e. we do not need -- nor want -- things like private, shared, firstprivate
> or lastprivate in Cython, because the scope of variables inside closures are
> already covered by Python syntax. OpenMP is just making up for the lack of
> closures in C here.
> We don't need to implement #pragma omp critical, because we have
> We don't need to implement #pragma omp atomic, because we have the GIL (as
> well as OS and compiler support for atomic operations).
> #pragma omp barrier becomes a butterfly of threading.Event.
But how useful is it to parallelize CPU-bound code while holding GIL?
Or do you mean to run the CPU-intensive section in a 'with nogil'
block and when you need to do locking, or when you need to deal with
Python objects you reaqcuire the GIL?
The point of OpenMP is convenience, i.e., having your CPU-bound
algorithm parallelized with just a few annotations. If you rewrite
your code as a closure for say, a parallel for construct, you'd have
to call your closure at every iteration. And then you still have to
take care of any reduction and corresponding synchronization (unless
you have the GIL already). And then there's still the issue of
ordered, single and master constructs.
Of course, using threads manually is always possible, it's just not
> There is not really much left to implement. We need a decorator to launch
> closures as parallel blocks (trivial) and classes to do static, dynamic and
> guided load balancing (trivial as well).
> It is hardly a page of code to write, just a handful of small classes, once
> Cython has closures working properly.
What do you mean with proper closures? We have closure support right now.
There is a lot of whitespace at the end of most of your messages.
> cython-devel mailing list
> cython-devel at python.org
More information about the cython-devel