Search code examples
arraysparallel-processingjobsslurmsbatch

SLURM/sbatch: pass array ID as input argument of an executable


I'm new to SLURM and I'm trying to do something very natural: I have a compiled C program, off.exe, which takes one variable as input, and I want to run it several times in parallel, each with a different value of the input parameter. I thought I could use the %a array iterator as input:

#!/bin/bash

#SBATCH --partition=regular1,regular2
#SBATCH --time=12:00:00                                         # walltime
#SBATCH --ntasks=1                                              # number of processor cores (i.e. tasks)
#SBATCH --mem-per-cpu=512M                                      # memory per CPU core
#SBATCH --job-name="ISM"                                        # job name
#SBATCH --array=1-60                                            # job array. The item identifier is %a
#SBATCH --output=Polarization_%a_v0.4.txt                       # output file. %A is the job ID

srun ./off.exe %a

but it's not working (it's as if the input parameter were always zero!). Can someone help me please?


Solution

  • $a, %j etc. are replacement symbols for filenames, for example in the names of the output and error files recorded by Slurm. For your job arrays, you need to use one of Slurm's output environment variables, probably $SLURM_ARRAY_TASK_ID. You can find the full list in the manpage for sbatch.