mpiutils

MPI utility class function.

class shift.mpiutils.MPI[source]
wait()[source]

Tells all jobs to wait – to ensure jobs are synchronised.

set_loop(loop_size)[source]

Sets the size of a distributed loop.

Parameters:

loop_size (int)

Yields:

Size of the MPI_loop.

mpi_ind2ind(mpi_ind)[source]

Converts the MPI_ind of a distributed loop to the index of a full loop.

Parameters:

mpi_ind (int)

Yields:

Index of a full loop.

clean_loop()[source]

Gets ride of loop_size definition.

split(length, size=None)[source]

For splitting an array across nodes.

Parameters:
  • Length (int) – Length of the array to be split.

  • size (int) – Size of the MPI.size (i.e. MPI task), if set then this will be used to be split for other reasons.

Returns:

  • split1 (array_like) – The indices of the first element of the split array.

  • split2 (array_like) – The indices of the last element of the split array.

split_array(array)[source]

Returns the values of the split array.

Parameters:

array (array_like) – Array to be split.

Yields:

Split array.

check_partition(NDshape, NDshape_split)[source]

Returns a boolean array showing the axes that an array will be split along.

Parameters:
  • NDshape (list) – The shape of the N-dimensional array.

  • NDshape_split (list) – The shape of the N-dimensional split array.

Yields:

Boolean array showing whether array will not be split along a said axes.

mpi_print(*value)[source]

Python print function using flush=True so print statements are outputed immediately in an MPI setting.

mpi_print_zero(*value)[source]

Prints only at node rank = 0.

send(data, to_rank=None, tag=11)[source]

Sends data from current core to other specified or all cores.

Parameters:
  • data (array) – Data to send.

  • to_rank (int, optional) – Specify rank to send data to, or leave as None to send to all cores.

  • tag (int, optional) – Sending tag to ensure the right data is being transfered.

recv(from_rank, tag=11)[source]

Receive data from another node.

Parameters:
  • from_rank (int) – Source of the data.

  • tag (int) – Sending tag to ensure the right data is being transfered.

Returns:

data – Data received.

Return type:

array

broadcast(data)[source]

Broadcast data from rank=0 to all nodes.

send_up(data)[source]

Send data from each node to the node above.

isend_up(data)[source]

Send data from each node to the node above (rank+1, wrapping around).

send_down(data)[source]

Send data from each node to the node below.

isend_down(data)[source]

Send data from each node to the node below (rank-1, wrapping around).

collect(data, outlist=False)[source]

Collects a distributed data to the processor with rank=0.

Parameters:
  • data (array) – Distributed data set.

  • outlist (bool, optional) – If outlist is False, we collect and concatenate, if True then we do not concatenate the list.

collect_noNone(data)[source]

Same as collect function, but removes data=None to the combined data set. :param data: Distributed data set. :type data: array

distribute(data)[source]

Distribute and split data from rank 0.

Parameters:

data (array) – Full data set which will be split across the cores.

sum(data)[source]

Sums a distributed data set to the processor with rank=0.

Parameters:

data (array) – distributed data set.

mean(data)[source]

Finds the mean of a distributed data set, which is broadcasted to all nodes.

Parameters:

data (array) – distributed data set.

min(data)[source]

Finds the minimum of a distributed data set, which is broadcasted to all nodes.

Parameters:

data (array) – distributed data set.

max(data)[source]

Finds the maximum of a distributed data set, which is broadcasted to all nodes.

Parameters:

data (array) – distributed data set.

end()[source]

Ends MPI environment.