Source code for tracesuite.mpi_helper

# DLR, Institute of Propulsion Technology
# Linder Hoehe
# 51147 Cologne
# Germany
#
# Copyright (c) 2019 DLR
#
"""Module providing additional convenience methods to handle issues around MPI."""
from __future__ import annotations

import typing

from mpi4py import MPI






[docs] def is_master(comm: MPI.Comm = MPI.COMM_WORLD) -> bool: """Return if this process master on a given communicator.""" return comm.Get_rank() == 0
[docs] def is_single_process(comm: MPI.Comm = MPI.COMM_WORLD) -> bool: """Return if there is only one process in the communicator.""" return comm.Get_size() == 1
[docs] def get_rank(comm: MPI.Comm = MPI.COMM_WORLD) -> int: """Get the rank of this process on a given communicator.""" return comm.Get_rank()
[docs] def broadcast(obj: typing.Any, root: int, comm: MPI.Comm = MPI.COMM_WORLD) -> typing.Any: # noqa: ANN401 (mpi4py.typing only available if mpi4py > 4) """Broadcast object from root to all members of comm.""" return comm.bcast(obj, root=root)
[docs] def barrier(comm: MPI.Comm = MPI.COMM_WORLD) -> None: """Wait for all processes in comm.""" comm.Barrier()