pydmqmc.utils.ParallelHelper
- class pydmqmc.utils.ParallelHelper(shape)
Bases:
objectHelper for coordinating parallel Methods.
- Parameters:
- shapeint or tuple of ints
The size of the arrays to be distributed among processors.
Attributes
Shape of the buffers for this processor.
Buffer size for this processor.
MPI communicator.
Maximum index for this processor.
Minimum index for this processor.
Whether this is the parent processor.
Whether running in parallel mode.
Rank of this processor.
Root processor rank.
Total number of processors.
Methods
Allocate send and receive buffers for communication.
allreduce_sum(array)Allreduce an array across all processors.
broadcast(array)Broadcast an array from the root processor.
get_rng_seed([rng_seed])Work out the rng seed for the calling processor.
print([text])Print text only from the parent processor.
safe_noncollective(func, *args, **kwargs)Run a function that returns a 2D array on the root rank in a deadlock safe way.
- __init__(shape)
Methods
__init__(shape)Allocate send and receive buffers for communication.
allreduce_sum(array)Allreduce an array across all processors.
broadcast(array)Broadcast an array from the root processor.
get_rng_seed([rng_seed])Work out the rng seed for the calling processor.
print([text])Print text only from the parent processor.
safe_noncollective(func, *args, **kwargs)Run a function that returns a 2D array on the root rank in a deadlock safe way.
Attributes
Shape of the buffers for this processor.
Buffer size for this processor.
MPI communicator.
Maximum index for this processor.
Minimum index for this processor.
Whether this is the parent processor.
Whether running in parallel mode.
Rank of this processor.
Root processor rank.
Total number of processors.
- allocate_reduce_buffers()
Allocate send and receive buffers for communication.
- allreduce_sum(array)
Allreduce an array across all processors.
- Parameters:
- arraynp.array
The array to be reduced. All processors will be updated with the reduced values. It must have the same shape as the bufshape attribute.
- Returns:
- arraynp.array
The reduced array. All processors will contain the reduced values.
- broadcast(array)
Broadcast an array from the root processor.
- Parameters:
- arraynp.array
The array to be broadcast. On the root processor, this contains the data to be sent. On other processors, this will be updated with the broadcast data.
- Returns:
- arraynp.array
The broadcasted array. All processors will have the same data after the broadcast.
- get_rng_seed(rng_seed=None)
Work out the rng seed for the calling processor.
If on the root, also report the rng seeds for all processors.
- Parameters:
- rng_seedint or array_like of ints
The user provided initial rng seed.
- Returns:
- seedint or array_like of ints
The rng seed(s) to use for the NumPy generator, which should be rank and calculation safe.
- print(text='')
Print text only from the parent processor.
- Parameters:
- textstr
The text to print.
- safe_noncollective(func, *args, **kwargs)
Run a function that returns a 2D array on the root rank in a deadlock safe way.
If an exception is raised on the active rank then this is caught and raised collectively.
- Parameters:
- func: function
The operation to be performed on a single rank. It must return a 2D array when working correctly.
- *args, **kwargs:
Arguments for the function.
- Returns:
- Any
The result of
func, broadcasted to all ranks.
- property bufshape
Shape of the buffers for this processor.
- property bufsize
Buffer size for this processor.
- property comm
MPI communicator.
- property imax
Maximum index for this processor.
- property imin
Minimum index for this processor.
- property is_root
Whether this is the parent processor.
- property parallel
Whether running in parallel mode.
- property rank
Rank of this processor.
- property root
Root processor rank.
- property size
Total number of processors.