pydmqmc.utils.ParallelHelper

class pydmqmc.utils.ParallelHelper(shape)

Bases: object

Helper for coordinating parallel Methods.

Parameters:
shapeint or tuple of ints

The size of the arrays to be distributed among processors.

Attributes

bufshape

Shape of the buffers for this processor.

bufsize

Buffer size for this processor.

comm

MPI communicator.

imax

Maximum index for this processor.

imin

Minimum index for this processor.

is_root

Whether this is the parent processor.

parallel

Whether running in parallel mode.

rank

Rank of this processor.

root

Root processor rank.

size

Total number of processors.

Methods

allocate_reduce_buffers()

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_reduce_buffers()

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

bufshape

Shape of the buffers for this processor.

bufsize

Buffer size for this processor.

comm

MPI communicator.

imax

Maximum index for this processor.

imin

Minimum index for this processor.

is_root

Whether this is the parent processor.

parallel

Whether running in parallel mode.

rank

Rank of this processor.

root

Root processor rank.

size

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.