-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path_parallelMaster.sh
executable file
·86 lines (71 loc) · 1.71 KB
/
_parallelMaster.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
#!/bin/bash
setup_job() {
echo "Setting up job"
cd ${SourceDir}
. setup_env.sh
ID=`uuidgen`
[[ -e /tmp ]] && WorkDir=/tmp/${USER}/${ID}
[[ -e /scratch ]] && WorkDir=/scratch/${USER}/${ID}
echo "WorkDir = ${WorkDir}"
mkdir -p ${WorkDir}
cd ${WorkDir}
}
cleanup_job() {
echo "Cleaning up job"
cd ${WorkDir}
echo "================"
echo "ls $PWD"
ls
echo "================"
find . -name '*.gen.log' -print0 | xargs -0 -I % sh -c 'echo == % ==; cat %' > ${LocalLogFile}.log
tar -czvf ${LocalLogFile}.tgz ${LocalLogFile}.log
echo mv ${LocalLogFile}.tgz ${LogFile}.tgz
mv ${LocalLogFile}.tgz ${LogFile}.tgz
cd ..
rm -rf ${WorkDir}
}
run_subjobs() {
cd
PIDS=""
for HOST in $LSB_HOSTS; do
ID=`uuidgen`
(lsrun -m "$HOST" ${SourceDir}/_parallelSlave.sh ${SourceDir} ${Cmd} ${Args}) &> ${WorkDir}/${ID}.gen.log &
PIDS="$PIDS $!"
done
cd -
}
mill_around() {
echo "Waiting for subjobs to end with PID: ${PIDS}"
Running=1
while [[ ${Running} -eq 1 ]]; do
sleep $(($RANDOM%300))
Running=0
for PID in $PIDS; do
kill -0 ${PID} &> /dev/null && Running=1
done
done
}
LogFile=${1}
shift
SourceDir=${1}
shift
NSubJobs=${1}
shift
Cmd=${SourceDir}/${1}
shift
Args=$*
LogFile="${LogFile}_`echo $LSB_BATCH_JID | sed -e 's/\[/_/; s/\]//'`"
LocalLogFile=`basename ${LogFile}`
echo "Begin at `date`"
echo SourceDir = $SourceDir
echo LogFile = ${LogFile}
echo Cmd = $Cmd
echo Args = $Args
echo "Subjob hosts: $LSB_HOSTS"
setup_job
run_subjobs ${NSubJobs}
trap cleanup_job SIGHUP SIGINT SIGTERM
mill_around
cleanup_job
echo "Let's blow this popsicle stand"
echo "End at `date`"