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. The MPI standard 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.
What is Open MPI?
The Open MPI Project is an open source, freely available implementation of MPI with MPI-1, MPI-2 and MPI-3.1 standards.
Using Open MPI
On HPC2021, you can set up the Open MPI environment variables and path by loading the module:
HPC2021 system | ||
---|---|---|
Open MPI version | Compiler | module command |
4.1.0 | GCC 8.3.1 | module load openmpi/gcc/4.1.0-gcc8.3.1 |
GCC 10.2 | module load openmpi/gcc/4.1.0-gcc10.2 | |
Intel 2020u4 | module load openmpi/intel/4.1.0-intel2020u4 | |
AOCC 3.1 | module load openmpi/aocc/4.1.0-aocc3.1 |
Compiling MPI applications
You can use the Open MPI’s wrapper compilers to compile your MPI applications. That is, instead of using (for example) gcc to compile your program, use mpicc. Open MPI provides a wrapper compiler for four languages:
Language | Environment variable | Wrapper compiler name |
---|---|---|
C | $MPICC | mpicc |
C++ | $MPICXX | mpicxx, mpic++ |
Fortran | $MPIFC | mpifort (for v1.7 and above) |
$MPIF90 | mpif90 | |
$MPIF77 | mpif77 |
Therefore, you can compile your MPI programs by:
mpicc mpi_program.c -o mpi_program
Note that Open MPI’s wrapper compilers do not do any actual compiling or linking; all they do is manipulate the command line and add in all the relevant compiler/linker flags and then invoke the underlying compiler/linker. You may visit Open MPI FAQ for additional information.
Running Open MPI program
(A) Interactive run (for short job testing):
mpiexec -n 20 ./mpi_program
(B) Sample SLURM script for batch run:
#!/bin/bash #SBATCH --job-name=test_openmpi #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 appropriate Open MPI (Intel Open MPI as an example here) module load openmpi/intel/4.1.0-intel2020u4 # run the program supporting MPI with the "mpirun" command # The -n option is not required since mpirun will automatically determine from SLURM settings mpirun ./mpi_program # end of example file
Additional Information
Official Open MPI website: http://www.open-mpi.org/
Official documentation for different Open MPI versions
MPI Programming Self-learn tutorial