pymor.tools.mpi
¶
This module provides helper methods to use pyMOR in parallel with MPI.
Executing this module will run event_loop
on all MPI ranks
except for rank 0 where either a given script is executed:
mpirun -n 16 python -m pymor.tools.mpi /path/to/script
or an interactive session is started:
mpirun -n 16 python -m pymor.tools.mpi
When IPython is available, an IPython kernel is started which the user can connect to by calling:
ipython console --existing file_name_printed_by_ipython.json
(Starting the IPython console directly will not work properly with most MPI implementations.) When IPython is not available, the builtin Python REPL is started.
When event_loop
is running on the MPI ranks, call
can be used on rank 0 to execute the same Python function (given
as first argument) simultaneously on all MPI ranks (including
rank 0). Calling quit
will exit event_loop
on
all MPI ranks.
Additionally, this module provides several helper methods which are
intended to be used in conjunction with call
: mpi_info
will print a summary of all active MPI ranks, run_code
will execute the given code string on all MPI ranks,
import_module
imports the module with the given path.
A simple object management is implemented with the
manage_object
, get_object
and remove_object
methods. It is the user’s responsibility to ensure that calls to
manage_object
are executed in the same order on all MPI ranks
to ensure that the returned ObjectId
refers to the same
distributed object on all ranks. The functions function_call
,
function_call_manage
, method_call
,
method_call_manage
map instances ObjectId
transparently to distributed objects. function_call_manage
and
method_call_manage
will call manage_object
on the
return value and return the corresponding ObjectId
. The functions
method_call
and method_call_manage
are given an
ObjectId
and a string as first and second argument and execute
the method named by the second argument on the object referred to by the
first argument.
Module Contents¶
- pymor.tools.mpi.call(method, *args, **kwargs)[source]¶
Execute method on all MPI ranks.
Assuming
event_loop
is running on all MPI ranks (except rank 0), this will executemethod
on all ranks (including rank 0) with positional argumentsargs
and keyword argumentskwargs
.Parameters
- method
The function to execute on all ranks (must be picklable).
- args
The positional arguments for
method
.- kwargs
The keyword arguments for
method
.
Returns
The return value of
method
on rank 0.
- pymor.tools.mpi.event_loop()[source]¶
Launches an MPI-based event loop.
Events can be sent by either calling
call
on rank 0 to execute an arbitrary method on all ranks or by callingquit
to exit the loop.
- pymor.tools.mpi.event_loop_settings(auto_launch=True)[source]¶
Settings for pyMOR’s MPI event loop.
Parameters
- auto_launch
If
True
, automatically executeevent_loop
on all MPI ranks (except 0) when pyMOR is imported.
- pymor.tools.mpi.function_call(f, *args, **kwargs)[source]¶
Execute the function
f
with given arguments.Intended to be used in conjunction with
call
. Arguments of typeObjectId
are transparently mapped to the object they refer to.
- pymor.tools.mpi.function_call_manage(f, *args, **kwargs)[source]¶
Execute the function
f
and manage the return value.Intended to be used in conjunction with
call
. The return value off
is managed by callingmanage_object
and the correspondingObjectId
is returned. Arguments of typeObjectId
are transparently mapped to the object they refer to.
- pymor.tools.mpi.import_module(path)[source]¶
Import the module named by
path
.Intended to be used in conjunction with
call
.
- pymor.tools.mpi.method_call(obj_id, name_, *args, **kwargs)[source]¶
Execute a method with given arguments.
Intended to be used in conjunction with
call
. Arguments of typeObjectId
are transparently mapped to the object they refer to.Parameters
- obj_id
The
ObjectId
of the object on which to call the method.name_
Name of the method to call.
- args
Positional arguments for the method.
- kwargs
Keyword arguments for the method.
- pymor.tools.mpi.method_call_manage(obj_id, name_, *args, **kwargs)[source]¶
Execute a method with given arguments and manage the return value.
Intended to be used in conjunction with
call
. The return value of the called method is managed by callingmanage_object
and the correspondingObjectId
is returned. Arguments of typeObjectId
are transparently mapped to the object they refer to.Parameters
- obj_id
The
ObjectId
of the object on which to call the method.name_
Name of the method to call.
- args
Positional arguments for the method.
- kwargs
Keyword arguments for the method.
- pymor.tools.mpi.mpi_info()[source]¶
Print some information on the MPI setup.
Intended to be used in conjunction with
call
.
- pymor.tools.mpi.quit()[source]¶
Exit the event loop on all MPI ranks.
This will cause
event_loop
to terminate on all MPI ranks.
- pymor.tools.mpi.remove_object(obj_id)[source]¶
Remove the object referred to by
obj_id
from the registry.