underworld.mpi module
This module contains routines related to parallel operation via the Message Passing Interface (MPI).
Attributes
- comm :: mpi4py.MPI.Intracomm
The MPI communicator.
- rank :: int
The rank of the current process.
- size :: int
The size of the pool of processes.
Functions
Creates an MPI barrier. |
Classes
This context manager calls the code within its block using the specified calling pattern. |
- underworld.mpi.barrier()[source]
Creates an MPI barrier. All processes wait here for others to catch up.
- class underworld.mpi.call_pattern(pattern='collective', returnobj=None)[source]
Bases:
objectThis context manager calls the code within its block using the specified calling pattern.
- Parameters:
pattern (str) – ‘collective’, each process calls the block of code simultaneously. ‘sequential’, processes call block of code in order of rank.
Example
This example is redundant as it will only run with a single process. However, where run in parallel, you should expect the outputs to be ordered according to process rank. Note also that for deterministic printing in parallel, and you may need to run Python unbuffered (mpirun -np 4 python -u yourscript.py, for example).
>>> import underworld as uw >>> with uw.mpi.call_pattern(pattern="sequential"): ... print("My rank is {}".format(uw.mpi.rank)) My rank is 0