Skip to content

maybempi

Type part of a name or a dotted path

Use MPI only when the process was launched under MPI, and a serial stand-in otherwise.

Importing mpi4py.MPI starts MPI, which costs close to a second and makes every collective cost something, even on one process. maybempi decides from the environment the launcher sets up, without importing mpi4py, and returns either mpi4py.MPI or a serial stand-in with the same interface::

import maybempi
MPI = maybempi.get_mpi() # mpi4py.MPI under mpirun/srun, else the stand-in
comm = MPI.COMM_WORLD
total = comm.allreduce(local_total, op=MPI.SUM)

from maybempi import MPI is the drop-in replacement for from mpi4py import MPI: the name resolves to get_mpi() when it is first imported.

:mod:maybempi.launch holds the detection, :mod:maybempi.serial the stand-in.

Attributes

NameDescription
LAUNCHER_VARIABLESNo description.
LOCAL_RANK_VARIABLESNo description.
OVERRIDE_VARIABLENo description.
__version__No description.

Classes

NameDescription
SerialCartcommStand-in for MPI.Cartcomm: a Cartesian grid of one process.
SerialCommA communicator of size 1, with the mpi4py Comm methods a serial run needs.
SerialFileStand-in for mpi4py.MPI.File: a file opened by the only process.
SerialGroupStand-in for MPI.Group: rank 0 alone, or the empty group.
SerialMPIStand-in for the mpi4py.MPI module in a serial run.
SerialPrequestA persistent request (Send_init/Recv_init): each Start posts it again.
SerialRequestA request of a non-blocking call of :class:SerialComm.
SerialStatusStand-in for MPI.Status: the source, tag and size of a received message.

Functions

NameDescription
get_mpiReturn mpi4py.MPI for an MPI run, else the serial stand-in.
is_serialTell whether obj is the serial stand-in (the module or a communicator).
launched_under_mpiTell whether this process was started by an MPI launcher, without importing mpi4py.
launcher_variableReturn the first variable of :data:LAUNCHER_VARIABLES that is set, if any.
local_rankReturn the rank of this process within its node, from the launcher's environment.
set_copy_hookReport copies between device and host arrays in buffer collectives.

Modules

  • cliThe maybempi command: show what maybempi decides in this environment.
  • launchDecide whether to use MPI, from the environment the launcher sets up.
  • serialA serial stand-in for mpi4py.MPI: a communicator of size 1.

LAUNCHER_VARIABLESattributemodule attribute#

LAUNCHER_VARIABLES = (
  'OMPI_COMM_WORLD_RANK',
  'PMI_RANK',
  'PMIX_RANK',
  'MV2_COMM_WORLD_RANK',
  'MPI_LOCALRANKID',
  'ALPS_APP_PE',
  'PALS_RANKID'
)

LOCAL_RANK_VARIABLESattributemodule attribute#

LOCAL_RANK_VARIABLES = (
  'OMPI_COMM_WORLD_LOCAL_RANK',
  'MV2_COMM_WORLD_LOCAL_RANK',
  'MPI_LOCALRANKID',
  'PMI_LOCAL_RANK',
  'PALS_LOCAL_RANKID',
  'SLURM_LOCALID',
  'LOCAL_RANK'
)

OVERRIDE_VARIABLEattributemodule attribute#

OVERRIDE_VARIABLE = 'MAYBEMPI'

__version__attributemodule attribute#

__version__ = version('maybempi')

SerialCartcommclass#

class SerialCartcomm(dims: Sequence[int], periods: Sequence[bool | int], name: str = 'COMM_WORLD')

Bases: SerialComm

Stand-in for MPI.Cartcomm: a Cartesian grid of one process.

Every dimension has length 1. Along a periodic dimension rank 0 is its own neighbour; along the others Shift gives PROC_NULL.

Cloneattributeclass attributeinstance attribute#

Clone = Dup

coordsproperty#

coords: list[int]

The coordinates of this process (all 0).

dimsproperty#

dims: list[int]

The processes along each dimension (all 1).

ndimproperty#

ndim: int

The number of dimensions.

periodsproperty#

periods: list[int]

Whether each dimension is periodic, as 0 or 1.

topoproperty#

topo: tuple[list[int], list[int], list[int]]

(dims, periods, coords).

Dupmethod#

def Dup(info: Any = None) -> SerialCartcomm

Return a new Cartesian communicator with the same grid.

Get_cart_rankmethod#

def Get_cart_rank(coords: Sequence[int]) -> int

Return 0 for coordinates on the grid (any along periodic dimensions).

Get_coordsmethod#

def Get_coords(rank: int) -> list[int]

Return the coordinates of rank (only 0 exists).

Get_dimmethod#

def Get_dim() -> int

Return the number of dimensions.

Get_topomethod#

def Get_topo() -> tuple[list[int], list[int], list[int]]

Return (dims, periods, coords).

Get_topologymethod#

def Get_topology() -> int

Return CART.

Shiftmethod#

def Shift(direction: int, disp: int) -> tuple[int, int]

Return (source, dest): 0 along periodic dimensions, else PROC_NULL.

Submethod#

def Sub(remain_dims: Sequence[bool]) -> SerialCartcomm

Return the grid of the dimensions in remain_dims.

Inherited from maybempi.serial.SerialComm

Bsendattributeclass attributeinstance attribute#

Bsend = Send

Bsend_initattributeclass attributeinstance attribute#

Bsend_init = Send_init

Ibsendattributeclass attributeinstance attribute#

Ibsend = Isend

Irsendattributeclass attributeinstance attribute#

Irsend = Isend

Rsendattributeclass attributeinstance attribute#

Rsend = Send

Rsend_initattributeclass attributeinstance attribute#

Rsend_init = Send_init

barrierattributeclass attributeinstance attribute#

barrier = Barrier

bsendattributeclass attributeinstance attribute#

bsend = send

ibsendattributeclass attributeinstance attribute#

ibsend = isend

iprobeattributeclass attributeinstance attribute#

iprobe = Iprobe

probeattributeclass attributeinstance attribute#

probe = Probe

rankattributeclass attributeinstance attribute#

rank = 0

sizeattributeclass attributeinstance attribute#

size = 1

groupproperty#

group: SerialGroup

The group of the communicator.

topologyproperty#

topology: int

The topology: UNDEFINED.

Abortmethod#

