Day 3: Writing MPI programs

Lecture slides

Using MPI

To load a particular MPI, you can use the module commamd. For example,

$ module load openmpi/gnu

You can then use mpicc to compile your MPI program:

$ mpicc -O3 -o pgm pgm.c

mpicc is a wrapper and the command below shows what it does:

$ mpicc -show

To run an MPI program, you type:

$ mpirun -np <#processes> ./pgm

Writing a simple MPI program

The exercise is to write a simple ping benchmark in MPI.c. You can start with this boilerplate code:

#include <mpi.h>
int main(int argc, char ** argv) {
  int processes, rank;
  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &processes);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  ...

  MPI_Finalize();
  return 0;
}

Using mpiP

You can load the mpip module by typing:

$ module load libunwind
$ module load mpip

To link mpiP to your program you need to add these libraries on your link line:

-L$(MPIP_LIBDIR) -lmpiP -lm -lbfd -L$(LIBUNWIND_LIBDIR) -Wl,-rpath,$(LIBUNWIND_LIBDIR) -lunwind

Using HPCToolkit