Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LSF - Get ID of submitted job

Tags:

lsf

Say I submit a job using something like bsub pwd. Now I would like to get the job ID of that job in order to build a dependency for the next job. Is there some way I can get bsub to return the job ID?

like image 775
Nils Avatar asked Aug 23 '12 14:08

Nils


2 Answers

Nils and Andrey have the answers to this specific question in shell and C/C++ environments respectively. For the purposes of building dependencies, you can also name your job with -J then build the dependency based on the job name:

bsub -J "job1" <cmd1>
bsub -J "job2" <cmd2>
bsub -w "done(job1) && done(job2)" <cmd>

There's a bit more info here.

This also works with job arrays:

bsub -J "ArrayA[1-10]" <cmd1>
bsub -J "ArrayB[1-10]" <cmd2>
bsub -w "done(ArrayA[3]) && done(ArrayB[5])" <cmd>

You can even do element-by-element dependency. The following job's i-th element will only run when the corresponding element in ArrayB reaches DONE status:

bsub -w "done(ArrayB[*])" -J "ArrayC[1-10]" <cmd3>

You can find more info on the various things you can specify in -w here.

like image 129
Squirrel Avatar answered Nov 13 '22 00:11

Squirrel


Just as a reference, this is the best solution I could come up with so far. It takes advantage of the fact that bsub write a line containing the ID to STDOUT.

function nk_jobid {
    output=$($*)
    echo $output | head -n1 | cut -d'<' -f2 | cut -d'>' -f1
}

Usage:

jobid=$(nk_jobid bsub pwd)
like image 30
Nils Avatar answered Nov 13 '22 01:11

Nils