Running Serial Jobs

Submitting a Single Serial Job

In this example we consider the case of running a serial Python script. Below is a sample Slurm script:

#!/bin/bash
#SBATCH --job-name=serial        # create a short name for your job
#SBATCH --nodes=1                # node count
#SBATCH --ntasks=1               # total number of tasks across all nodes
#SBATCH --cpus-per-task=1        # cpu-cores per task (>1 if multi-threaded tasks)
#SBATCH --mem-per-cpu=4G         # memory per cpu-core (4G per cpu-core is default)
#SBATCH --time=01:00:00          # total run time limit (HH:MM:SS)
#SBATCH --mail-type=all          # send email on job start, end and fail
#SBATCH --mail-user=YourNetID@princeton.edu

module purge
module load anaconda3

python myscript.py

If the Slurm script is called job.slurm then the job is submitted to the batch system with the following command:

sbatch job.slurm

Submitting Multiple Serial Tasks with a Single Job

NOTE: Do not use this method if the multiple serial tasks running as part of a single job are expected to have significantly different execution times. This will result in tying up idle processors. In general, one should prefer job arrays over the method described here.

Once the serial executable, a.out, is compiled, a job script will need to be created for Slurm. Here is a sample command script, mixed.cmd, which schedules multiple instances of a serial task.

#!/bin/bash
#SBATCH --job-name=mixed         # create a short name for your job
#SBATCH --nodes=1                # node count
#SBATCH --ntasks=10              # total number of tasks across all nodes
#SBATCH --cpus-per-task=1        # cpu-cores per task (>1 if multi-threaded tasks)
#SBATCH --mem-per-cpu=4G         # memory per cpu-core (4G per cpu-core is default)
#SBATCH --time=04:00:00          # total run time limit (HH:MM:SS)
#SBATCH --mail-type=all          # send email on job start, end and fail
#SBATCH --mail-user=YourNetID@princeton.edu

# run instance of the serial job with unique parameters
for ((myproc=1; myproc<=$SLURM_NPROCS; myproc++)) do
    ./a.out $myproc > test-$myproc.out &
done
wait