3. Running Parallel Jobs
Create a Program
We want to run a few jobs in parallel. We're going to create a simple program that takes a number as input and prints the square of that number. We'll pass the number of the job as an argument to the program. There is an example saved in the directory called
myapplication.sh
.#!/bin/bash # Square the input integer input=$1 result=$((input * input)) # Print the result echo "The square of $input is $result"Create a Job Script
Create a file named
array_job.sh
with the following content. The$SLURM_ARRAY_TASK_ID
variable will be set to the index of the job in the array. We'll be creating an array of 5 jobs.#!/bin/bash #SBATCH --account=def-sponsor00 #SBATCH --time=0-0:5 #SBATCH --array=1-5 ./myapplication.sh $SLURM_ARRAY_TASK_IDSubmit the Job
Use the
sbatch
command to submit your job script:sbatch array_job.shMonitor the Job
Check the Output
Cancel Jobs
Additional Resources
Last modified: 21 March 2025