-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathschedule-batch.sh
executable file
·145 lines (119 loc) · 4.54 KB
/
schedule-batch.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
#
# This script takes a FieldTrip revision and schedules all tests in that
# revision for execution on the torque compute cluster.
#
# Use as either one of these
# schedule-batch.sh <FIELDTRIPDIR> <LOGDIR> <MATLABCMD>
# schedule-batch.sh <FIELDTRIPDIR> <LOGDIR>
# schedule-batch.sh <FIELDTRIPDIR>
# schedule-batch.sh
#
set -u -e # exit on error or if variable is unset
# ensure that other team members can read the results
umask 0022
DASHBOARDDIR=$(dirname $(readlink -f $0))
# load some bash helper functions
source $DASHBOARDDIR/tobytes.sh
source $DASHBOARDDIR/togb.sh
source $DASHBOARDDIR/toseconds.sh
source $DASHBOARDDIR/tohms.sh
# this overhead is added to the job requirements
MEMOVERHEAD=2000000000
WALLTIMEOVERHEAD=1800
if [ "$#" -ge 1 ]; then
FIELDTRIPDIR=$1
else
FIELDTRIPDIR=$HOME/matlab/fieldtrip
fi
REVISION=$(cd $FIELDTRIPDIR && git rev-parse --short HEAD)
BRANCH=$(cd $FIELDTRIPDIR && git rev-parse --abbrev-ref HEAD)
if [ "$#" -ge 2 ]; then
LOGDIR=$2
else
LOGDIR=$DASHBOARDDIR/logs/$REVISION
(cd $DASHBOARDDIR/logs && rm -rf latest && ln -s $REVISION latest)
fi
if [ "$#" -ge 3 ]; then
MATLABCMD=$3
else
MATLABCMD="/opt/matlab/R2018b/bin/matlab -nodesktop -nosplash -nodisplay -singleCompThread"
fi
if [[ $MATLABCMD == *"matlab"* ]]; then
QSUB="$HOME/bin/qsub -q matlab"
# QSUB="qsub -q matlab"
# QSUB="qsub -q matlab -l nodes=dccn-c019.dccn.nl,nodes=dccn-c020.dccn.nl"
# QSUB="qsub -q matlab -l nodes=1:ppn=8,nodes=dccn-c006.dccn.nl,nodes=dccn-c007.dccn.nl,nodes=dccn-c019.dccn.nl,nodes=dccn-c020.dccn.nl,nodes=dccn-c021.dccn.nl,nodes=dccn-c027.dccn.nl,nodes=dccn-c028.dccn.nl,nodes=dccn-c033.dccn.nl,nodes=dccn-c034.dccn.nl"
# QSUB="qsub -q matlab -l nodes=1:ppn=8"
# QSUB="qsub -q matlab -l nodes=1:intel"
# QSUB="qsub -q matlab -l nodes=amd"
# QSUB="qsub -q matlab -l nodes=dccn-c006.dccn.nl,nodes=nodes=dccn-c007.dccn.nl,nodes=dccn-c019.dccn.nl,nodes=dccn-c021.dccn.nl,nodes=dccn-c027.dccn.nl,nodes=dccn-c028.dccn.nl,nodes=dccn-c033.dccn.nl,nodes=dccn-c034.dccn.nl"
# QSUB="qsub -q matlab -l nodes=1:ppn=8"
elif [[ $MATLABCMD == *"octave"* ]]; then
QSUB="qsub -q batch"
else
>&2 echo Error: unknown MATLABCMD $MATLABCMD
fi
mkdir -p $LOGDIR
echo $BRANCH > $LOGDIR/branch
echo $REVISION > $LOGDIR/revision
# keep track of all the jobs that are in this batch
rm -rf $LOGDIR/batch
for TEST in `find $FIELDTRIPDIR -path "*test/test_*.m"` ; do
# this should be formatted in the matlab files as
# % WALLTIME 4:00:00
# % MEM 1gb
WALLTIME=`grep WALLTIME $TEST | cut -d ' ' -f 3`
MEM=`grep MEM $TEST | cut -d ' ' -f 3`
# set the mem and walltime if the matlab files do not specify them
if [ -z "$WALLTIME" ] ; then WALLTIME="12:00:00" ; fi
if [ -z "$MEM" ] ; then MEM="16gb" ; fi
WALLTIME=$( toseconds $WALLTIME )
WALLTIME=$(( $WALLTIME + $WALLTIMEOVERHEAD ))
WALLTIME=$( tohms $WALLTIME )
MEM=$( tobytes $MEM )
MEM=$(( $MEM + $MEMOVERHEAD ))
MEM=$( togb $MEM )
# the following lines allow for a temporary override
# WALLTIME=23:59:00
# MEM=16gb
# Create temp file for job submission with so-called "here document":
BASHSCRIPT=`mktemp $LOGDIR/test_XXXXXXXX.sh`
# ---------------------------------------------------------------------------
cat > $BASHSCRIPT <<EOF
#!/usr/bin/env bash
#
% This BASH script will be automatically removed when the job has been scheduled.
#
# The script to start MATLAB and execute the specific test should be called as
# run-test.sh <TESTSCRIPT> <FIELDTRIPDIR> <LOGDIR> <MATLABCMD>
#
$DASHBOARDDIR/run-test.sh $TEST $FIELDTRIPDIR $LOGDIR \'$MATLABCMD\'
EOF
# ---------------------------------------------------------------------------
# extract test name from filename
TESTNAME=${TEST%.*}
TESTNAME=${TESTNAME##*/}
# run test job on Torque
job=$($QSUB -h -l walltime=$WALLTIME,mem=$MEM -N $TESTNAME -o $LOGDIR/$TESTNAME.txt -e $LOGDIR/$TESTNAME.err $BASHSCRIPT)
echo $job >> $LOGDIR/batch
# remove temp file again
rm $BASHSCRIPT
done
# Create temp file for job submission with so-called "here document":
BASHSCRIPT=`mktemp $LOGDIR/test_XXXXXXXX.sh`
DEPEND=`paste -s -d : $LOGDIR/batch`
# ---------------------------------------------------------------------------
cat > $BASHSCRIPT <<EOF
#!/usr/bin/env bash
#
#PBS -l mem=250mb,walltime=00:10:00
#PBS -W depend=afterany:$DEPEND
#PBS -N run-release
#PBS -o $LOGDIR/run-release.txt -e $LOGDIR/run-release.err
$DASHBOARDDIR/run-release.sh $REVISION
EOF
# ---------------------------------------------------------------------------
$QSUB $BASHSCRIPT || echo FAILED to submit run-release
rm $BASHSCRIPT
for job in `cat $LOGDIR/batch` ; do qrls $job ; done