tbplas.MPIEnv

class tbplas.MPIEnv(enable_mpi: bool = False, echo_details: bool = False)

Wrapper over MPI4PY APIs.

__comm

default global mpi communicator

Type:

‘mpi4py.MPI.Intracomm’ class

__rank

id of this process in mpi communicator

Type:

integer

__size

number of processes in mpi communicator

Type:

integer

__init__(enable_mpi: bool = False, echo_details: bool = False) None
Parameters:
  • enable_mpi – whether to enable parallelization using MPI

  • echo_details – whether to report parallelization details

Returns:

None

Methods

__init__([enable_mpi, echo_details])

param enable_mpi:

whether to enable parallelization using MPI

all_average(data_local)

Average results over random samples broadcast to all process.

all_reduce(data_local)

Reduce local data and broadcast to all processes.

average(data_local)

Average results over random samples and store results to master process.

barrier()

Wrapper for self.comm.Barrier.

bcast(data_local)

Broadcast data from master to other processes.

dist_bound(n_max)

Same as dist_range, but returns the lower and upper bounds.

dist_list(raw_list[, algorithm])

Distribute a list over processes.

dist_range(n_max)

Distribute range(n_max) over processes.

log([event, fmt])

Log the date and time of event.

print([text])

Print text on master process.

reduce(data_local)

Reduce local data to master process.

Attributes

is_master

Determine whether this is the master process.

mpi_enabled

Determine whether MPI is enabled.

rank

Interface for the '__rank' attribute.

size

Interface for the '__size' attribute.

__init__(enable_mpi: bool = False, echo_details: bool = False) None
Parameters:
  • enable_mpi – whether to enable parallelization using MPI

  • echo_details – whether to report parallelization details

Returns:

None

all_average(data_local: ndarray) ndarray

Average results over random samples broadcast to all process.

Parameters:

data_local – local results on each process

Returns:

averaged data from data_local

all_reduce(data_local: ndarray) ndarray

Reduce local data and broadcast to all processes.

Parameters:

data_local – local results on each process

Returns:

summed data from data_local

average(data_local: ndarray) ndarray

Average results over random samples and store results to master process.

Parameters:

data_local – local results on each process

Returns:

averaged data from data_local

barrier() None

Wrapper for self.comm.Barrier.

bcast(data_local: ndarray) None

Broadcast data from master to other processes.

Parameters:

data_local – local results on each process

Returns:

None

dist_bound(n_max: int) Tuple[int, int]

Same as dist_range, but returns the lower and upper bounds. Both of the bounds are close, i.e. [i_min, i_max].

Parameters:

n_max – upper bound of range

Returns:

lower and upper bounds of subrange assigned to this process

dist_list(raw_list: List[Any], algorithm: str = 'range') List[Any]

Distribute a list over processes.

Parameters:
  • raw_list – raw list to distribute

  • algorithm – distribution algorithm, should be either “remainder” or “range”

Returns:

sublist assigned to this process

dist_range(n_max: int) range

Distribute range(n_max) over processes.

Parameters:

n_max – upper bound of the range

Returns:

subrange assigned to this process

log(event: str = '', fmt: str = '%x %X') None

Log the date and time of event.

Parameters:
  • event – notice of the event

  • fmt – date and time format

Returns:

None.

print(text: str = '') None

Print text on master process.

NOTE: flush=True is essential for some MPI implementations, e.g. MPICH3.

Parameters:

text – text to print

Returns:

None

reduce(data_local: ndarray) ndarray

Reduce local data to master process.

Parameters:

data_local – local results on each process

Returns:

summed data from data_local

__weakref__

list of weak references to the object (if defined)

property is_master: bool

Determine whether this is the master process.

property mpi_enabled: bool

Determine whether MPI is enabled.

property rank: int

Interface for the ‘__rank’ attribute.

Returns:

rank of this MPI process

property size: int

Interface for the ‘__size’ attribute.

Returns:

number of MPI processes