Running MPICH program
MPICH is one of the most popular implementations of MPI.
In this tutorial, we aim to introduce that in a CSCI4160 cluster with 3 machines: node-1
, node-2
, and node-3
.

How to compile MPI program
Here we will use mpi_hello_world
in https://mpitutorial.com/tutorials/ as an example.
SSH to node-1
You can login node-1
by using your CSE account just like linux9.
Clone the mpitutorial git repository
cd ~ # make sure that your are now in the home directory
git clone https://github.com/wesleykendall/mpitutorial
cd ~/mpitutorial/tutorials/mpi-hello-world/code
Compile the mpi_hello_world using mpicc
Instead of using gcc
, we use mpicc
such that the mpich library is linked.
mpicc -o mpi_hello_world mpi_hello_world.c
Now you should get the executable mpi_hello_world
Run MPI program in CSCI4160 cluster using SLURM
We have setup a small SLURM cluster consists of node-1
, node-2
and node-3
. Use salloc
command to launch your mpi program on that cluster:
salloc -N 3 mpirun ./mpi_hello_world
-N 3
: request 3 nodes from the cluster
node-1:~/mpitutorial/tutorials/mpi-hello-world/code$ salloc -N 3 mpirun ./mpi_hello_world
salloc: Granted job allocation 23695
Hello world from processor node-3.cse.cuhk.edu.hk, rank 2 out of 3 processors
Hello world from processor node-1.cse.cuhk.edu.hk, rank 0 out of 3 processors
Hello world from processor node-2.cse.cuhk.edu.hk, rank 1 out of 3 processors
salloc: Relinquishing job allocation 23695
You can see that there are 3 Hello world messages from 3 processors with different hostnames: node-1 node-2 node-3
MPICH Programming
I suggest you go through the tutorials below, which will help you a lot in Asgn1c.
Last updated
Was this helpful?