pymor.parallel.dummy¶
Module Contents¶
Classes¶
Interface for parallel worker pools. |
|
Handle to remote data on the workers of a |
Attributes¶
- class pymor.parallel.dummy.DummyPool[source]¶
Bases:
pymor.parallel.interface.WorkerPoolInterface for parallel worker pools.
WorkerPoolsallow to easily parallelize algorithms which involve no or little communication between the workers at runtime. The interface methods give the user simple means to distribute data to workers (push,scatter_array,scatter_list) and execute functions on the distributed data in parallel (apply), collecting the return values from each function call. A single worker can be instructed to execute a function using theWorkerPool.apply_onlymethod. Finally, a parallelizedmapfunction is available, which automatically scatters the data among the workers.All operations are performed synchronously.
- push(self, obj)[source]¶
Push a copy of
objto all workers of the pool.A
RemoteObjectis returned as a handle to the pushed object. This object can be used as a keyword argument toapply,apply_only,mapand will then be transparently mapped to the respective copy of the pushed object on the worker.Immutableobjects will be pushed only once. If the sameimmutableobject is pushed a second time, the returnedRemoteObjectwill refer to the already transferred copy. It is therefore safe to usepushto ensure that a givenimmutableobject is available on the worker. No unnecessary copies will be created.Parameters
- obj
The object to push to all workers.
Returns
A
RemoteObjectreferring to the pushed data.
- scatter_array(self, U, copy=True)[source]¶
Distribute
VectorArrayevenly among the workers.On each worker a
VectorArrayis created holding an (up to rounding) equal amount of vectors ofU. The returnedRemoteObjecttherefore refers to different data on each of the workers.Parameters
- U
The
VectorArrayto distribute.- copy
If
False,Uwill be emptied during distribution of the vectors.
Returns
A
RemoteObjectreferring to the scattered data.
- scatter_list(self, l)[source]¶
Distribute list of objects evenly among the workers.
On each worker a
listis created holding an (up to rounding) equal amount of objects ofl. The returnedRemoteObjecttherefore refers to different data on each of the workers.Parameters
- l
The list (sequence) of objects to distribute.
Returns
A
RemoteObjectreferring to the scattered data.
- apply(self, function, *args, **kwargs)[source]¶
Apply function in parallel on each worker.
This calls
functionon each worker in parallel, passingargsas positional andkwargsas keyword arguments. Keyword arguments which areRemoteObjectsare automatically mapped to the respective object on the worker. Moreover, keyword arguments which areimmutableobjects that have already been pushed to the workers will not be transmitted again. (Immutableobjects which have not been pushed before will be transmitted and the remote copy will be destroyed after function execution.)Parameters
- function
The function to execute on each worker.
- args
The positional arguments for
function.- kwargs
The keyword arguments for
function.
Returns
List of return values of the function executions, ordered by worker number (from
0tolen(pool) - 1).
- apply_only(self, function, worker, *args, **kwargs)[source]¶
Apply function on a single worker.
This calls
functionon on the worker with numberworker, passingargsas positional andkwargsas keyword arguments. Keyword arguments which areRemoteObjectsare automatically mapped to the respective object on the worker. Moreover, keyword arguments which areimmutableobjects that have already been pushed to the workers will not be transmitted again. (Immutableobjects which have not been pushed before will be transmitted and the remote copy will be destroyed after function execution.)Parameters
- function
The function to execute.
- worker
The worker on which to execute the function. (Number between
0andlen(pool) - 1.)- args
The positional arguments for
function.- kwargs
The keyword arguments for
function.
Returns
Return value of the function execution.
- map(self, function, *args, **kwargs)[source]¶
Parallel version of the builtin
mapfunction.Each positional argument (after
function) must be a sequence of same length n.mapcallsfunctionin parallel on each of these n positional argument combinations, always passingkwargsas keyword arguments. Keyword arguments which areRemoteObjectsare automatically mapped to the respective object on the worker. Moreover, keyword arguments which areimmutableobjects that have already been pushed to the workers will not be transmitted again. (Immutableobjects which have not been pushed before will be transmitted and the remote copy will be destroyed after function execution.)Parameters
- function
The function to execute on each worker.
- args
The sequences of positional arguments for
function.- kwargs
The keyword arguments for
function.
Returns
List of return values of the function executions, ordered by the sequence of positional arguments.
- class pymor.parallel.dummy.DummyRemoteObject(obj)[source]¶
Bases:
pymor.parallel.interface.RemoteObjectHandle to remote data on the workers of a
WorkerPool.See documentation of
WorkerPoolfor usage of these handles in conjunction withapply,scatter_array,scatter_list.Remote objects can be used as a context manager: when leaving the context, the remote object’s
removemethod is called to ensure proper cleanup of remote resources.