Mondaic

salvus.mesh.algorithms.distributed_mesh.mpi_communication

salvus.mesh.algorithms.distributed_mesh.mpi_communication salvus mesh algorithms distributed_mesh mpi_communication

MPI broadcast and scatter utilities for Salvus meshes.

Functions

broadcast_mesh()

def broadcast_mesh(mesh: Mesh | None, comm: int, root: int) -> Mesh: ...

Broadcast a Mesh from the root rank to all other ranks.

This function broadcasts a Salvus Mesh efficiently by transferring each numpy array individually, avoiding memory duplication on the root rank that would occur with full serialization. Scalar values and non-array objects are serialized using dill.

Parameters
  • mesh Mesh | None — The Mesh to broadcast. Only needs to be valid on the root rank; can be None on other ranks.
  • comm int — MPI communicator handle.
  • root int — The rank that holds the mesh to broadcast.
Returns Mesh — The broadcasted Mesh on all ranks.

scatter_meshes()

def scatter_meshes(
    meshes: list[Mesh] | None, comm: int, root: int
) -> Mesh: ...

Scatter a list of Meshes from the root rank, one mesh per rank.

On the root rank, meshes must be a list of length comm_size; rank i receives meshes[i]. The meshes may have completely different structure (different number of blocks, different field keys, different array shapes).

The implementation uses point-to-point send/recv rather than bindings.mpi.scatter. This will cause an efficient transfer of numpy arrays but it is a manual loop over ranks instead of a built-in MPI scatter.

Parameters
  • meshes list[Mesh] | None — On the root rank, a list of meshes of length equal to the communicator size; ignored on other ranks.
  • comm int — MPI communicator handle.
  • root int — The rank that holds the list of meshes to scatter.
Returns Mesh — The mesh assigned to the local rank.