def Abort(errorcode: int = 0) -> None

Exit the process with errorcode (SystemExit).

Allgathermethod#

def Allgather(sendbuf: Any, recvbuf: Any) -> None

Copy sendbuf into recvbuf.

Allgathervmethod#

def Allgatherv(sendbuf: Any, recvbuf: Any) -> None

Copy sendbuf into recvbuf, at the displacement of rank 0.

Allreducemethod#

def Allreduce(sendbuf: Any, recvbuf: Any, op: Any = None) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Alltoallmethod#

def Alltoall(sendbuf: Any, recvbuf: Any) -> None

Copy sendbuf into recvbuf.

Alltoallvmethod#

def Alltoallv(sendbuf: Any, recvbuf: Any) -> None

Copy the part of sendbuf for rank 0 into recvbuf, at the displacement of rank 0.

Barriermethod#

def Barrier() -> None

Return at once.

Bcastmethod#

def Bcast(buf: Any, root: int = 0) -> None

Do nothing: rank 0 already has the data.

Createmethod#

def Create(group: SerialGroup) -> Any

Return a communicator for group: a new one, or COMM_NULL if empty.

Create_cartmethod#

def Create_cart(dims: Sequence[int], periods: Sequence[bool] | None = None, reorder: bool = False) -> SerialCartcomm

Return a Cartesian communicator; the dimensions must multiply to 1.

Raises

ValueError
If the grid needs more than one process.

Create_groupmethod#

def Create_group(group: SerialGroup, tag: int = 0) -> Any

Return a communicator for group: a new one, or COMM_NULL if empty.

Exscanmethod#

def Exscan(sendbuf: Any, recvbuf: Any, op: Any = None) -> None

Do nothing: the receive buffer of rank 0 is undefined.

Freemethod#

def Free() -> None

Do nothing.

Gathermethod#

