Setting Up MPI

On a Remote Cluster

Refer to the instructions from your site, for example UVA Research Computing for our local environment. Nearly always, you will be required to prepare your code and run it through a resource manager such as Slurm.

For Python, you will need to install mpi4py. You may wish to create a conda environment for it. On the UVA system you must use pip rather than conda.

module load gcc openmpi
module load anaconda
pip install --user mpi4py

On a Local Computer

If you have access to a multicore computer, you can run MPI programs on it.

If using a compiled language, before you can build MPI codes you must install a compiler, and possibly some kind of IDE. See our guides for C++ or Fortran.

For Python, on all operating systems install mpi4py. To install mpi4py you must have a working mpicc compiler. If you use conda or mamaba from a distribution like miniforge, the required compiler will be installed as a dependency. For pip installations you must provide your own compiler setup.

The author of mpi4py recommends using pip even with a conda environment. This command will be similar on a local system to that used for installation on a multiuser system.

python -m pip install mpi4py

This may avoid some issues that occasionally arise in prebuilt mpi4py packages. Be sure that an appropriate mpicc executable is in the path. Alternatively, use the conda-forge channel (recommended in general for most scientific software).

Linux

Parallel programs are most frequently used in a high-performance computing environment such as the clusters we have discussed, but many multicore workstations are available that can run Linux and many parallel programmers are familiar with this environment. The simplest way to install MPI is to use a precompiled version for your distribution and compiler.

GCC The recommended MPI distribution is OpenMPI. Most distributions provide a package.

Intel oneAPI Installing the HPC Toolkit will also install IntelMPI.

NVIDIA HPC SDK The NVIDIA software ships with a precompiled version of OpenMPI.

The headers and libraries for MPI must match. Using a header from one MPI and libraries from another, or using headers from a version from one compiler and libraries from a different compiler, usually results in some difficult-to-interpret bugs. Moreover, the process manager must be compatible with the MPI used to compile the code. Because of this, if more than one compiler and especially more than one MPI version is installed, the use of modules ( environment modules or lmod) becomes particularly beneficial. Both Intel and NVIDIA provide scripts for the environment modules package (lmod can also read these), with possibly some setup required. If you plan to use mpi4py as well as compiled-language versions, creating a module for your Python distribution would also be advisable.

Mac OS

GCC Installing homebrew is the simplest way to set up MPI on a Mac. Install the gcc package followed by the open-mpi package.

Intel oneAPI Install the HPC Toolkit for IntelMPI.

NVIDIA HPC SDK The NVIDIA suite is not available for Mac OS.

Windows

GCC The simplest way to use OpenMPI on Windows is through Cygwin. In this case, the gcc compiler suite would first be installed, with g++ and/or gfortran added. Then the openmpi package could also be installed through the cygwin package manager.

Intel oneAPI Install the HPC Toolkit.

NVIDIA HPC_SDK Download the package when it is available.

MPI codes must generally be compiled and run through a command line on Windows. Cygwin users can find a variety of tutorials online, for example here.

The Intel oneAPI Basic Toolkit includes a customized command prompt in its folder in the Apps menu.

Previous
Next