-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.sh
46 lines (36 loc) · 1.1 KB
/
job.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
#!/bin/bash
# NOTE: This script is not intended to be run directly by users.
# It is designed to be invoked from arrayjob-runner.sh.
if [ -z "$SLURM_ARRAY_TASK_ID" ]; then
echo "Use arrayjob-runner.sh to submit job." >&2
exit 1
fi
TASK_LIST="$1"
TASKS_PER_JOB="$2"
TASK_SCRIPT="$3"
if [ ! -f "$TASK_LIST" ]; then
echo "Error: '$TASK_LIST' is not found." >&2
exit 1
fi
if [[ ! "$TASKS_PER_JOB" =~ ^[0-9]+$ ]]; then
echo "Error: $TASKS_PER_JOB is an invalid value for tasks_per_job." >&2
exit 1
fi
if [ ! -x "$TASK_SCRIPT" ]; then
echo "Error: '$TASK_SCRIPT' is not found or not executable." >&2
exit 1
fi
# Calculate the line numbers of the first and last tasks to be processed
START_LINE=$(( (SLURM_ARRAY_TASK_ID - 1) * TASKS_PER_JOB + 1 ))
END_LINE=$(( SLURM_ARRAY_TASK_ID * TASKS_PER_JOB ))
for LINE in $(seq $START_LINE $END_LINE); do
TASK=$(sed -n "${LINE}p" "$TASK_LIST")
if [ -n "$TASK" ]; then
if "$TASK_SCRIPT" "$TASK"; then
echo "Completed: $TASK"
else
echo "Failed: $TASK"
echo "$TASK" >&2
fi
fi
done