Isaac Liu
Isaac Liu

Reputation: 419

Job arrays and shell script with only some parallel steps

I am working with the following .sh script which I submit using sbatch. Pairwise_3_P_a.do and Pairwise_3_P_c.do are linear steps that should be run only once, but Pairwise_3_P_b.do uses an array. I am having problems with Pairwise_3_P_c.do being run before the array is done.

Is there a way to fix this script using --wait or the wait bash command? Do I need to use srun, as in this answer: How to hold up a script until a slurm job (start with srun) is completely finished? ? I do not fully understand how to implement wait and --wait as mentioned there and in the documentation.

#!/bin/bash

#SBATCH --array=1-248

module load stata
stata-mp Pairwise_3_P_a.do
stata-mp Pairwise_3_P_b.do $SLURM_ARRAY_TASK_ID
stata-mp Pairwise_3_P_c.do

So far I have been trying to split the parallel step off into a separate .sh script, but this is annoying to run.

Thanks.

Upvotes: 2

Views: 566

Answers (1)

damienfrancois
damienfrancois

Reputation: 59110

The way the submission script is written will create 248 jobs that will each do exactly the same first and last steps and only differ in the second step. This is probably not what you want.

You should split the three lines in three different jobs, only the second of which should be a job array. I assume order is important here.

Job1.sh:

#!/bin/bash
module load stata
stata-mp Pairwise_3_P_a.do

Job2.sh:

#!/bin/bash
#SBATCH --array=1-248

module load stata
stata-mp Pairwise_3_P_b.do $SLURM_ARRAY_TASK_ID

Job3.sh:

#!/bin/bash
module load stata
stata-mp Pairwise_3_P_c.do

With those files set, run the following commands:

FIRSTJOBID=$(sbatch --parsable Job1.sh)
SECONDJOBID=$(sbatch --parsable --dependendcy=afterok:$FIRSTJOBID Job2.sh)
sbatch --parsable --dependendcy=afterany:$SECONDJOBID Job3.sh

Also as you start stata-mp, it would make sense to request at least more than one core to enable Stata to use its multithreaded functionalities, with, for instance:

--cpus-per-task=8

Upvotes: 1

Related Questions