[Cython] cython.parallel tasks, single, master, critical, barriers

mark florisson markflorisson88 at gmail.com
Sun Oct 9 14:11:56 CEST 2011


So far people have been enthusiastic about the cython.parallel features, I
think we should introduce some new features. I propose the following, assume
parallel has been imported from cython:

with parallel.master():
    this is executed in the master thread in a parallel (non-prange) section

with parallel.single():
   same as master, except any thread may do the execution

An optional keyword argument 'nowait' specifies whether there will be a
barrier at the end. The default is to wait.

with parallel.task():
    create a task to be executed by some thread in the team
    once a thread takes up the task it shall only be executed by that thread
and no other thread (so the task will be tied to the thread)

    C variables will be firstprivate
    Python objects will be shared

parallel.taskwait() # wait on any direct descendent tasks to finish

with parallel.critical():
    this section of code is mutually exclusive with other critical sections

    optional keyword argument 'name' specifies a name for the critical
    which means all sections with that name will exclude each other, but not
    critical sections with different names

    Note: all threads that encounter the section will execute it, just not
at the same time

with parallel.barrier():
    all threads wait until everyone has reached the barrier
    either no one or everyone should encounter the barrier
    shared variables are flushed

Unfortunately, gcc again manages to horribly break master and single
constructs in loops (versions 4.2 throughout 4.6), so I suppose I'll first
file a bug report. Other (better) compilers like Portland (and I'm sure
Intel) work fine. I suppose a warning in the documentation will suffice

If we at some point implement vector/SIMD operations we could also try out
the Fortran openmp workshare construct.

What do you guys think?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20111009/5c988f53/attachment.html>

More information about the cython-devel mailing list