#The variable $SLURM_ARRAY_TASK_ID is the ID for this task.
#The variable $SLURM_ARRAY_TASK_MIN is the ID for the first task.
#The variable $SLURM_ARRAY_TASK_MAX is the ID for the last task.
if [[ $SLURM_ARRAY_TASK_ID == $SLURM_ARRAY_TASK_MIN ]]; then
position="first"
elif [[ $SLURM_ARRAY_TASK_ID == $SLURM_ARRAY_TASK_MAX ]]; then
position="last"
else
position="neither"
fi
#The variable $SLURM_ARRAY_JOB_ID is the ID for the entire array job
#The variable $SLURM_JOB_ID is the ID for each job in the array
echo "Array Job ID: $SLURM_ARRAY_JOB_ID"
echo "Job ID: $SLURM_JOB_ID"
echo "Task ID: $SLURM_ARRAY_TASK_ID"
echo "First or last: $position"
This script will request to run 7 tasks (task ids: 1, 7, 13, 19, 25, 31 and 37) and for
each task the node will print out the array job ID, job ID, task ID, and whether the
task was the first task, last task or neither.
Step 3. We will now submit the array job to the Matador partition using the sbatch
command.
sbatch array.sh
Step 4. Once your job has completed, list the directory and view some of the newly
created output files. For each task ID, you will see the following files:
• array-<array_job_id>_<task_id>.out
o This file will contain the output for your task.
• array-<array_job_id>_<task_id>.err
o This file will contain any errors generated by your task.
Step 5. Edit the array.sh file and change the line "#SBATCH -a 1-37:6" to instead say
"#SBATCH -a 1-6". Now rerun steps 3 and 4 and see what has changed. Notice how the
array job now only ran 5 array tasks with IDs 1,2,3,4, and 5. Keep in mind that if you do
not specifically set an increment, it will default to an increment of 1.
Step 6. Congratulations, you have now successfully set up and run an array job on
Matador!