[Python-ideas] adding an __exec__ method to context managers?

Bruce Leban bruce at leapyear.org
Tue Oct 13 18:26:58 CEST 2009


It seems to me that the right way to support this kind of thing is
decorators on suites:
def sample_for():
    @parallel.for:
        for i in range(n):
            do_something(i)

def sample_sections():
    @parallel.sections:
        @parallel.section:
            do_one()
        @parallel.section:
            do_two()
        @parallel.section:
            do_three()

Now there's a lot I don't know about python internals that may make this
more/less practical. The suite decorator would of course be able to do the
same kinds of things that a function decorator can so this is not just
limited to the parallel example.

--- Bruce


On Mon, Oct 12, 2009 at 6:46 PM, Sturla Molden <sturla at molden.no> wrote:

>
>
>   #pragma omp parallel for private(i)
>   for (i=0; i<n; i++)
>      /* whatever */
>
> A simple pragma tells that the loop is parallel, and that the counter is
> private to the thread. Calling multiple task in separate threads are equally
> simple:
>
>  #pragma omp parallel sections
>  {
>     #pragma omp section
>     task1();
>
>     #pragma omp section
>     task2();
>
>     #pragma omp section
>     task3();
>
>  }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20091013/8a28c9f3/attachment.html>


More information about the Python-ideas mailing list