Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Array submission works via the “--array” option of sbatch (read more about it here). This requires the start, stop, and optional step size for your array indices – each index will be given its own task ID and will be submitted as a batch job with the #SBATCH commands listed in your header.

For example:

Code Block
--array=0-10

Will create a job with tasks 0 - 10 (11 tasks in total).

Code Block
--array=5-7

Will create a job with tasks 5, 6, and 7 (3 in total).

...

Again, this assumes that you have 13 .csv files with the prefix “simulated_data” in the “/home/name/dir/” directory.

If you would rather provide a file that contains a list that you would like to iterate through, you can read in the file using the readarray command, and then assign this to your “data” variable, as shown below.

Code Block
#!/bin/bash

#SBATCH --account=placeholder
#SBATCH --time=01:00:00
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=1
#SBATCH --array=0-12

module load gcc
module load swset
module load r/3.6.1

readarray -t data < data_list.txt

Rscript /home/name/dir/coolscript.R ${data[$SLURM_ARRAY_TASK_ID]}

There are certainly more ways to use this system than those I’ve laid out here – please add any others you can think of if others might find it useful!