Re: [Cython] OpenMP support

2011-03-13 Thread Stefan Behnel
Greg Ewing, 12.03.2011 23:57: mark florisson wrote: Have we ever thought about supporting 'with gil' as an actual statement instead of just as part of a function declaration or definition? That's the way I was originally going to do it in Pyrex, but it turned out to be problematic, because th

Re: [Cython] OpenMP support

2011-03-12 Thread Greg Ewing
mark florisson wrote: Have we ever thought about supporting 'with gil' as an actual statement instead of just as part of a function declaration or definition? That's the way I was originally going to do it in Pyrex, but it turned out to be problematic, because there is some setup that gets don

Re: [Cython] OpenMP support

2011-03-12 Thread mark florisson
On 11 March 2011 14:54, Sturla Molden wrote: > Den 11.03.2011 11:42, skrev Matej Laitl: >> >> #pragma omp parallel for private(var1) reduction(+:var2) schedule(guided) >> for i in range(n): >>     do_work(i) >> > I do like this, as it is valid Python and can be turned on/off with a > compiler fla

Re: [Cython] OpenMP support

2011-03-12 Thread mark florisson
On 11 March 2011 12:13, Sturla Molden 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. Implementat

Re: [Cython] OpenMP support

2011-03-12 Thread mark florisson
On 11 March 2011 08:56, Dag Sverre Seljebotn wrote: > On 03/11/2011 08:20 AM, Stefan Behnel wrote: >> >> Robert Bradshaw, 11.03.2011 01:46: >>> >>> On Tue, Mar 8, 2011 at 11:16 AM, Francesc Alted >>>  wrote: A Tuesday 08 March 2011 18:50:15 Stefan Behnel escrigué: > > mark floris

Re: [Cython] OpenMP support

2011-03-12 Thread mark florisson
On 11 March 2011 01:46, Robert Bradshaw wrote: > On Tue, Mar 8, 2011 at 11:16 AM, Francesc Alted wrote: >> A Tuesday 08 March 2011 18:50:15 Stefan Behnel escrigué: >>> mark florisson, 08.03.2011 18:00: >>> > What I meant was that the >>> > wrapper returned by the decorator would have to call the

Re: [Cython] OpenMP support

2011-03-12 Thread Francesc Alted
A Saturday 12 March 2011 02:43:16 Sturla Molden escrigué: > The free C/C++ compiler in Windows SDK supports OpenMP. This is the > system C compiler on Windows. System compiler on Windows? I've never heard defining MSVC like this ;) > OpenMP on GCC is the same on Windows as on any other platform.

Re: [Cython] OpenMP support

2011-03-11 Thread Sturla Molden
The free C/C++ compiler in Windows SDK supports OpenMP. This is the system C compiler on Windows. Visual C++ Express is an IDE for beginners and hobbyists. OpenMP on GCC is the same on Windows as on any other platform. Sturla A Friday 11 March 2011 11:42:26 Matej Laitl escrigué: I'm stro

Re: [Cython] OpenMP support

2011-03-11 Thread Francesc Alted
A Friday 11 March 2011 11:42:26 Matej Laitl escrigué: > I'm strongly for implementing thin and low-level support for OpenMP > at the first place instead of (ab?)using it to implement high-level > threading API. My opinion on this continues to be -1. I'm afraid that difficult access to OpenMP on

Re: [Cython] OpenMP support

2011-03-11 Thread Stefan Behnel
Sturla Molden, 11.03.2011 15:19: Den 11.03.2011 12:43, skrev Stefan Behnel: What's your use actual case for this? Just avoid different syntax inside and outside nogil-blocks. I like this style with openmp.critical: better than what is currently legal with nogil: openmp.critical() if

Re: [Cython] OpenMP support

2011-03-11 Thread Sturla Molden
Den 11.03.2011 12:43, skrev Stefan Behnel: What's your use actual case for this? Just avoid different syntax inside and outside nogil-blocks. I like this style with openmp.critical: better than what is currently legal with nogil: openmp.critical() if 1: openmp.end_criti

Re: [Cython] OpenMP support

2011-03-11 Thread Sturla Molden
Den 11.03.2011 11:42, skrev Matej Laitl: #pragma omp parallel for private(var1) reduction(+:var2) schedule(guided) for i in range(n): do_work(i) I do like this, as it is valid Python and can be turned on/off with a compiler flag to Cython. Issues to warn about: - We cannot jump out of

Re: [Cython] OpenMP support

