-
Notifications
You must be signed in to change notification settings - Fork 1
/
fake-sbatch.sh
executable file
·53 lines (44 loc) · 1.02 KB
/
fake-sbatch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#set -euo pipefail
export SLURM_TASKS_PER_NODE=1
export SLURM_CPUS_ON_NODE=1
ARRAY_INDEXES="1-1"
echo "$@" >&2
while [[ $1 = -* ]]; do
if [[ $1 == "--cpus-per-task" ]]; then
export SLURM_CPUS_PER_TASK=$2
export SLURM_CPUS_ON_NODE=$2
shift 2
elif [[ $1 == "--ntasks" ]]; then
export SLURM_TASKS_PER_NODE=$2
shift 2
elif [[ $1 =~ --(parsable|verbose|exclusive) ]]; then
shift 1
elif [[ $1 == "--array" ]] || [[ $1 == "-a" ]]; then
ARRAY_INDEXES="$2"
shift 2
else
shift 2
fi
done
parse-array-sequence() {
if [[ $# == 2 ]]; then
seq $1 ${2%\%*} # remove any %32 that may have been specified
else
echo $1
fi
}
parse-array-indexes() {
while IFS=, read -a sequences; do
for sequence in ${sequences[@]}; do
parse-array-sequence $(tr '-' ' ' <<< $sequence)
done
done <<< $@
}
export SLURM_ARRAY_JOB_ID=1
# The JOB_ID that sbatch would normally print to stdout
echo "${SLURM_ARRAY_JOB_ID}"
for TASK_ID in $(parse-array-indexes $ARRAY_INDEXES); do
export SLURM_ARRAY_TASK_ID=$TASK_ID
"$@"
done