pymor.parallel package¶
Submodules¶
basic module¶
This module contains a base class for implementing WorkerPoolInterface.
-
class
pymor.parallel.basic.RemoteObject(pool, remote_id, uid=None)[source]¶ Bases:
pymor.parallel.interfaces.RemoteObjectInterfaceMethods
RemoteObjectInterfaceremoveAttributes
RemoteObjectInterfaceremoved
-
class
pymor.parallel.basic.WorkerPoolBase[source]¶ Bases:
pymor.parallel.basic.WorkerPoolDefaultImplementations,pymor.parallel.interfaces.WorkerPoolInterfaceMethods
Attributes
BasicInterfacelogger,logging_disabled,name,uid
-
class
pymor.parallel.basic.WorkerPoolDefaultImplementations[source]¶ Bases:
objectMethods
WorkerPoolDefaultImplementationsscatter_array,scatter_list
default module¶
-
pymor.parallel.default.new_parallel_pool(ipython_num_engines=None, ipython_profile=None, allow_mpi=True)[source]¶ Creates a new default
WorkerPool.If
ipython_num_enginesoripython_profileis provided as an argument or set as adefault, anIPythonPoolWorkerPoolwill be created using the given parameters via theipclusterscript.Otherwise, when
allow_mpiisTrueand an MPI parallel run is detected, anMPIPoolWorkerPoolwill be created.Otherwise, a sequential run is assumed and
pymor.parallel.dummy.dummy_poolis returned.Defaults
ipython_num_engines, ipython_profile, allow_mpi (see
pymor.core.defaults)
dummy module¶
-
class
pymor.parallel.dummy.DummyPool[source]¶ Bases:
pymor.parallel.interfaces.WorkerPoolInterfaceMethods
DummyPoolapply,apply_only,map,push,scatter_array,scatter_listBasicInterfacedisable_logging,enable_logging,has_interface_name,implementor_names,implementorsAttributes
BasicInterfacelogger,logging_disabled,name,uid
-
class
pymor.parallel.dummy.DummyRemoteObject(obj)[source]¶ Bases:
pymor.parallel.interfaces.RemoteObjectInterfaceMethods
RemoteObjectInterfaceremoveAttributes
RemoteObjectInterfaceremoved
interfaces module¶
-
class
pymor.parallel.interfaces.RemoteObjectInterface[source]¶ Bases:
objectHandle to remote data on the workers of a
WorkerPool.See documentation of
WorkerPoolInterfacefor 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.Methods
RemoteObjectInterfaceremoveAttributes
RemoteObjectInterfaceremoved-
remove()[source]¶ Remove the remote object from the workers.
Remove the object this handle refers to from all workers. Note that the object will only be destroyed if no other object on the worker holds a reference to that object. Moreover,
immutableobjects will only be destroyed ifremovehas been called on allRemoteObjectswhich refer to the object (seepush).
-
-
class
pymor.parallel.interfaces.WorkerPoolInterface[source]¶ Bases:
pymor.core.interfaces.BasicInterfaceInterface 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 theWorkerPoolInterface.apply_onlymethod. Finally, a parallelizedmapfunction is available, which automatically scatters the data among the workers.All operations are performed synchronously.
Methods
WorkerPoolInterfaceapply,apply_only,map,push,scatter_array,scatter_list,__len__BasicInterfacedisable_logging,enable_logging,has_interface_name,implementor_names,implementorsAttributes
BasicInterfacelogger,logging_disabled,name,uid-
apply(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(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(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.
-
push(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(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(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.
-
ipython module¶
-
class
pymor.parallel.ipython.IPythonPool(num_engines=None, **kwargs)[source]¶ Bases:
pymor.parallel.basic.WorkerPoolBaseWorkerPoolbased on the IPython parallel computing features.Parameters
- num_engines
- Number of IPython engines to use. If
None, all available engines are used. - kwargs
- Keyword arguments used to instantiate the IPython cluster client.
Methods
Attributes
BasicInterfacelogger,logging_disabled,name,uid
-
class
pymor.parallel.ipython.RemoteId[source]¶ Bases:
intMethods
intbit_length,conjugate,from_bytes,to_bytes,__ceil__,__floor__,__new__,__round__,__sizeof__,__trunc__Attributes
intdenominator,imag,numerator,real
-
class
pymor.parallel.ipython.new_ipcluster_pool(profile=None, cluster_id=None, num_engines=None, ipython_dir=None, min_wait=1, timeout=60)[source]¶ Bases:
pymor.core.interfaces.BasicInterfaceCreate a new IPython parallel cluster and connect to it.
This context manager can be used to create an
IPythonPoolWorkerPool. When entering the context a new IPython cluster is created using theipclusterscript and anIPythonPoolis instantiated for the newly created cluster. When leaving the context the cluster is shut down.Parameters
- profile
- Passed as
--profileparameter to theipclusterscript. - cluster_id
- Passed as
--cluster-idparameter to theipclusterscript. - nun_engines
- Passed as
--nparameter to theipclusterscript. - ipython_dir
- Passed as
--ipython-dirparameter to theipclusterscript. - min_wait
- Wait at least this many seconds before trying to connect to the new cluster.
- timeout
- Wait at most this many seconds for all Ipython cluster engines to become available.
Methods
BasicInterfacedisable_logging,enable_logging,has_interface_name,implementor_names,implementorsAttributes
BasicInterfacelogger,logging_disabled,name,uid
manager module¶
-
class
pymor.parallel.manager.RemoteObjectManager[source]¶ Bases:
pymor.core.interfaces.BasicInterfaceA simple context manager to keep track of
RemoteObjects.When leaving this context, all
RemoteObjectsthat have beenmanagedby this object will beremoved.Methods
RemoteObjectManagermanage,remove_objectsBasicInterfacedisable_logging,enable_logging,has_interface_name,implementor_names,implementorsAttributes
BasicInterfacelogger,logging_disabled,name,uid-
manage(remote_object)[source]¶ Add a
RemoteObjectto the list of managed objects.Parameters
- remote_object
- The object to add to the list.
Returns
remote_object
-
mpi module¶
-
class
pymor.parallel.mpi.MPIPool[source]¶ Bases:
pymor.parallel.basic.WorkerPoolBaseWorkerPoolbased pyMOR’s MPIevent loop.Methods
Attributes
BasicInterfacelogger,logging_disabled,name,uid