2011-03-11 Thread Dag Sverre Seljebotn
On 03/11/2011 12:37 PM, Stefan Behnel wrote: Dag Sverre Seljebotn, 11.03.2011 08:56: Basically, I'm +1 to anything that can make me pretend the GIL doesn't exist, even if it comes with a 2x performance hit: Because that will make me write parallell code (which I can't be bothered to do in Cyt

Re: [Cython] OpenMP support

2011-03-11 Thread Stefan Behnel
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 o

Re: [Cython] OpenMP support

2011-03-11 Thread Stefan Behnel
Dag Sverre Seljebotn, 11.03.2011 08:56: Basically, I'm +1 to anything that can make me pretend the GIL doesn't exist, even if it comes with a 2x performance hit: Because that will make me write parallell code (which I can't be bothered to do in Cython currently), and I have 4 cores on the laptop

Re: [Cython] OpenMP support

2011-03-11 Thread Sturla Molden
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 li

Re: [Cython] OpenMP support

2011-03-11 Thread Matej Laitl
> On a slightly higher level, are we just trying to use OpenMP from > Cython, or are we trying to build it into the language? If the former, > it may make sense to stick closer than one might otherwise be tempted > in terms of API to the underlying C to leverage the existing > documentation. A libr

Re: [Cython] OpenMP support

2011-03-11 Thread Dag Sverre Seljebotn
On 03/11/2011 08:20 AM, Stefan Behnel wrote: Robert Bradshaw, 11.03.2011 01:46: On Tue, Mar 8, 2011 at 11:16 AM, Francesc Alted wrote: A Tuesday 08 March 2011 18:50:15 Stefan Behnel escrigué: mark florisson, 08.03.2011 18:00: What I meant was that the wrapper returned by the decorator would

Re: [Cython] OpenMP support

2011-03-10 Thread Stefan Behnel
Robert Bradshaw, 11.03.2011 01:46: On Tue, Mar 8, 2011 at 11:16 AM, Francesc Alted wrote: A Tuesday 08 March 2011 18:50:15 Stefan Behnel escrigué: mark florisson, 08.03.2011 18:00: What I meant was that the wrapper returned by the decorator would have to call the closure for every iteration,

Re: [Cython] OpenMP support

2011-03-10 Thread Robert Bradshaw
On Tue, Mar 8, 2011 at 11:16 AM, Francesc Alted wrote: > A Tuesday 08 March 2011 18:50:15 Stefan Behnel escrigué: >> mark florisson, 08.03.2011 18:00: >> > What I meant was that the >> > wrapper returned by the decorator would have to call the closure >> > for every iteration, which introduces fun

Re: [Cython] OpenMP support

2011-03-09 Thread Francesc Alted
A Tuesday 08 March 2011 18:02:13 Sturla Molden escrigué: > Den 08.03.2011 17:33, skrev mark florisson: > > With OpenMP code, exactly how common are exceptions and error > > handling? > > Error handling is always needed, but OpenMP does not help with this. > > One can use an integer variable as er

Re: [Cython] OpenMP support

2011-03-08 Thread Stefan Behnel
Greg Ewing, 09.03.2011 00:27: Stefan Behnel wrote: You *can* use Python references inside of nogil blocks, even if there's a lot of stuff that you can't do with them, ... But you can access cdef > attributes on them, Strictly speaking it's not even safe to do that, unless you know there's so

Re: [Cython] OpenMP support

2011-03-08 Thread Greg Ewing
Stefan Behnel wrote: You *can* use Python references inside of nogil blocks, even if there's a lot of stuff that you can't do with them, ... But you can access cdef > attributes on them, Strictly speaking it's not even safe to do that, unless you know there's some locking mechanism in effect

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 20:34, skrev Stefan Behnel: ... but that could be put into a builtin Cython library, right? At least a couple of primitives, decorators, helpers, etc. Yes. Sturla ___ cython-devel mailing list cython-devel@python.org http://mail.pyth

Re: [Cython] OpenMP support

2011-03-08 Thread Francesc Alted
A Tuesday 08 March 2011 20:24:51 Sturla Molden escrigué: > Den 08.03.2011 20:13, skrev Francesc Alted: > > And another problem that should be taken in account is that MS > > Visual Studio does not offer OpenMP in the Express edition (the > > free, as in beer, one). > > Which is why one should get

Re: [Cython] OpenMP support

2011-03-08 Thread Stefan Behnel
Sturla Molden, 08.03.2011 20:18: 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. ... but that could be put into a builtin Cython library

Re: [Cython] OpenMP support

2011-03-08 Thread Stefan Behnel
Francesc Alted, 08.03.2011 20:16: A Tuesday 08 March 2011 18:50:15 Stefan Behnel escrigué: mark florisson, 08.03.2011 18:00: What I meant was that the wrapper returned by the decorator would have to call the closure for every iteration, which introduces function call overhead. [...] I guess w

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 20:13, skrev Francesc Alted: And another problem that should be taken in account is that MS Visual Studio does not offer OpenMP in the Express edition (the free, as in beer, one). Which is why one should get the Windows 7 SDK instead :-) As I see this, if we could stick using j

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
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

Re: [Cython] OpenMP support

2011-03-08 Thread Francesc Alted
A Tuesday 08 March 2011 18:50:15 Stefan Behnel escrigué: > mark florisson, 08.03.2011 18:00: > > What I meant was that the > > wrapper returned by the decorator would have to call the closure > > for every iteration, which introduces function call overhead. > > > >[...] > > > > I guess we just have

Re: [Cython] OpenMP support

2011-03-08 Thread Francesc Alted
A Tuesday 08 March 2011 17:38:46 Sturla Molden escrigué: > But should we care if this is implemented with OpenMP or Python > threads? It's just an implementation detail in the library, not > visible to the user. > > Also I am not against OpenMP, I use it all the time in Fortran :-) > > Another pr

Re: [Cython] OpenMP support

2011-03-08 Thread Hoyt Koepke
Apologies for the OT post, but a quick FYI: I've been using openmp with cython pretty extensively, usually wrapped in static inline or template functions in a separate header. However, I've been hindered by a strange bug that seems to appear when python loads gomp, gcc's openmp implementation (htt

Re: [Cython] OpenMP support

2011-03-08 Thread Stefan Behnel
mark florisson, 08.03.2011 18:00: What I meant was that the wrapper returned by the decorator would have to call the closure for every iteration, which introduces function call overhead. [...] I guess we just have to establish what we want to do: do we want to support code with Python objects (an

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 18:00, skrev mark florisson: Sure, that's not what I was hinting at. What I meant was that the wrapper returned by the decorator would have to call the closure for every iteration, which introduces function call overhead. OpenMP does this too, in addition to work-scheduling overh

Re: [Cython] OpenMP support

2011-03-08 Thread Stefan Behnel
Sturla Molden, 08.03.2011 17:50: Den 08.03.2011 17:04, skrev Stefan Behnel: Could you elaborate what you are referring to here? Nothing, except my own ignorance :-) Now that we've settled that... ;) What about writing up a little "parallel computing with Cython closures" tutorial in the Wi

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 17:33, skrev mark florisson: With OpenMP code, exactly how common are exceptions and error handling? Error handling is always needed, but OpenMP does not help with this. One can use an integer variable as error flag, and use an atomic write in case of error. Sturla __

Re: [Cython] OpenMP support

2011-03-08 Thread mark florisson
On 8 March 2011 17:38, Sturla Molden wrote: > Den 08.03.2011 17:10, skrev mark florisson: >> >> 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 d

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 17:04, skrev Stefan Behnel: Could you elaborate what you are referring to here? Nothing, except my own ignorance :-) As for OpenMP I'd like to add that closures in Cython/Python more cleanly map to Apple's "grand central dispatch" than OpenMP. Yet a third way to easy parallel

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 17:10, skrev mark florisson: 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 Python

