Compiling a parallel MPI C program

This will guide you through the process of compiling a simple C program that uses the MPI library for parallel computation. We will be using the GCC 10.2.0 compilers and the OpenMPI 4.1.1 library. The program simply prints "Hello world from processor ###, rank ###"

Step 1 – Download and transfer the program to the Cluster

The program is available here. Download it and transfer it to the cluster using WinSCP or any other file transfer program. Alternatively, a more direct route is to run the wget command on the cluster to directly download the file:

wget https://enghpcdocs.swan.ac.uk/wp-content/uploads/2021/07/hello_world_mpi.c

Step 2 – Load the required modules

We need to load the modules that provide the GCC C compiler and the OpenMPI library.

Enter the following commands:

module load gcc/10.2.0
module load openmpi/4.1.1

Step 3 – Compile the program

Enter the following command:

mpicc -o hello_world hello_world_mpi.c

Step 3 – Run the program

Unlike programs that run aon a single cpu core, as described in the previous guide, parallel programs cannot be executed directly on the login node. Instead, the program must be submitted to the compute nodes as a batch job.

This is described in this guide.