On 9 October 2011 21:48, Jon Olav Vik <jono...@gmail.com> wrote: > On Sun, Oct 9, 2011 at 9:01 PM, mark florisson > <markflorisso...@gmail.com> wrote: >> On 9 October 2011 19:54, Jon Olav Vik <jono...@gmail.com> wrote: >>> Personally, I think I'd prefer context managers as a very >>> readable way to deal with parallelism >> >> Yeah it makes a lot of sense for mutual exclusion, but 'master' really >> means "only the master thread executes this peace of code, even though >> other threads encounter the same code", which is more akin to 'if' >> than 'with'. > > I see your point. However, another similarity with "with" statements > as an encapsulated "try..finally" is when there's a barrier at the end > of the block. I can live with some magic if it saves me from having a > boilerplate line of "barrier" everywhere 8-) > _______________________________________________ > cython-devel mailing list > cython-devel@python.org > http://mail.python.org/mailman/listinfo/cython-devel >
Hm, indeed. I just noticed that unlike single constructs, master constructs don't have barriers. Both are also not allowed to be closely nested in worksharing constructs. I think the single directive is more useful with respect to tasks, e.g. have a single thread generate tasks and have other threads waiting at the barrier execute them. In that sense I suppose 'if parallel.is_master():' makes sense (no barrier, master thread) and 'with single():' (with barrier, any thread). We could still support single in prange though, if we simply have the master thread execute it ('if (omp_get_thread_num() == 0)') and put a barrier after the block. This makes me wonder what the point of master was supposed to be... _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel