Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

MPI in Python: mpi4py

mpi4py provides MPI bindings to the Python programming language. This document provides instructions for using mpi4py on the FAS cluster at Harvard University.

Installing mpi4py

We recommend the Mambaforge Python distribution. The latest version is available with the python/3.10.9-fasrc01 software module. Since mpi4py is not available with the default module you need to install it in your user environment.

The most straightforward way to install mpi4py in your user space is to create a new conda environment with the mpi4py package. For instance, you can do something like the below:

module load python/3.10.12-fasrc01 
mamba create -n python3_env1 python numpy pip wheel mpi4py
source activate python3_env1  

This will create a conda environment named python3_env1 with the mpi4py package and activate it. It will also install a MPI library required by mpi4py. By default, the above commands will install MPICH.

For most of the cases the above installation procedure should work well. However, if your workflow requires a specific flavor and/or version of MPI, you could use pip to install mpi4py in your custom conda environment as detailed below:

  • Load compiler and MPI software modules:
module load gcc/12.2.0-fasrc01
module load openmpi/4.1.5-fasrc03

This will load OpenMPI in your user environment. You can also look at our user documentation to learn more about software modules on the FAS cluster.

  • Load a Python module:
module load python/3.10.12-fasrc01
  • Create a conda environment:
mamba create -n python3_env2 python numpy pip wheel
  • Install mpi4py with pip:
pip install mpi4py
  • Activate the new environment:
source activate python3_env2

Running mpi4py

Now that you have successfully installed mpi4py in your environment you can try some examples!

References