scope_profiler.mpi_wrappers
Opt-in profiling wrappers for mpi4py communicators and requests.
Importing this module never imports mpi4py. Pass an existing communicator to
profile_mpi_comm, or explicitly call profile_mpi4py to patch predefined
communicators for the duration of a run. Importing scope-profiler therefore
cannot initialize MPI in a serial process.
Classes
| Name | Description |
|---|---|
MPIRegionMetadata | Structured metadata decoded from a Python or native MPI region name. |
ProfiledMPIComm | A transparent communicator proxy for common mpi4py operations. |
ProfiledMPIRequest | A request proxy that attributes blocking completion time to MPI wait. |
Functions
| Name | Description |
|---|---|
format_mpi_region | Return the canonical region name shared by Python and C++ wrappers. |
message_nbytes | Estimate payload bytes for an mpi4py object or buffer specification. |
parse_mpi_region | Decode a canonical MPI region name, or return None for another region. |
profile_mpi4py | Temporarily profile mpi4py's predefined communicators. |
profile_mpi_comm | Wrap a communicator without importing mpi4py. |
MPIRegionMetadataclassdataclass#
class MPIRegionMetadata(operation: str, kind: str, bytes: int, peer: int, root: int, tag: int, communicator: int, request: str | None = None)Structured metadata decoded from a Python or native MPI region name.
bytesattributeinstance attribute#
bytes: intcommunicatorattributeinstance attribute#
communicator: intkindattributeinstance attribute#
kind: stroperationattributeinstance attribute#
operation: strpeerattributeinstance attribute#
peer: intrequestattributeclass attributeinstance attribute#
request: str | None = Nonerootattributeinstance attribute#
root: inttagattributeinstance attribute#
tag: intProfiledMPICommclass#
class ProfiledMPIComm(communicator: Any, *, pickle_object_sizes: bool = False)A transparent communicator proxy for common mpi4py operations.
Allreducemethod#
def Allreduce(sendbuf, recvbuf, op=None)Barriermethod#
def Barrier()Bcastmethod#
def Bcast(buf, root: int = 0)Irecvmethod#
def Irecv(buf, source: int = -1, tag: int = -1) -> ProfiledMPIRequestIsendmethod#
def Isend(buf, dest: int, tag: int = 0) -> ProfiledMPIRequestRecvmethod#
def Recv(buf, source: int = -1, tag: int = -1, status=None)Reducemethod#
def Reduce(sendbuf, recvbuf, op=None, root: int = 0)Sendmethod#
def Send(buf, dest: int, tag: int = 0)allreducemethod#
def allreduce(sendobj, op=None)barriermethod#
def barrier()bcastmethod#
def bcast(obj, root: int = 0)irecvmethod#
def irecv(buf=None, source: int = -1, tag: int = -1) -> ProfiledMPIRequestisendmethod#
def isend(obj, dest: int, tag: int = 0) -> ProfiledMPIRequestrecvmethod#
def recv(buf=None, source: int = -1, tag: int = -1, status=None)reducemethod#
def reduce(sendobj, op=None, root: int = 0)sendmethod#
def send(obj, dest: int, tag: int = 0)ProfiledMPIRequestclass#
class ProfiledMPIRequest(request: Any, *, operation: str, bytes: int, peer: int, tag: int, communicator: int)A request proxy that attributes blocking completion time to MPI wait.
format_mpi_regionfunction#
def format_mpi_region(operation: str, *, bytes: int = -1, peer: int = -1, root: int = -1, tag: int = -1, communicator: int = -1, request: str | None = None) -> strReturn the canonical region name shared by Python and C++ wrappers.
message_nbytesfunction#
def message_nbytes(value: Any, *, pickle_objects: bool = True) -> intEstimate payload bytes for an mpi4py object or buffer specification.
Buffer-mode calls are exact when their datatype exposes Get_size.
Object-mode values use their buffer size when possible. With
pickle_objects=True (the default for this explicit helper), other
objects use the size of their protocol-5 pickle. -1 means unknown.
parse_mpi_regionfunction#
def parse_mpi_region(name: str) -> MPIRegionMetadata | NoneDecode a canonical MPI region name, or return None for another region.
profile_mpi4pyfunction#
def profile_mpi4py(mpi_module: Any = None, *, pickle_object_sizes: bool = False, lazy: bool = False) -> Iterator[None]Temporarily profile mpi4py’s predefined communicators.
When lazy is true, mpi4py is wrapped only if the target imports it. This
lets scope-profiler run --mpi-calls enable MPI-call profiling without
importing or initializing MPI for an ordinary serial program. Both globals
and Python’s import function are restored even when the program raises.
profile_mpi_commfunction#
def profile_mpi_comm(communicator: Any, *, pickle_object_sizes: bool = False) -> ProfiledMPICommWrap a communicator without importing mpi4py.
Set pickle_object_sizes=True to measure serialized object-mode payloads
at the cost of one extra serialization per call. It is off by default to
avoid overhead and repeated __reduce__ side effects.