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.

Module Summary

functions:

underworld.mpi.barrier Creates an MPI barrier.

classes:

underworld.mpi.call_pattern This context manager calls the code within its block using the specified calling pattern.

Module Details

functions:

underworld.mpi.barrier()[source]

Creates an MPI barrier. All processes wait here for others to catch up.

classes:

class underworld.mpi.call_pattern(pattern='collective', returnobj=None)[source]

Bases: object

This 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