You are here: Home / Cluster / Tutorials / MPI Demo - Prime Number Generation

MPI Demo - Prime Number Generation

Demo - Prime Number Generation

Log on to the cluster via SSH

List all available modules for use, and then load the settings for MPI

module avail
module load mpi/openmpi-2.0.2

Copy the MPI demo program into your home directory

cp -R /exports/common/llnl_mpi_demos/prime_number_generation .
cd prime_number_generation

Compile the MPI demo program
(which requires math library, hence -lm

mpicc mpi_prime.c -lm -o mpi_prime

Check the SLURM scheduler - is the cluster busy now? How many jobs are pending?

sinfo
squeue 

Run your program in a variety of configurations, and measure how long each job took:

# 1 node, 4 CPU cores total
srun --nodes=1 --ntasks=4 ./mpi_prime

# 1 node, 8 CPU cores total
srun --nodes=1 --ntasks=16 ./mpi_prime

# 1 node, 16 CPU cores total
srun --nodes=1 --ntasks=16 ./mpi_prime

# 1 node, 32 CPU cores total
srun --nodes=1 --ntasks=32 ./mpi_prime

# 2 nodes, 64 CPU cores total
srun --nodes=2 --ntasks=64 ./mpi_prime

# 4 nodes, 128 CPU cores total
srun --nodes=4 --ntasks=128 ./mpi_prime