MPI for Python

An Implementation of MPI Bindings for Python


MPI for Python (mpi4py) is an implementation of language bindings for python of the MPI parallel computing framework. The package allows access to MPI function calls and allows the user to leverage multiple processors to run their code natively in Python without having to use other bindings for MPI such as C or Fortran.

Using MPI for Python on RCC Resources

MPI for Python is a native python library which allows access to the MPI framework for parallel programming. In order to run MPI for Python, first, the GNU OpenMPI module should be loaded. Then, once your code has been written, you can run the python code using the mpirun command. For example, if you want to run a code with 4 processors:

module load gnu-openmpi
mpirun -np 4 python

Running MPI for Python with Slurm

MPI for Python codes can also be run on the compute nodes using a Slurm submit script. A short example of one might be the following using 4 processors again. For good examples and tutorials and test codes, refer to the users manual as it has both documentation and a good set of tutorials.


#SBATCH -p genacc_q
#SBATCH -n 4
#SBATCH -t 00:10:00
#SBATCH --mail-type=ALL

module load gnu-openmpi
mpirun -np 4 python