Re: [Cython] OpenMP support

2011-03-08 Thread mark florisson
On 8 March 2011 16:28, Dag Sverre Seljebotn wrote: > On 03/08/2011 11:34 AM, mark florisson wrote: >> >> I'd like to implement OpenMP support for Cython. Looking at > > Great news! It looks like this will be a topic on the coming workshop, with > Francesc coming as well (but nothing wrong with get

Re: [Cython] OpenMP support

2011-03-08 Thread Stefan Behnel
mark florisson, 08.03.2011 17:10: 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? You don't need the

Re: [Cython] OpenMP support

2011-03-08 Thread mark florisson
On 8 March 2011 16:10, Sturla Molden 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 b

Re: [Cython] OpenMP support

2011-03-08 Thread Stefan Behnel
Sturla Molden, 08.03.2011 16:10: once Cython has closures working properly. Could you elaborate what you are referring to here? Cython does have closure support. Maybe you are missing closures for cdef functions? Or is it block level closures that you want? That could be done as well, just l

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
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.

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Reposting this, seems it got lost in cyber space. Sturla Den 8. mars 2011 kl. 16.10 skrev Sturla Molden : 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

Re: [Cython] OpenMP support

2011-03-08 Thread Dag Sverre Seljebotn
On 03/08/2011 11:34 AM, mark florisson wrote: I'd like to implement OpenMP support for Cython. Looking at Great news! It looks like this will be a topic on the coming workshop, with Francesc coming as well (but nothing wrong with getting started before then). (And please speak up if you are

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 11:34, skrev mark florisson: What do you guys think? Make Cython fully support closures, then we can easily implement our own "OpenMP" using Python threads. No change to the compiler is needed. You might not realise this at first, but OpenMP is just a way of implementing closu

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 11:34, skrev mark florisson: What do you guys think? Make Cython fully support closures, then we can easily implement our own "OpenMP" using Python threads. No change to the compiler is needed. You might not realise this at first, but OpenMP is just a way of implementing closu

Re: [Cython] OpenMP support

2011-03-08 Thread Sturla Molden
Den 08.03.2011 11:34, skrev mark florisson: could be written for i in openmp.prange(..., firstprivate=('a', 'b'), reduction='+:result'): ... How would you deal with name mangling, aliases, unboxing of numpy arrays, etc.? Sturla ___

[Cython] OpenMP support

2011-03-08 Thread mark florisson
I'd like to implement OpenMP support for Cython. Looking at http://wiki.cython.org/enhancements/openmp I agree a close 1:1 mapping would be nice. It would probably make sense to start with support for 'nogil' sections because GIL-holding sections would be hard to deal with considering all the 'goto