irradiapy.utils.mpi module

Utilities for MPI-related functionalities.

class irradiapy.utils.mpi.MPIExceptionHandlerMixin[source]

Bases: object

Provides a common MPI exception handler method when mpi_safe_method cannot be used.

This is useful for __init__ and __post_init__ methods where decorators cannot be applied because self.comm and self.rank are not yet defined before the function is called. You can use this method after the comm and rank attributes are initialized in a try/except block.

class irradiapy.utils.mpi.MPITagAllocator[source]

Bases: object

A class to allocate unique tags for processes.

classmethod get_tag()[source]

Get a unique tag for the current process.

Warning

This method should not be called in a statement that is only executed by one rank, such as in if rank == 0:. It is designed to be called by all ranks to ensure that all ranks receive the same tag.

Return type:

int

irradiapy.utils.mpi.ap_rm_file(original, target, comm)[source]

Append content from original to target and delete original.

Return type:

None

irradiapy.utils.mpi.broadcast_variables(root, comm, *variables)[source]

Broadcasts variables.

Parameters:
  • root (int) – The rank of the process that will broadcast the variables.

  • comm (Comm) – The MPI communicator.

  • variables (Any) – Variables to broadcast.

Returns:

The broadcasted variables.

Return type:

list[Any]

irradiapy.utils.mpi.cp_file(original, target, comm)[source]

Copy a file from original to target, overwriting target if it exists.

Return type:

None

irradiapy.utils.mpi.mpi_safe_method(method)[source]

Decorator that wraps an MPI-using method so any exception prints a traceback with the current rank and then calls MPI.Abort.

The method should be a member of a class that has comm and rank attributes.

Return type:

Callable[..., Any]

irradiapy.utils.mpi.mpi_subdomains_decomposition(n)[source]

Factor n into three integers nx, ny, nz for MPI decomposition into subdomains.

nx, ny and nz are such that: - nx * ny * nz == n - the maximum of (nx, ny, nz) divided by the minimum is as small as possible.

Parameters:

n (int) – The number of processes to decompose into subdomains.

Returns:

A tuple containing the number of subdomains in the x, y, and z directions.

Return type:

tuple[int, int, int]

irradiapy.utils.mpi.mv_file(original, target, comm)[source]

Move a file from original to target, overwriting target if it exists.

Return type:

None

irradiapy.utils.mpi.rm_file(path, comm)[source]

Remove a file.

Return type:

None