Skip to content

Preferred syntax for one-command-per-line job arrays #5

Description

@pjvandehaar
  • Option 1: (used by https://github.com/statgen/SLURM-examples/blob/master/job-array-one-command-per-line)

    #!/bin/bash
    #SBATCH --array=1-2
    declare -a commands
    commands[1]="Rscript myscript.R input_file_A.txt"
    commands[2]="Rscript myscript.R input_file_B.txt"
    bash -c "${commands[${SLURM_ARRAY_TASK_ID}]}"
    
  • Option 2:

    #!/bin/bash
    #SBATCH --array=1-2
    commands=(
    "Rscript myscript.R input_file_A.txt"
    "Rscript myscript.R input_file_B.txt"
    )
    bash -c "${commands[${SLURM_ARRAY_TASK_ID}]}"
    
  • Option 3:

    #!/bin/bash
    #SBATCH --array=1-2
    read -d '' commands <<'EOF'
    Rscript myscript.R input_file_A.txt
    Rscript myscript.R input_file_B.txt
    EOF
    echo "$commands" | sed -n ${SLURM_ARRAY_TASK_ID}p | bash
    
  • Option 4: somewhere there's a script (maybe written by Terry?) that does this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions