MPI-tools#

This module contains a number of handy functions for MPI functionality.

Under normal circumstances you shouldn’t have to use any of the methods in here if you use the run module to run GPry.

mpi.get_random_generator(seed=None)[source]#

Generates seed sequences for processes running in parallel.

Parameters:

seed (int or numpy seed, or numpy.random.Generator, optional (default=None)) – A random seed to initialise a Generator, or a Generator to be used directly. If none is provided a random one will be drawn.

mpi.bcast(args, root=0)[source]#

Wrapper for MPI.comm.bcast, that works if MPI not present.

mpi.gather(args, root=0)[source]#

Wrapper for MPI.comm.gather, that works if MPI not present.

mpi.allgather(args)[source]#

Wrapper for MPI.allgather, that works if MPI not present.

mpi.split_number_for_parallel_processes(n, n_proc=1)[source]#

Splits a number of atomic tasks n between the parallel processes.

If n is not divisible by the number of processes, processes with lower rank are preferred, e.g. 5 tasks for 3 processes are assigned as [2, 2, 1].

Parameters:
  • n (int) – The number of atomic tasks

  • n_proc (int, optional (default=number of MPI comm's)) – The number of processes to divide the tasks between

Return type:

An array with the number of tasks corresponding each process.

mpi.step_split(values)[source]#

Broadcasts from rank=0 and splits array between MPI processes, using mpi.size as step.

If starting from sorted arrays, it preserves “computational scaling” among processes, but producing similar-in-content partial arrays.

mpi.merge_step_split(values)[source]#

Gather step-split (with ::mpi.SIZE) arrays and returns the merged set for the rank=0 process (None for the rest).

mpi.multi_gather_array(arrs)[source]#

Gathers (possibly a list of) arrays from all processes into the main process.

NB: mpi-gather guarantees rank order is preserved.

Parameters:

arrs (array-like) – The arrays to gather

Return type:

The gathered array(s) from all processes

mpi.sync_processes()[source]#

Makes all processes halt here until all have reached this point.

mpi.share_attr(instance, attr_name, root=0)[source]#

Broadcasts attr of instance from process of rank root.

mpi.compute_y_parallel(gpr, X, y, sigma_y, ensure_sigma_y=False)[source]#

Computes the GPR mean (and std if do_sigma_y=True) in parallel.

Returns the resulting (y, sigma_y) arrays (computed or given) for rank 0, and None otherwise.