def Gather(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy sendbuf into recvbuf.

Gathervmethod#

def Gatherv(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy sendbuf into recvbuf, at the displacement of rank 0.

Get_groupmethod#

def Get_group() -> SerialGroup

Return the group of the communicator: rank 0 only.

Get_namemethod#

def Get_name() -> str

Return the name of the communicator, e.g. "COMM_WORLD".

Get_rankmethod#

def Get_rank() -> int

Return 0.

Get_sizemethod#

def Get_size() -> int

Return 1.

Iallgathermethod#

def Iallgather(sendbuf: Any, recvbuf: Any) -> SerialRequest

Copy like Allgather and return a completed request.

Iallreducemethod#

def Iallreduce(sendbuf: Any, recvbuf: Any, op: Any = None) -> SerialRequest

Copy like Allreduce and return a completed request.

Ibarriermethod#

def Ibarrier() -> SerialRequest

Return a completed request.

Ibcastmethod#

def Ibcast(buf: Any, root: int = 0) -> SerialRequest

Return a completed request (Bcast does nothing).

Iprobemethod#

def Iprobe(source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> bool

Return whether a matching message is waiting, without receiving it.

Irecvmethod#

def Irecv(buf: Any, source: int = _ANY_SOURCE, tag: int = _ANY_TAG) -> SerialRequest

Post a receive into buf; complete once a matching message is sent.

Is_intermethod#

def Is_inter() -> bool

Return False.

Is_intramethod#

def Is_intra() -> bool

Return True.

Isendmethod#

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

Send buf and return a completed request (the data are copied).

Issendmethod#

def Issend(buf: Any, dest: int, tag: int = 0) -> SerialRequest

Send synchronously: the request completes when a receive takes it.

Probemethod#

def Probe(source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> bool

Return True for a waiting message (RuntimeError if none was sent).

Recvmethod#

def Recv(buf: Any, source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> None

Receive into buf (RuntimeError if no matching message was sent).

Recv_initmethod#

def Recv_init(buf: Any, source: int = _ANY_SOURCE, tag: int = _ANY_TAG) -> SerialPrequest

Return a persistent receive: each Start posts a receive into buf.

Reducemethod#

def Reduce(sendbuf: Any, recvbuf: Any, op: Any = None, root: int = 0) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Scanmethod#

def Scan(sendbuf: Any, recvbuf: Any, op: Any = None) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Scattermethod#

def Scatter(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Scattervmethod#

def Scatterv(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy the part of sendbuf at the displacement of rank 0 into recvbuf.

Sendmethod#

def Send(buf: Any, dest: int, tag: int = 0) -> None

Send buf to dest (0, or PROC_NULL); kept until received.

Send_initmethod#

def Send_init(buf: Any, dest: int, tag: int = 0) -> SerialPrequest

Return a persistent send: each Start sends buf.

Sendrecvmethod#

def Sendrecv(sendbuf: Any, dest: int, sendtag: int = 0, recvbuf: Any = None, source: int = _ANY_SOURCE, recvtag: int = _ANY_TAG, status: Any = None) -> None

Send sendbuf to dest and receive into recvbuf from source.

With dest=0, source=0 that copies sendbuf into recvbuf; with PROC_NULL the send or the receive does nothing.

Sendrecv_replacemethod#

def Sendrecv_replace(buf: Any, dest: int, sendtag: int = 0, source: int = _ANY_SOURCE, recvtag: int = _ANY_TAG, status: Any = None) -> None

Send buf to dest, then receive into buf from source.

Splitmethod#

def Split(color: int = 0, key: int = 0) -> Any

Return a new serial communicator, or COMM_NULL for color=UNDEFINED.

Split_typemethod#

def Split_type(split_type: int, key: int = 0, info: Any = None) -> Any

Return a new serial communicator, or COMM_NULL for UNDEFINED.

Ssendmethod#

def Ssend(buf: Any, dest: int, tag: int = 0) -> None

Send synchronously: a matching receive must already be posted.

Ssend_initmethod#

def Ssend_init(buf: Any, dest: int, tag: int = 0) -> SerialPrequest

Return a persistent synchronous send.

allgathermethod#

def allgather(sendobj: Any) -> list[Any]

Return [sendobj].

allreducemethod#

def allreduce(sendobj: Any, op: Any = None) -> Any

Return sendobj.

alltoallmethod#

def alltoall(sendobj: Any) -> list[Any]

Return sendobj as a list (ValueError unless it has one item).

bcastmethod#

def bcast(obj: Any, root: int = 0) -> Any

Return obj.

exscanmethod#

def exscan(sendobj: Any, op: Any = None) -> None

Return None: the result is undefined on rank 0 (None in mpi4py).

gathermethod#

def gather(sendobj: Any, root: int = 0) -> list[Any]

Return [sendobj].

iallreducemethod#

def iallreduce(sendobj: Any, op: Any = None) -> SerialRequest

Return a completed request whose wait() returns sendobj.

ibcastmethod#

def ibcast(obj: Any, root: int = 0) -> SerialRequest

Return a completed request whose wait() returns obj.

irecvmethod#

def irecv(buf: Any = None, source: int = _ANY_SOURCE, tag: int = _ANY_TAG) -> SerialRequest

Post an object receive; wait() returns the object.

isendmethod#

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

Send a (pickled) object and return a completed request.

issendmethod#

def issend(obj: Any, dest: int, tag: int = 0) -> SerialRequest

Send an object synchronously: complete when a receive takes it.

recvmethod#

def recv(buf: Any = None, source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> Any

Return a received object (None from PROC_NULL).

reducemethod#

def reduce(sendobj: Any, op: Any = None, root: int = 0) -> Any

Return sendobj.

scanmethod#

def scan(sendobj: Any, op: Any = None) -> Any

Return sendobj.

scattermethod#

def scatter(sendobj: Any, root: int = 0) -> Any

Return the only item of sendobj (ValueError unless it has one).

sendmethod#

def send(obj: Any, dest: int, tag: int = 0) -> None

Send a (pickled) object to dest.

sendrecvmethod#

def sendrecv(sendobj: Any, dest: int, sendtag: int = 0, recvbuf: Any = None, source: int = _ANY_SOURCE, recvtag: int = _ANY_TAG, status: Any = None) -> Any

Send sendobj to dest and return the object received from source.

With dest=0, source=0 that is a copy of sendobj (unless an earlier message matches first); None with source=PROC_NULL.

ssendmethod#

def ssend(obj: Any, dest: int, tag: int = 0) -> None

Send an object synchronously: a matching receive must be posted.

SerialCommclass#

class SerialComm(name: str = 'COMM_WORLD')

A communicator of size 1, with the mpi4py Comm methods a serial run needs.

Collectives return (object methods) or copy (buffer methods) what they would on one rank: allreduce(x) is x, gather(x) is [x], Allreduce(send, recv) copies send into recv (nothing with IN_PLACE), Bcast does nothing. Point-to-point messages go to and come from rank 0 itself or PROC_NULL: a send is kept, per communicator, until a receive with a matching tag takes it, in the order sent. A blocking receive with no matching message raises RuntimeError (MPI would wait forever). Other methods raise AttributeError.

Attributes

NameDescription
rankAlways 0.
sizeAlways 1.

Bsendattributeclass attributeinstance attribute#

Bsend = Send

Bsend_initattributeclass attributeinstance attribute#

Bsend_init = Send_init

Cloneattributeclass attributeinstance attribute#

Clone = Dup

Ibsendattributeclass attributeinstance attribute#

Ibsend = Isend

Irsendattributeclass attributeinstance attribute#

Irsend = Isend

Rsendattributeclass attributeinstance attribute#

Rsend = Send

Rsend_initattributeclass attributeinstance attribute#

Rsend_init = Send_init

barrierattributeclass attributeinstance attribute#

barrier = Barrier

bsendattributeclass attributeinstance attribute#

bsend = send

ibsendattributeclass attributeinstance attribute#

ibsend = isend

iprobeattributeclass attributeinstance attribute#

iprobe = Iprobe

probeattributeclass attributeinstance attribute#

probe = Probe

rankattributeclass attributeinstance attribute#

rank = 0

sizeattributeclass attributeinstance attribute#

size = 1

groupproperty#

group: SerialGroup

The group of the communicator.

topologyproperty#

topology: int

The topology: UNDEFINED.

Abortmethod#

def Abort(errorcode: int = 0) -> None

Exit the process with errorcode (SystemExit).

Allgathermethod#

def Allgather(sendbuf: Any, recvbuf: Any) -> None

Copy sendbuf into recvbuf.

Allgathervmethod#

def Allgatherv(sendbuf: Any, recvbuf: Any) -> None

Copy sendbuf into recvbuf, at the displacement of rank 0.

Allreducemethod#

def Allreduce(sendbuf: Any, recvbuf: Any, op: Any = None) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Alltoallmethod#

def Alltoall(sendbuf: Any, recvbuf: Any) -> None

Copy sendbuf into recvbuf.

Alltoallvmethod#

def Alltoallv(sendbuf: Any, recvbuf: Any) -> None

Copy the part of sendbuf for rank 0 into recvbuf, at the displacement of rank 0.

Barriermethod#

def Barrier() -> None

Return at once.

Bcastmethod#

def Bcast(buf: Any, root: int = 0) -> None

Do nothing: rank 0 already has the data.

Createmethod#

def Create(group: SerialGroup) -> Any

Return a communicator for group: a new one, or COMM_NULL if empty.

Create_cartmethod#

def Create_cart(dims: Sequence[int], periods: Sequence[bool] | None = None, reorder: bool = False) -> SerialCartcomm

Return a Cartesian communicator; the dimensions must multiply to 1.

Raises

ValueError
If the grid needs more than one process.

Create_groupmethod#

def Create_group(group: SerialGroup, tag: int = 0) -> Any

Return a communicator for group: a new one, or COMM_NULL if empty.

Dupmethod#

def Dup(info: Any = None) -> SerialComm

Return a new serial communicator with the same name.

Exscanmethod#

def Exscan(sendbuf: Any, recvbuf: Any, op: Any = None) -> None

Do nothing: the receive buffer of rank 0 is undefined.

Freemethod#

def Free() -> None

Do nothing.

Gathermethod#

def Gather(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy sendbuf into recvbuf.

Gathervmethod#

def Gatherv(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy sendbuf into recvbuf, at the displacement of rank 0.

Get_groupmethod#

def Get_group() -> SerialGroup

Return the group of the communicator: rank 0 only.

Get_namemethod#

def Get_name() -> str

Return the name of the communicator, e.g. "COMM_WORLD".

Get_rankmethod#

def Get_rank() -> int

Return 0.

Get_sizemethod#

def Get_size() -> int

Return 1.

Get_topologymethod#

def Get_topology() -> int

Return UNDEFINED: no topology.

Iallgathermethod#

def Iallgather(sendbuf: Any, recvbuf: Any) -> SerialRequest

Copy like Allgather and return a completed request.

Iallreducemethod#

def Iallreduce(sendbuf: Any, recvbuf: Any, op: Any = None) -> SerialRequest

Copy like Allreduce and return a completed request.

Ibarriermethod#

def Ibarrier() -> SerialRequest

Return a completed request.

Ibcastmethod#

def Ibcast(buf: Any, root: int = 0) -> SerialRequest

Return a completed request (Bcast does nothing).

Iprobemethod#

def Iprobe(source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> bool

Return whether a matching message is waiting, without receiving it.

Irecvmethod#

def Irecv(buf: Any, source: int = _ANY_SOURCE, tag: int = _ANY_TAG) -> SerialRequest

Post a receive into buf; complete once a matching message is sent.

Is_intermethod#

def Is_inter() -> bool

Return False.

Is_intramethod#

def Is_intra() -> bool

Return True.

Isendmethod#

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

Send buf and return a completed request (the data are copied).

Issendmethod#

def Issend(buf: Any, dest: int, tag: int = 0) -> SerialRequest

Send synchronously: the request completes when a receive takes it.

Probemethod#

def Probe(source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> bool

Return True for a waiting message (RuntimeError if none was sent).

Recvmethod#

def Recv(buf: Any, source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> None

Receive into buf (RuntimeError if no matching message was sent).

Recv_initmethod#

def Recv_init(buf: Any, source: int = _ANY_SOURCE, tag: int = _ANY_TAG) -> SerialPrequest

Return a persistent receive: each Start posts a receive into buf.

Reducemethod#

def Reduce(sendbuf: Any, recvbuf: Any, op: Any = None, root: int = 0) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Scanmethod#

def Scan(sendbuf: Any, recvbuf: Any, op: Any = None) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Scattermethod#

def Scatter(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy sendbuf into recvbuf (nothing with IN_PLACE).

Scattervmethod#

def Scatterv(sendbuf: Any, recvbuf: Any, root: int = 0) -> None

Copy the part of sendbuf at the displacement of rank 0 into recvbuf.

Sendmethod#

def Send(buf: Any, dest: int, tag: int = 0) -> None

Send buf to dest (0, or PROC_NULL); kept until received.

Send_initmethod#

def Send_init(buf: Any, dest: int, tag: int = 0) -> SerialPrequest

Return a persistent send: each Start sends buf.

Sendrecvmethod#

def Sendrecv(sendbuf: Any, dest: int, sendtag: int = 0, recvbuf: Any = None, source: int = _ANY_SOURCE, recvtag: int = _ANY_TAG, status: Any = None) -> None

Send sendbuf to dest and receive into recvbuf from source.

With dest=0, source=0 that copies sendbuf into recvbuf; with PROC_NULL the send or the receive does nothing.

Sendrecv_replacemethod#

def Sendrecv_replace(buf: Any, dest: int, sendtag: int = 0, source: int = _ANY_SOURCE, recvtag: int = _ANY_TAG, status: Any = None) -> None

Send buf to dest, then receive into buf from source.

Splitmethod#

def Split(color: int = 0, key: int = 0) -> Any

Return a new serial communicator, or COMM_NULL for color=UNDEFINED.

Split_typemethod#

def Split_type(split_type: int, key: int = 0, info: Any = None) -> Any

Return a new serial communicator, or COMM_NULL for UNDEFINED.

Ssendmethod#

def Ssend(buf: Any, dest: int, tag: int = 0) -> None

Send synchronously: a matching receive must already be posted.

Ssend_initmethod#

def Ssend_init(buf: Any, dest: int, tag: int = 0) -> SerialPrequest

Return a persistent synchronous send.

allgathermethod#

def allgather(sendobj: Any) -> list[Any]

Return [sendobj].

allreducemethod#

def allreduce(sendobj: Any, op: Any = None) -> Any

Return sendobj.

alltoallmethod#

def alltoall(sendobj: Any) -> list[Any]

Return sendobj as a list (ValueError unless it has one item).

bcastmethod#

def bcast(obj: Any, root: int = 0) -> Any

Return obj.

exscanmethod#

def exscan(sendobj: Any, op: Any = None) -> None

Return None: the result is undefined on rank 0 (None in mpi4py).

gathermethod#

def gather(sendobj: Any, root: int = 0) -> list[Any]

Return [sendobj].

iallreducemethod#

def iallreduce(sendobj: Any, op: Any = None) -> SerialRequest

Return a completed request whose wait() returns sendobj.

ibcastmethod#

def ibcast(obj: Any, root: int = 0) -> SerialRequest

Return a completed request whose wait() returns obj.

irecvmethod#

def irecv(buf: Any = None, source: int = _ANY_SOURCE, tag: int = _ANY_TAG) -> SerialRequest

Post an object receive; wait() returns the object.

isendmethod#

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

Send a (pickled) object and return a completed request.

issendmethod#

def issend(obj: Any, dest: int, tag: int = 0) -> SerialRequest

Send an object synchronously: complete when a receive takes it.

recvmethod#

def recv(buf: Any = None, source: int = _ANY_SOURCE, tag: int = _ANY_TAG, status: Any = None) -> Any

Return a received object (None from PROC_NULL).

reducemethod#

def reduce(sendobj: Any, op: Any = None, root: int = 0) -> Any

Return sendobj.

scanmethod#

def scan(sendobj: Any, op: Any = None) -> Any

Return sendobj.

scattermethod#

def scatter(sendobj: Any, root: int = 0) -> Any

Return the only item of sendobj (ValueError unless it has one).

sendmethod#

def send(obj: Any, dest: int, tag: int = 0) -> None

Send a (pickled) object to dest.

sendrecvmethod#

def sendrecv(sendobj: Any, dest: int, sendtag: int = 0, recvbuf: Any = None, source: int = _ANY_SOURCE, recvtag: int = _ANY_TAG, status: Any = None) -> Any

Send sendobj to dest and return the object received from source.

With dest=0, source=0 that is a copy of sendobj (unless an earlier message matches first); None with source=PROC_NULL.

ssendmethod#

def ssend(obj: Any, dest: int, tag: int = 0) -> None

Send an object synchronously: a matching receive must be posted.

SerialFileclass#

Re-exported from maybempi._fileView source
class SerialFile(handle: Any, path: str, amode: int)

Stand-in for mpi4py.MPI.File: a file opened by the only process.

Read_allattributeclass attributeinstance attribute#

Read_all = Read

Read_at_allattributeclass attributeinstance attribute#

Read_at_all = Read_at

Write_allattributeclass attributeinstance attribute#

Write_all = Write

Write_at_allattributeclass attributeinstance attribute#

Write_at_all = Write_at

Closemethod#

def Close() -> None

Close the file (and delete it with MODE_DELETE_ON_CLOSE).

Deletemethodstaticmethod#

def Delete(filename: str | os.PathLike[str], info: Any = None) -> None

Delete a file.

Get_amodemethod#

def Get_amode() -> int

Return the access mode the file was opened with.

Get_atomicitymethod#

def Get_atomicity() -> bool

Return the atomicity flag.

Get_byte_offsetmethod#

def Get_byte_offset(offset: int) -> int

Return the byte position of the elementary type at offset in the view.

Get_positionmethod#

def Get_position() -> int

Return the file pointer, in etypes of the view.

Get_sizemethod#

def Get_size() -> int

Return the size of the file in bytes.

Get_viewmethod#

def Get_view() -> tuple[int, _Datatype, _Datatype, str]

Return (disp, etype, filetype, datarep).

Ireadmethod#

def Iread(buf: Any) -> Any

Read like Read and return a completed request.

Iread_atmethod#

def Iread_at(offset: int, buf: Any) -> Any

Read like Read_at and return a completed request.

Iwritemethod#

def Iwrite(buf: Any) -> Any

Write like Write and return a completed request.

Iwrite_atmethod#

def Iwrite_at(offset: int, buf: Any) -> Any

Write like Write_at and return a completed request.

Openmethodclassmethod#

def Open(comm: Any, filename: str | os.PathLike[str], amode: int = MODE_RDONLY, info: Any = None) -> SerialFile

Open filename with the MPI access mode amode (MODE_RDONLY, …).

Raises

ValueError
For an invalid combination of modes.
OSError
If the file cannot be opened (e.g. FileNotFoundError).

Preallocatemethod#

def Preallocate(size: int) -> None

Extend the file to at least size bytes.

Readmethod#

def Read(buf: Any, status: Any = None) -> None

Read into buf from the file pointer and advance it.

Read_atmethod#

def Read_at(offset: int, buf: Any, status: Any = None) -> None

Read into buf from the explicit offset offset (in etypes of the view).

Seekmethod#

def Seek(offset: int, whence: int = SEEK_SET) -> None

Move the file pointer (in etypes of the view).

Raises

ValueError
For SEEK_END in a view with gaps, or a negative position.

Set_atomicitymethod#

def Set_atomicity(flag: bool) -> None

Record the atomicity flag (one process is always atomic).

Set_sizemethod#

def Set_size(size: int) -> None

Truncate or extend the file to size bytes.

Set_viewmethod#

def Set_view(disp: int = 0, etype: _Datatype | None = None, filetype: _Datatype | None = None, datarep: str = 'native', info: Any = None) -> None

Set the view: data from byte disp on, where filetype places it.

Resets the file pointer to 0.

Raises

ValueError
For a data representation other than "native", or a file type not built from the elementary type.

Syncmethod#

def Sync() -> None

Write the file to the storage device.

Writemethod#

def Write(buf: Any, status: Any = None) -> None

Write buf at the file pointer and advance it.

Write_atmethod#

def Write_at(offset: int, buf: Any, status: Any = None) -> None

Write buf at the explicit offset offset (in etypes of the view).

SerialGroupclass#

class SerialGroup(size: int = 1)

Stand-in for MPI.Group: rank 0 alone, or the empty group.

rankproperty#

rank: int

The rank of this process in the group.

sizeproperty#

size: int

The number of ranks.

Comparemethod#

def Compare(group: SerialGroup) -> int

Return IDENT for groups of the same size, else UNEQUAL.

Differencemethodstaticmethod#

def Difference(group1: SerialGroup, group2: SerialGroup) -> SerialGroup

Return the ranks of group1 that are not in group2.

Dupmethod#

def Dup() -> SerialGroup

Return a copy.

Exclmethod#

def Excl(ranks: Sequence[int]) -> SerialGroup

Return the group without ranks.

Freemethod#

def Free() -> None

Do nothing.

Get_rankmethod#

def Get_rank() -> int

Return 0, or UNDEFINED for the empty group.

Get_sizemethod#

def Get_size() -> int

Return 1, or 0 for the empty group.

Inclmethod#

def Incl(ranks: Sequence[int]) -> SerialGroup

Return the group of ranks: [0] or [].

Intersectionmethodstaticmethod#

def Intersection(group1: SerialGroup, group2: SerialGroup) -> SerialGroup

Return the intersection of two groups.

Translate_ranksmethod#

def Translate_ranks(ranks: Sequence[int] | None = None, group: SerialGroup | None = None) -> list[int]

Return the ranks in group of ranks of this group (0 stays 0).

Unionmethodstaticmethod#

def Union(group1: SerialGroup, group2: SerialGroup) -> SerialGroup

Return the union of two groups.

SerialMPIclass#

class SerialMPI

Stand-in for the mpi4py.MPI module in a serial run.

:func:~maybempi.launch.get_mpi returns one instance, and :func:~maybempi.launch.is_serial tells it from mpi4py.MPI. COMM_WORLD and COMM_SELF are :class:SerialComm objects; the reduction operations, datatypes and other constants are placeholders that :class:SerialComm accepts. Is_initialized() is False: MPI itself is never started.

ANY_SOURCEattributeclass attributeinstance attribute#

ANY_SOURCE = _ANY_SOURCE

ANY_TAGattributeclass attributeinstance attribute#

ANY_TAG = _ANY_TAG

BANDattributeclass attributeinstance attribute#

BAND = _Op('BAND')

BOOLattributeclass attributeinstance attribute#

BOOL = _Datatype('BOOL', 1)

BORattributeclass attributeinstance attribute#

BOR = _Op('BOR')

BOTTOMattributeclass attributeinstance attribute#

BOTTOM = _Constant('BOTTOM')

BXORattributeclass attributeinstance attribute#

BXOR = _Op('BXOR')

BYTEattributeclass attributeinstance attribute#

BYTE = _Datatype('BYTE', 1)

CARTattributeclass attributeinstance attribute#

CART = _CART

CHARattributeclass attributeinstance attribute#

CHAR = _Datatype('CHAR', 1)

COMM_NULLattributeclass attributeinstance attribute#

COMM_NULL = _COMM_NULL

COMM_SELFattributeclass attributeinstance attribute#

COMM_SELF = SerialComm('COMM_SELF')

COMM_TYPE_SHAREDattributeclass attributeinstance attribute#

COMM_TYPE_SHARED = 0

COMM_WORLDattributeclass attributeinstance attribute#

COMM_WORLD = SerialComm('COMM_WORLD')

COMPLEXattributeclass attributeinstance attribute#

COMPLEX = _Datatype('COMPLEX', 8)

CONGRUENTattributeclass attributeinstance attribute#

CONGRUENT = 1

C_BOOLattributeclass attributeinstance attribute#

C_BOOL = _Datatype('C_BOOL', 1)

C_DOUBLE_COMPLEXattributeclass attributeinstance attribute#

C_DOUBLE_COMPLEX = _Datatype('C_DOUBLE_COMPLEX', 16)

C_FLOAT_COMPLEXattributeclass attributeinstance attribute#

C_FLOAT_COMPLEX = _Datatype('C_FLOAT_COMPLEX', 8)

Cartcommattributeclass attributeinstance attribute#

Cartcomm = SerialCartcomm

Commattributeclass attributeinstance attribute#

Comm = SerialComm

DATATYPE_NULLattributeclass attributeinstance attribute#

DATATYPE_NULL = _Null('DATATYPE_NULL')

DIST_GRAPHattributeclass attributeinstance attribute#

DIST_GRAPH = _DIST_GRAPH

DOUBLEattributeclass attributeinstance attribute#

DOUBLE = _Datatype('DOUBLE', 8)

DOUBLE_COMPLEXattributeclass attributeinstance attribute#

DOUBLE_COMPLEX = _Datatype('DOUBLE_COMPLEX', 16)

Datatypeattributeclass attributeinstance attribute#

Datatype = _Datatype

FILE_NULLattributeclass attributeinstance attribute#

FILE_NULL = _file.FILE_NULL

FLOATattributeclass attributeinstance attribute#

FLOAT = _Datatype('FLOAT', 4)

Fileattributeclass attributeinstance attribute#

File = SerialFile

GRAPHattributeclass attributeinstance attribute#

GRAPH = _GRAPH

GROUP_EMPTYattributeclass attributeinstance attribute#

GROUP_EMPTY = SerialGroup(0)

GROUP_NULLattributeclass attributeinstance attribute#

GROUP_NULL = _Null('GROUP_NULL')

Groupattributeclass attributeinstance attribute#

Group = SerialGroup

IDENTattributeclass attributeinstance attribute#

IDENT = 0

INFO_ENVattributeclass attributeinstance attribute#

INFO_ENV = _Constant('INFO_ENV')

INFO_NULLattributeclass attributeinstance attribute#

INFO_NULL = _Null('INFO_NULL')

INTattributeclass attributeinstance attribute#

INT = _Datatype('INT', ctypes.sizeof(ctypes.c_int))

INT16_Tattributeclass attributeinstance attribute#

INT16_T = _Datatype('INT16_T', 2)

INT32_Tattributeclass attributeinstance attribute#

INT32_T = _Datatype('INT32_T', 4)

INT64_Tattributeclass attributeinstance attribute#

INT64_T = _Datatype('INT64_T', 8)

INT8_Tattributeclass attributeinstance attribute#

INT8_T = _Datatype('INT8_T', 1)

IN_PLACEattributeclass attributeinstance attribute#

IN_PLACE = _IN_PLACE

Intracommattributeclass attributeinstance attribute#

Intracomm = SerialComm

LANDattributeclass attributeinstance attribute#

LAND = _Op('LAND')

LONGattributeclass attributeinstance attribute#

LONG = _Datatype('LONG', ctypes.sizeof(ctypes.c_long))

LONG_DOUBLEattributeclass attributeinstance attribute#

LONG_DOUBLE = _Datatype('LONG_DOUBLE', ctypes.sizeof(ctypes.c_longdouble))

LONG_LONGattributeclass attributeinstance attribute#

LONG_LONG = _Datatype('LONG_LONG', 8)

LORattributeclass attributeinstance attribute#

LOR = _Op('LOR')

LXORattributeclass attributeinstance attribute#

LXOR = _Op('LXOR')

MAXattributeclass attributeinstance attribute#

MAX = _Op('MAX')

MAXLOCattributeclass attributeinstance attribute#

MAXLOC = _Op('MAXLOC')

MINattributeclass attributeinstance attribute#

MIN = _Op('MIN')

MINLOCattributeclass attributeinstance attribute#

MINLOC = _Op('MINLOC')

MODE_APPENDattributeclass attributeinstance attribute#

MODE_APPEND = _file.MODE_APPEND

MODE_CREATEattributeclass attributeinstance attribute#

MODE_CREATE = _file.MODE_CREATE

MODE_DELETE_ON_CLOSEattributeclass attributeinstance attribute#

MODE_DELETE_ON_CLOSE = _file.MODE_DELETE_ON_CLOSE

MODE_EXCLattributeclass attributeinstance attribute#

MODE_EXCL = _file.MODE_EXCL

MODE_RDONLYattributeclass attributeinstance attribute#

MODE_RDONLY = _file.MODE_RDONLY

MODE_RDWRattributeclass attributeinstance attribute#

MODE_RDWR = _file.MODE_RDWR

MODE_SEQUENTIALattributeclass attributeinstance attribute#

MODE_SEQUENTIAL = _file.MODE_SEQUENTIAL

MODE_UNIQUE_OPENattributeclass attributeinstance attribute#

MODE_UNIQUE_OPEN = _file.MODE_UNIQUE_OPEN

MODE_WRONLYattributeclass attributeinstance attribute#

MODE_WRONLY = _file.MODE_WRONLY

OP_NULLattributeclass attributeinstance attribute#

OP_NULL = _Null('OP_NULL')

ORDER_Cattributeclass attributeinstance attribute#

ORDER_C = ORDER_C

ORDER_Fattributeclass attributeinstance attribute#

ORDER_F = ORDER_F

ORDER_FORTRANattributeclass attributeinstance attribute#

ORDER_FORTRAN = ORDER_F

Opattributeclass attributeinstance attribute#

Op = _Op

PROC_NULLattributeclass attributeinstance attribute#

PROC_NULL = _PROC_NULL

PRODattributeclass attributeinstance attribute#

PROD = _Op('PROD')

Prequestattributeclass attributeinstance attribute#

Prequest = SerialPrequest

REPLACEattributeclass attributeinstance attribute#

REPLACE = _Op('REPLACE')

REQUEST_NULLattributeclass attributeinstance attribute#

REQUEST_NULL = _Null('REQUEST_NULL')

ROOTattributeclass attributeinstance attribute#

ROOT = -3

Requestattributeclass attributeinstance attribute#

Request = SerialRequest

SEEK_CURattributeclass attributeinstance attribute#

SEEK_CUR = _file.SEEK_CUR

SEEK_ENDattributeclass attributeinstance attribute#

SEEK_END = _file.SEEK_END

SEEK_SETattributeclass attributeinstance attribute#

SEEK_SET = _file.SEEK_SET

SIMILARattributeclass attributeinstance attribute#

SIMILAR = 2

SUCCESSattributeclass attributeinstance attribute#

SUCCESS = 0

SUMattributeclass attributeinstance attribute#

SUM = _Op('SUM')

Statusattributeclass attributeinstance attribute#

Status = SerialStatus

THREAD_FUNNELEDattributeclass attributeinstance attribute#

THREAD_FUNNELED = 1

THREAD_MULTIPLEattributeclass attributeinstance attribute#

THREAD_MULTIPLE = 3

THREAD_SERIALIZEDattributeclass attributeinstance attribute#

THREAD_SERIALIZED = 2

THREAD_SINGLEattributeclass attributeinstance attribute#

THREAD_SINGLE = 0

UINT16_Tattributeclass attributeinstance attribute#

UINT16_T = _Datatype('UINT16_T', 2)

UINT32_Tattributeclass attributeinstance attribute#

UINT32_T = _Datatype('UINT32_T', 4)

UINT64_Tattributeclass attributeinstance attribute#

UINT64_T = _Datatype('UINT64_T', 8)

UINT8_Tattributeclass attributeinstance attribute#

UINT8_T = _Datatype('UINT8_T', 1)

UNDEFINEDattributeclass attributeinstance attribute#

UNDEFINED = _UNDEFINED

UNEQUALattributeclass attributeinstance attribute#

UNEQUAL = 3

UNSIGNEDattributeclass attributeinstance attribute#

UNSIGNED = _Datatype('UNSIGNED', ctypes.sizeof(ctypes.c_uint))

UNSIGNED_LONGattributeclass attributeinstance attribute#

UNSIGNED_LONG = _Datatype('UNSIGNED_LONG', ctypes.sizeof(ctypes.c_ulong))

Compute_dimsmethodstaticmethod#

def Compute_dims(nnodes: int, dims: int | Sequence[int]) -> list[int]

Return a process grid for nnodes (1) processes: all ones.

Raises

ValueError
For a number of processes other than 1.

Finalizemethodstaticmethod#

def Finalize() -> None

Do nothing.

Get_processor_namemethodstaticmethod#

def Get_processor_name() -> str

Return the host name.

Get_versionmethodstaticmethod#

def Get_version() -> tuple[int, int]

Return (4, 0): the MPI standard the stand-in follows.

Initmethodstaticmethod#

def Init() -> None

Do nothing.

Is_finalizedmethodstaticmethod#

def Is_finalized() -> bool

Return False.

Is_initializedmethodstaticmethod#

def Is_initialized() -> bool

Return False: MPI is never started.

Query_threadmethodstaticmethod#

def Query_thread() -> int

Return 0 (THREAD_SINGLE).

Wtickmethodstaticmethod#

def Wtick() -> float

Return the resolution of :meth:Wtime in seconds.

Wtimemethodstaticmethod#

def Wtime() -> float

Return the wall-clock time in seconds (time.time()).

SerialPrequestclass#

class SerialPrequest(start: Callable[[], SerialRequest] | None = None)

Bases: SerialRequest

A persistent request (Send_init/Recv_init): each Start posts it again.

Before the first Start, the request is inactive and complete.

Cancelmethod#

def Cancel() -> None

Cancel the started operation.

Startmethod#

def Start() -> None

Post the operation (a send or a receive).

Startallmethodstaticmethod#

def Startall(requests: Sequence[Any]) -> None

Start every request.

Testmethod#

def Test(status: Any = None) -> bool

Return whether the started operation is complete (True if inactive).

Waitmethod#

def Wait(status: Any = None) -> None

Wait for the started operation (at once if inactive).

Inherited from maybempi.serial.SerialRequest

Freemethod#

def Free() -> None

Do nothing.

Testallmethodstaticmethod#

def Testall(requests: Sequence[Any], statuses: Any = None) -> bool

Return whether every request is complete.

Testanymethodstaticmethod#

def Testany(requests: Sequence[Any], status: Any = None) -> tuple[int, bool]

Return (index, True) for a complete request, else (UNDEFINED, ...).

Testsomemethodstaticmethod#

def Testsome(requests: Sequence[Any], statuses: Any = None) -> list[int] | None

Return the indices of the complete requests (None for no requests).

Waitallmethodstaticmethod#

def Waitall(requests: Sequence[Any], statuses: Any = None) -> None

Wait for every request (RuntimeError if one can never complete).

Waitanymethodstaticmethod#

def Waitany(requests: Sequence[Any], status: Any = None) -> int

Return the index of a complete request, or UNDEFINED for no requests.

Waitsomemethodstaticmethod#

def Waitsome(requests: Sequence[Any], statuses: Any = None) -> list[int] | None

Return the indices of the complete requests (None for no requests).

testmethod#

def test(status: Any = None) -> tuple[bool, Any]

Return (True, result) when complete, else (False, None).

testallmethodstaticmethod#

def testall(requests: Sequence[Any], statuses: Any = None) -> tuple[bool, Any]

Return (True, results) when all are complete, else (False, None).

waitmethod#

def wait(status: Any = None) -> Any

Return the result of the non-blocking object call (RuntimeError if never).

waitallmethodstaticmethod#

def waitall(requests: Sequence[Any], statuses: Any = None) -> list[Any]

Return the results of the requests.

SerialRequestclass#

class SerialRequest(result: Any = None, *, complete: bool = True, waiting_for: str = '')

A request of a non-blocking call of :class:SerialComm.

Collectives and sends complete at once. A receive (Irecv, irecv) or a synchronous send (Issend) completes when its matching message (or receive) is posted. Waiting for a request that can never complete raises RuntimeError: on one process, MPI would wait forever.

Cancelmethod#

def Cancel() -> None

Cancel a receive that has no message yet; nothing for a complete request.

Freemethod#

def Free() -> None

Do nothing.

Testmethod#

def Test(status: Any = None) -> bool

Return whether the operation is complete.

Testallmethodstaticmethod#

def Testall(requests: Sequence[Any], statuses: Any = None) -> bool

Return whether every request is complete.

Testanymethodstaticmethod#

def Testany(requests: Sequence[Any], status: Any = None) -> tuple[int, bool]

Return (index, True) for a complete request, else (UNDEFINED, ...).

Testsomemethodstaticmethod#

def Testsome(requests: Sequence[Any], statuses: Any = None) -> list[int] | None

Return the indices of the complete requests (None for no requests).

Waitmethod#

def Wait(status: Any = None) -> None

Return once the operation is complete (RuntimeError if it never can).

Waitallmethodstaticmethod#

def Waitall(requests: Sequence[Any], statuses: Any = None) -> None

Wait for every request (RuntimeError if one can never complete).

Waitanymethodstaticmethod#

def Waitany(requests: Sequence[Any], status: Any = None) -> int

Return the index of a complete request, or UNDEFINED for no requests.

Waitsomemethodstaticmethod#

def Waitsome(requests: Sequence[Any], statuses: Any = None) -> list[int] | None

Return the indices of the complete requests (None for no requests).

testmethod#

def test(status: Any = None) -> tuple[bool, Any]

Return (True, result) when complete, else (False, None).

testallmethodstaticmethod#

def testall(requests: Sequence[Any], statuses: Any = None) -> tuple[bool, Any]

Return (True, results) when all are complete, else (False, None).

waitmethod#

def wait(status: Any = None) -> Any

Return the result of the non-blocking object call (RuntimeError if never).

waitallmethodstaticmethod#

def waitall(requests: Sequence[Any], statuses: Any = None) -> list[Any]

Return the results of the requests.

SerialStatusclass#

class SerialStatus()

Stand-in for MPI.Status: the source, tag and size of a received message.

Get_elementsattributeclass attributeinstance attribute#

Get_elements = Get_count

countattributeinstance attribute#

count = 0

errorattributeinstance attribute#

error = 0

sourceattributeinstance attribute#

source = 0

tagattributeinstance attribute#

tag = 0

Get_countmethod#

def Get_count(datatype: Any = None) -> int

Return the number of datatype items received (bytes by default).

Get_errormethod#

def Get_error() -> int

Return 0 (SUCCESS).

Get_sourcemethod#

def Get_source() -> int

Return the source rank (0, or PROC_NULL).

Get_tagmethod#

def Get_tag() -> int

Return the tag of the message.

Is_cancelledmethod#

def Is_cancelled() -> bool

Return False.

get_mpifunction#

def get_mpi(use_mpi: bool | None = None) -> Any

Return mpi4py.MPI for an MPI run, else the serial stand-in.

Parameters

NameTypeDefaultDescription
use_mpibool | NoneNoneNone (the default) decides with :func:launched_under_mpi, once per process. True imports mpi4py (ImportError if it is not installed). False returns the stand-in without importing mpi4py.

Returns

Any
mpi4py.MPI, or the one :class:~maybempi.serial.SerialMPI object,
Any
which has the attributes of the module that a serial run needs.
Any
func:is_serial tells which one it is.

Warns

RuntimeWarning
Launched under MPI, but mpi4py is not installed. Every process then runs as if it were alone, as rank 0 of 1.

is_serialfunction#

def is_serial(obj: Any) -> bool

Tell whether obj is the serial stand-in (the module or a communicator).

Parameters

NameTypeDescription
objAnyWhat :func:get_mpi returned, or a communicator such as MPI.COMM_WORLD.

Returns

bool
True for :class:~maybempi.serial.SerialMPI and
bool
class:~maybempi.serial.SerialComm objects, False for mpi4py’s.

launched_under_mpifunction#

def launched_under_mpi() -> bool

Tell whether this process was started by an MPI launcher, without importing mpi4py.

True if a per-rank variable of a common launcher is set (Open MPI, MPICH, Intel MPI, PMIx/srun, MVAPICH2, Hydra, Cray ALPS/PALS; see :data:LAUNCHER_VARIABLES), or if mpi4py is already imported and MPI initialized (using it then costs nothing more). MAYBEMPI=1/0 overrides the detection, e.g. for a launcher whose variables are not known.

Returns

bool
Whether the process belongs to an MPI job.

launcher_variablefunction#

def launcher_variable() -> str | None

Return the first variable of :data:LAUNCHER_VARIABLES that is set, if any.

Useful to see why :func:launched_under_mpi decided as it did.

Returns

str | None
The name of the variable, or None if none is set.

local_rankfunction#

def local_rank() -> int

Return the rank of this process within its node, from the launcher’s environment.

Reads the node-local rank that common launchers export (Open MPI, MVAPICH2, Intel MPI/MPICH, PMI, Cray PALS, Slurm, LOCAL_RANK, see :data:LOCAL_RANK_VARIABLES). These are set before MPI_Init, so this works before MPI is initialized and without importing mpi4py.

Returns

int
The node-local rank, or 0 if no launcher variable is set (a serial run).

set_copy_hookfunction#

def set_copy_hook(hook: Callable[[str, Any], None] | None) -> None

Report copies between device and host arrays in buffer collectives.

A receive into a host array from a device array (one with .get(), e.g. a CuPy array), or the other way round, is a transfer that an application may want to count. The hook is called after each such copy.

Parameters

NameTypeDescription
hookCallable[[str, Any], None] | NoneCalled as hook(kind, array) with kind "to_host" or "to_device" and the host array that was copied. None removes the hook.