pybnb.mpi_utils¶
Various utility function for MPI.
Copyright by Gabriel A. Hackebeil (gabe.hackebeil@gmail.com).
- class pybnb.mpi_utils.Message(comm)[source]¶
A helper class for probing for and receiving messages. A single instance of this class is meant to be reused.
- Parameters
comm (
mpi4py.MPI.Comm
) – The MPI communicator to use.
- recv(datatype=None, data=None)[source]¶
Complete the receive for the most recent message probe and return the data as a numeric array or a string, depending on the datatype keyword.
- Parameters
datatype ({
mpi4py.MPI.DOUBLE
,mpi4py.MPI.CHAR
}, optional) – An MPI datatype used to interpret the received data. If None,mpi4py.MPI.DOUBLE
will be used. (default: None)data (array.array or None, optional) – An existing data array to store data into. If None, one will be created. (default: None)
- pybnb.mpi_utils.recv_nothing(comm, status)[source]¶
A helper function for receiving an empty message. This function is not thread safe.
- Parameters
comm (
mpi4py.MPI.Comm
) – An MPI communicator.status (
mpi4py.MPI.Status
) – An MPI status object that has been populated with information about the message to be received via a probe. If None, a new status object will be created and an empty message will be expected from any source with any tag. (default: None)
- Returns
status – If the original status argument was not None, it will be returned after being updated by the receive. Otherwise, the status object that was created will be returned.
- Return type
mpi4py.MPI.Status
- pybnb.mpi_utils.send_nothing(comm, dest, tag=0)[source]¶
A helper function for sending an empty message with a given tag. This function is not thread safe.
- Parameters
comm (
mpi4py.MPI.Comm
) – An MPI communicator.dest (int) – The process rank to send the message to.
tag (int, optional) – A valid MPI tag to use for the message. (default: 0)
- pybnb.mpi_utils.recv_data(comm, status, datatype, out=None)[source]¶
A helper function for receiving numeric or string data sent using the lower-level buffer-based mpi4py routines.
- Parameters
comm (
mpi4py.MPI.Comm
) – An MPI communicator.status (
mpi4py.MPI.Status
) – An MPI status object that has been populated with information about the message to be received via a probe.datatype (
mpi4py.MPI.Datatype
) – An MPI datatype used to interpret the received data. If the datatype ismpi4py.MPI.CHAR
, the received data will be converted to a string.out (buffer-like object, optional) – A buffer-like object that is compatible with the datatype argument and can be passed to comm.Recv. Can only be left as None when the datatype is
mpi4py.MPI.CHAR
.
- Returns
- Return type
string or user-provided data buffer
- for ... in pybnb.mpi_utils.dispatched_partition(comm, items, root=0)[source]¶
A generator that partitions the list of items across processes in the communicator. If the communicator size is greater than 1, the root process will be yielded no items and instead will serve them dynamically by sending list indices to workers as work requests are received.
- Parameters
comm (
mpi4py.MPI.Comm
or None) – An MPI communicator or None in the serial processing case.items (list) – The list of items to partition. This This function assumes each process has an identical copy of the items list. Therefore, items in the list are not transferred (only indices).
root (integer, optional) – An integer indicating which process rank should be designated as the dispatcher. (default: 0)
- Returns
- Return type
string or user-provided data buffer