slurm

slurm using replacment symbols with wrap


I am submitting a single script to slurm using the --wrap option, but I also want it to addend a run time to the log file.

  sbatch \
    -J nom \
    --mem=16G \
    -c 4 \
    -t 24:00:00 \
    -p partition \
    -A acount \
    -o %A_scriptname_%x.log \
    --wrap "echo 'hello world'; squeue -j %A --Format=TimeUsed"

In order to get the job_id, I tried both the replacement string %A and the script variable $SLURM_JOBID. The former returns the error squeue: error: Invalid job id: %A, and the latter doesn't recognize the job ID and prints the TimeUsed for all active jobs on the server. Is there a format to use in the quoted section to interpolate the replacement strings?


Solution

  • The %A placeholders are only available in the --output parameter. You will need to use the job ID.

    The variable in the command line must be escaped, because it is not yet defined at the time of the invocation of the command and will only be defined within the job. Bash will therefore expand it to an empty string prior to submission. It must therefore be transmitted literally to the job:

    --wrap "echo 'hello world'; squeue -j \$SLURM_JOB_ID --Format=TimeUsed"
    

    This is different from other variables that you would use from the submitting environment for instance with

    Rscript run.R -v $var1 -s $var2
    

    In that case, the variables are already defined in the environment when you submit the job, and they are expanded prior to submission.