Ping-Pong: Using the Cluster Environment


Throughout these modules, we assume that all code will be executed on a cluster. In this module, we will provide an example of submitting a job script to the batch scheduler.

Local vs. Cluster Environments

In the example below we will contrast running in your local environment and the cluster.

To run locally, there are two steps (assuming $p=4$ ranks):

Compile: mpicc pingpong_comm_starter.c -lm -o pingpong_comm_starter

Run: mpirun -np 4 -hostfile myhostfile.txt ./pingpong_comm_starter

In contrast, to use the SLURM batch scheduler, you must write a job script, as follows. For this example, assume this file is called

#SBATCH --job-name=ping_pong           
#SBATCH --output=/path/to/scratch/myfile.out	
#SBATCH --error=/path/to/scratch/myfile.err
#SBATCH --time=02:00				# 2 min
#SBATCH --mem=2000 
#SBATCH --nodes=1
#SBATCH --ntasks=4 
#SBATCH --cpus-per-task=1

module load openmpi

mpicc ~/path/to/work/directory/ping_pong.c -lm -o ~/path/to/work/directory/ping_pong

srun ~/path/to/work/directory/ping_pong

After you have created your script, submit your job using the command sbatch

  • Q2: How many process ranks are used in the script above?