Job chains

How to submit jobs to slurm?

Deploying dependent jobs (job chains)

In certain scenarios, it might be desirable to condition the execution of a certain job on the status of another job. In such cases, the sbatch directive --dependency=<condition>:<jobID> can be used, where <condition> specifies the type of dependency (See table 2), and <jobID> is the slurm jobID upon which dependency is based. To specify more than one dependency, the , separator is used to indicate that all dependencies must be specified, and, ? is used denotes that any dependency may be satisfied.

For example, assume the slurm job scripts, job_1.sbatch, … job_3.sbatch need to run sequentially one after the other. To start this chain, submit the first job and obtain its jobID:

$ sbatch job_1.sbatch
Submitted batch job 8580135

Next, submit the second job to run only if the first job is successful:

$ sbatch --dependency=afterok:8580135 job_2.sbatch
Submitted batch job 8580136

And, now, to run the third job only after the first two jobs have both run successfully:

$ sbatch --dependency=afterok:8580135,8580136 job_3.sbatch
Submitted batch job 8580140

Alternatively, if the third job is dependent on either job running successfully:

$ sbatch --dependency=afterok:8580135?8580136 job_3.sbatch
Submitted batch job 8580141
Table 2: Possible sbatch dependency conditions
ArgumentDescription
afterThis job can begin execution after the specified jobs have begun execution
afteranyThis job can begin execution after the specified jobs have terminated.
aftercorrA task of this job array can begin execution after the corresponding task ID in the specified job has completed successfully
afternotokThis job can begin execution after the specified jobs have terminated in some failed state
afterokThis job can begin execution after the specified jobs have successfully executed
singletonThis job can begin execution after any previously launched jobs sharing the same job name and user have terminated