Referencing job index in LSF job array

2019-07-19 09:16发布

问题:

I'm trying to pass the index of a job in a job array as a parameter to another bash script.

numSims=3 
numTreatments=6 # uses numTreatments top rows of parameters.csv
maxFail=10
j=1
while [ $j -le $numSims ];
do
    bsub -q someQueue -J "mySim[1-$numTreatments]%2" ./another_script.sh $LSB_JOBINDEX $j $maxFail
    let j=j+1
done

The ultimate idea here is to submit, for each of 1,...,numTreatments,numSims jobs (simulations). I'd like two jobs running at a time (%2). Outputs have the form XX_indexNumber_simNumber, where indexNumber runs from 1,...,numTreatments and simNumber from 1,...,numSims.

Ideally, everything submitted as part of this script would have the same job ID. This isn't yet set up correctly, because all jobs with the same j are being assigned a distinct job ID. My immediate problem is that another_script.sh is not recognizing $LSB_JOBINDEX as input--it sees $j and $maxFail as the first and only two passed parameters. When I put some other variable in place of $LSB_JOBINDEX, there's no problem. What am I doing wrong?


Edit - some things I've tried: "$LSB_JOBINDEX", ${LSB_JOBINDEX}, %I, and I=$LSB_JOBINDEX; bsub ... $I $j $maxFail

回答1:

From this link:

The definition above will launch not just one batch job, but 100 batch jobs where the subjob specific environment variable $LSB_JOBINDEX gets values form 1 to 100. This variable can then be utilized in the actual job launching commands so that each subtask gets processed.

In your case, this means that the variable $LSB_JOBINDEX is available from inside the script another_script.sh. You do not need to pass it as a parameter, but just access $LSB_JOBINDEX in your script.



标签: bash jobs hpc lsf