Wait for one or all LSF jobs to complete

If you give the -K option to bsub, it will wait for the job to complete before returning. You can then background several bsub commands in the shell and use the shell's wait command to wait for them. Example:

#!/bin/bash
bsub -K -o out.1 sleep 10 &
bsub -K -o out.2 sleep 5 &
wait

bwait

Example:

bsub -J 'myjobname' -o bsub.log bash -c 'date && sleep 10'
bwait -w 'ended(myjobname)'

The bwait waits until the corresponding bsub finished.

The same method also works for jobs arrays where -K is not supported:

bsub -J 'myjobname[1-40]' -o 'bsub%I.log" 'sleep $JOBINDEX && echo $JOBINDEX'
bwait -w 'ended(myjobname)'

Besides ended() there is also done() and exit(), which make bwait only exit successfully if the exit status is 0 or not 0 respectively, and otherwise fail with:

Wait condition is never satisfied

because LSF has different job states for both cases.

Related documentation:

  • https://www.ibm.com/support/knowledgecenter/en/SSWRJV_10.1.0/lsf_command_ref/bwait.1.html
  • https://www.ibm.com/support/knowledgecenter/SSWRJV_10.1.0/lsf_command_ref/bsub.w.1.html#bsub_option_w

Tags:

Hpc

Cluster