-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrayjob-runner.sh
executable file
·64 lines (54 loc) · 1.69 KB
/
arrayjob-runner.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
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
usage() {
echo "Usage: $0 -f <tasklist> [-n <tasks_per_job>] -s <task_program> -- [additional options for sbatch...]"
exit 1
}
TASK_LIST=""
TASKS_PER_JOB="1"
TASK_SCRIPT=""
while getopts "f:n:s:" opt; do
case $opt in
f)
TASK_LIST="$OPTARG"
if [ ! -f "$TASK_LIST" ]; then
echo "Error: '$TASK_LIST' is not found." >&2
usage
fi
;;
n)
TASKS_PER_JOB="$OPTARG"
if [[ ! "$TASKS_PER_JOB" =~ ^[0-9]+$ ]]; then
echo "Error: -n option requires an integer." >&2
usage
fi
;;
s)
TASK_SCRIPT="$OPTARG"
if [ ! -x "$TASK_SCRIPT" ]; then
echo "Error: '$TASK_SCRIPT' is not found or not executable." >&2
usage
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "$TASK_LIST" ]; then
echo "Error: -f option is required." >&2
usage
fi
if [ -z "$TASK_SCRIPT" ]; then
echo "Error: -s option is required." >&2
usage
fi
[[ ! "$TASK_SCRIPT" =~ ^(/|\./|\.\./|~) ]] && TASK_SCRIPT="./$TASK_SCRIPT"
JOB_NAME=$(basename "$TASK_SCRIPT")
TOTAL_TASKS=$(wc -l < "$TASK_LIST")
N=$(( (TOTAL_TASKS + TASKS_PER_JOB - 1) / TASKS_PER_JOB ))
echo "Processing tasks in $TASK_LIST with $TASK_SCRIPT, $TASKS_PER_JOB tasks each."
echo "Total tasks: $TOTAL_TASKS"
echo "Submitting job: sbatch --job-name=$JOB_NAME --array=1-$N $* job.sh $TASK_LIST $TASKS_PER_JOB $TASK_SCRIPT"
sbatch --job-name="$JOB_NAME" --array=1-$N "$@" job.sh "$TASK_LIST" "$TASKS_PER_JOB" "$TASK_SCRIPT"