SLURM Job Dependencies

You may submit jobs that runs depending on status of the previously submitted jobs or schedule a bunch of jobs to run one after the other.

Once you submit a job, using that job ID, you can submit dependency jobs.

You need to extract the job id “12345” from the output of the “sbatch” command

$ sbatch job.cmd
Submitted batch job 12345

By adding the “–parsable” option to “sbatch command”, only the job ID would be returned and its value can be stored in a shell variable for later use.

$ jobID=$(sbatch --parsable job.cmd)
$ echo ${jobID}
12345

Next, you can submit a job that only runs after successful completion of the first job as follows where we set the “afterok” as the dependency type.

$ sbatch --dependency=afterok:${jobID} second_job.cmd

The format here is

$ sbatch --dependency=type:job_id jobfile

If the job requires more than one job to be completed before it is executed, you can supply all the jobids using , separator

$ sbatch --dependency=type:job_id,job_id,job_id jobfile

You can also set the job to run if any one of the job ids completes successfully using a ? separator

$ sbatch --dependency=type:job_id?job_id?job_id jobfile

The other dependencies that can be used for<type:job_id> are as follows:

Type Description
after This job can begin execution after the specified jobs have begun execution
afterany This job can begin execution after the specified jobs have terminated.
aftercorr A task of this job array can begin execution after the corresponding task ID in the specified job has completed successfully
afternotok This job can begin execution after the specified jobs have terminated in some failed state
afterok This job can begin execution after the specified jobs have successfully executed
singleton This job can begin execution after any previously launched jobs sharing the same job name and user have terminated