Skip to content
Projects

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

NameDescription
MPIRegionMetadataStructured metadata decoded from a Python or native MPI region name.
ProfiledMPICommA transparent communicator proxy for common mpi4py operations.
ProfiledMPIRequestA request proxy that attributes blocking completion time to MPI wait.

Functions

NameDescription
format_mpi_regionReturn the canonical region name shared by Python and C++ wrappers.
message_nbytesEstimate payload bytes for an mpi4py object or buffer specification.
parse_mpi_regionDecode a canonical MPI region name, or return None for another region.
profile_mpi4pyTemporarily profile mpi4py's predefined communicators.
profile_mpi_commWrap 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: int

communicatorattributeinstance attribute#

communicator: int

kindattributeinstance attribute#

kind: str

operationattributeinstance attribute#

operation: str

peerattributeinstance attribute#

peer: int

requestattributeclass attributeinstance attribute#

request: str | None = None

rootattributeinstance attribute#

root: int

tagattributeinstance attribute#

tag: int

ProfiledMPICommclass#

class ProfiledMPIComm(communicator: Any, *, pickle_object_sizes: bool = False)

A transparent communicator proxy for common mpi4py operations.

communicatorproperty#

communicator: Any

The unwrapped mpi4py communicator.

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) -> ProfiledMPIRequest

Isendmethod#

def Isend(buf, dest: int, tag: int = 0) -> ProfiledMPIRequest

Recvmethod#

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) -> ProfiledMPIRequest

isendmethod#

def isend(obj, dest: int, tag: int = 0) -> ProfiledMPIRequest

recvmethod#

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.

Waitmethod#

def Wait(status=None)

waitmethod#

def wait(status=None)

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) -> str

Return the canonical region name shared by Python and C++ wrappers.

message_nbytesfunction#

def message_nbytes(value: Any, *, pickle_objects: bool = True) -> int

Estimate 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 | None

Decode 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) -> ProfiledMPIComm

Wrap 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.