Hello,

PEP 377 has been rejected for lack of use cases. Here is one.

I'm writing an MPI-based application and in some cases, when there is less
work items than processes, I need to create a new communicator excluding
the processes that have nothing to do. This new communicator should finally
be freed by the processes that had work to do (and only by them). If there
is more work than processes, the usual communicator should be used.

A neat way to do that would be to write:

with filter_comm(comm, nworkitems) as newcomm:
    ... do work with communicator newcomm...

the body being executed only by the processes that have work to do.

It looks better than:

if comm.size < nworkitems:
    newcomm = get_new_communicator(comm, nworkitems)
else:
    newcomm = comm

if comm.rank < nworkitems:
    try:
        ... do work with communicator newcomm...
    finally:
        if comm.size < nworkitems:
            newcomm.Free()

Especially since I have to use that quite often.

Cheers,

Pierre
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to