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 and MPI-3) defines syntax ans 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 nack to MPICH with a version number of 3.0. MPICH (v3) implements MPI-3 standard which contains significant extensions to MPI functionality, including non-blocking collectives, new one-sided communication operators, and Fortran 2008 bindings.
Which MPI version to use?
MPI-3 is the latest version of MPI standard. It includes new Fortran 2008 bindings while it removes deprecated C++ bindings and deprecated routines and MPI objects. We suggest you use MPI-3 since better solutions were provided with newer versions of MPI.
MPICH2 replaces MPICH1 and should be used instead of MPICH1 except for the case users requiring the communication of heterogeneous data representations (e.g., different lengths for integers or different byte ordering).
How to use MPICH?
On HPC2021, you can set the required environment variables and path by loading the module.
HPC2021 system | ||||
---|---|---|---|---|
MPI version | Compiler | module command | ||
MPICH | ||||
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 |
To know which MPI compiler you are using, you may type command:
mpicc -v or 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/intel/3.4.2-intel2021 # 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