What is MPI?

MPI stands for the Message Passing Interface. It is a standard define and maintain by the MPI Forum used for parallel and/or distributed computing. MPI addresses primarily the message-passing parallel programming model, in which data is moved from the address space of one process to that of another process through cooperative operations on each process. The MPI standard (MPI-1, MPI-2, MPI-3 and MPI-4) defines syntax and semantics of library routines useful for users writing portal message-passing programs in varies programming languages. The primary goals of MPI are high efficiency, functionality and portability.

The MPI standard includes but not limit to:

  • Point-to-point communication
  • Datatypes
  • Collective operations
  • Process groups
  • Communication contexts

What is MPICH?

MPICH is a freely available, high performance and widely portable implementation of Message Passing Interface(MPI), a standard for message-passing libraries for distributed-memory applications used in parallel computing.

What does MPICH stands for?

MPI stands for Message Passing Interface. The CH comes from Chameleon, the portability layer used in the original MPICH to provide portability to the existing message-passing systems.

What is the different between MPICH1, MPICH2 and MPICH (v3)?

MPICH1 implemented MPI-1 standard while MPICH2 is an all-new the implementation of MPI standard, with implementations of MPI-1 and MPI-2 functionality. MPICH2 includes additional features supporting one-side communication, dynamic processes, intercommunicator collective operations, and expanded MPI-IO functionality.

Start from November 2012, the MPICH2 project is renamed back to MPICH with a version number of 3.0. MPICH 3.x implements MPI-3 standard while MPICH 4.x implements MPI-4 standard.

How to use MPICH?

On HPC2021, you can set the required environment variables and path by loading the module.

HPC2021 system
MPICH version Compiler module command
3.4.2 INTEL Compiler 2021 module load mpich/intel/3.4.2-intel2021
GNU Compiler (GCC) 8.3.1 module load mpich/gcc/3.4.2-gcc8.3.1
4.1.2 INTEL Compiler 2023 module load mpich/intel/4.1.2
GNU Compiler (GCC) 12.3 module load mpich/gcc/4.1.2-gcc12.3

To know which MPI compiler you are using, you may type command:

$ mpicc -v

Compiling MPI program

Ensure suitable PATH of MPICH version you would like to use is defined in your ~/.bashrc file or load the module.

For MPI C/C++ programs :

$ mpicc program.c -o program.exe

or

$ mpic++ program.cpp -o program.exe

For MPI Fortran 77 or Fortran 90 programs:

$ mpif77 program.f -o program.exe

or

$ mpif90 program.f90 -o program.exe

Running MPICH program

(A) Interactive run (for short job testing):

$ mpirun -np 20 ./program.exe

(B) Sample MPICH SLURM script for batch run:

#!/bin/bash 
#SBATCH --job-name=test_mpi
#SBATCH --nodes=2
#SBATCH --ntasks=10
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=1G
#SBATCH --time=0-00:10:00
#SBATCH --output=output.log
#SBATCH --error=error.log

cd ${SLURM_SUBMIT_DIR}
# Load the environment for MPICH (Intel compiler as an example here)
module load mpich/gcc/4.1.2-gcc12.3

# run the program supporting MPI with the "mpirun" command 
# The -n option is not required since mpirun will automatically determine from SLURM settings
mpirun ./program.exe

Additional Information

MPICH Homepage: http://www.mpich.org/‎
MPICH user guide and tutorial: http://www.mpich.org/documentation/guides/
MPI Programming Self-learn tutorial