PAOFLOW.utils.communication#
Attributes#
Functions#
|
Compute start and stop indices for a simple 1-D load-balanced partition. |
|
Compute scatter/gather layout for all MPI ranks. |
|
Scatter the first dimension of an array to all MPI ranks. |
|
Gather local sub-arrays into a full array on |
|
Scatter the first dimension of an array using a chunked pool strategy. |
|
Gather local sub-arrays from all ranks using a chunked pool strategy. |
|
Redistribute an array so that |
|
Create a shared-memory window containing a copy of |
Module Contents#
- PAOFLOW.utils.communication.load_balancing(size, rank, n)[source]#
Compute start and stop indices for a simple 1-D load-balanced partition.
- PAOFLOW.utils.communication.load_sizes(size, n, dim)[source]#
Compute scatter/gather layout for all MPI ranks.
- Parameters:
- Returns:
Row
icontains:sizes[i, 0]— number of scalar elements on ranki(first-dimension count timesdim).sizes[i, 1]— scalar offset in the flat array where ranki’s sub-array begins.sizes[i, 2]— first-dimension count on ranki.
- Return type:
np.ndarray, shape
(size, 3), int
- PAOFLOW.utils.communication.scatter_array(arr, sroot=0)[source]#
Scatter the first dimension of an array to all MPI ranks.
- Parameters:
arr (np.ndarray or None) – Array to scatter (only significant on
sroot). The first dimension is distributed; all remaining dimensions are replicated.sroot (int, optional) – Rank of the process that holds the data to scatter (default
0).
- Returns:
Local sub-array for this rank. The first dimension has size determined by
load_sizes(); remaining dimensions are identical to those ofarr.- Return type:
np.ndarray
Notes
Uses
MPI.Scattervfor variable-count scatter so that the array does not need to be exactly divisible by the number of ranks. Shape and dtype are broadcast fromsrootbefore the transfer.
- PAOFLOW.utils.communication.gather_array(arr, arraux, sroot=0)[source]#
Gather local sub-arrays into a full array on
sroot.- Parameters:
arr (np.ndarray or None) – Destination array on rank
sroot(only written onsroot). Its shape must match the result of gathering allarrauxsub-arrays along the first dimension.arraux (np.ndarray) – Local sub-array on this rank.
sroot (int, optional) – Rank that collects the gathered result (default
0).
- Returns:
The result is written directly into
arronsroot.- Return type:
None
Notes
Uses
MPI.Gathervwith offsets computed fromload_sizes(). The layout is consistent withscatter_array().
- PAOFLOW.utils.communication.scatter_full(arr, npool, sroot=0)[source]#
Scatter the first dimension of an array using a chunked pool strategy.
- Parameters:
- Returns:
Local sub-array on this rank, sized according to
load_balancing().- Return type:
np.ndarray
Notes
Internally delegates to
scatter_array()for each pool chunk to keep individual MPI message sizes manageable.
- PAOFLOW.utils.communication.gather_full(arr, npool, sroot=0)[source]#
Gather local sub-arrays from all ranks using a chunked pool strategy.
- Parameters:
- Returns:
Assembled array on
sroot;Noneon all other ranks.- Return type:
np.ndarray or None
Notes
Internally delegates to
gather_array()for each pool chunk. The inverse operation ofscatter_full().
- PAOFLOW.utils.communication.gather_scatter(arr, scatter_axis, npool)[source]#
Redistribute an array so that
scatter_axisis the distributed axis.- Parameters:
arr (np.ndarray) – Array to redistribute. All ranks hold an identical copy on entry.
scatter_axis (int) – Axis along which the output will be scattered across ranks.
npool (int) – Number of pools passed to the underlying
scatter_full()/gather_full()calls.
- Returns:
Sub-array for this rank, with
scatter_axisdistributed.- Return type:
np.ndarray
Notes
This is useful when a computation requires a different distribution axis than the one provided by an earlier
scatter_full()call. Each rank first gathers the slices it needs, then the process withrank == rcallsgather_full()withsroot=rin a loop over all ranks.
- PAOFLOW.utils.communication.gen_window(array, root=0)[source]#
Create a shared-memory window containing a copy of
array.- Parameters:
array (np.ndarray or None) – Array to place in shared memory (only significant on
root).root (int, optional) – Rank that owns the source data (default
0).
- Returns:
View into the shared-memory buffer. All ranks on the same compute node can read the data without additional communication after the initial barrier.
- Return type:
np.ndarray
Notes
Uses
MPI.Win.Allocate_sharedto create a one-sided memory window. Non-root ranks allocate zero bytes; the data pointer is obtained on all ranks viaShared_query(0).