```bash sbatch --array 1-2 --gpus-per-task 1 --cpus-per-task 32 --wrap 'bash -c "echo $SLURM_ARRAY_TASK_ID"' ``` ``` sbatch: error: Failed to validate job spec. --gpus-per-task or --tres-per-task used without either --gpus or -n/--ntasks is not allowed. sbatch: error: Invalid generic resource (gres) specification ```
How to solve this issue?
Jun 4, 11:25pm
The error occurs because Slurm requires either --gpus or --ntasks (or -n) to be specified when using --gpus-per-task or --tres-per-task. The --wrap option does not implicitly set --ntasks, so you need to explicitly define the number of tasks.
Solution
Add --ntasks=1 (or -n 1) to your command to specify that each array job should run as a single task. This resolves the validation error.