-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel_dgx.sh
71 lines (64 loc) · 1.37 KB
/
parallel_dgx.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
#!/bin/bash
## This file is used to run r script files parallelly.
## define some variables
rfile=extract_value_set_data_from_medical_claim_diagnosis # name of r script file
rex=.R # extention of r script file
Fjob=0001 # first r script file
Njob=0006 # total number of r script files
Nproc=2 # number of r script to run every time
## set up a function
function CMD {
echo -e "Begin Job $1 \r\n" >> log.txt
echo -e "Begin Job $1 \r\n"
Rscript $rfile\_$i$rex
n=$((random % 5 + 1))
sleep $n
echo -e "Job $1 $Ijob $2 exiting ...\r\n" >> log.txt
echo -e "Job $1 $Ijob $2 exiting ...\r\n"
}
function PushQue {
Que="$Que $1"
Nrun=$(($Nrun+1))
}
function GenQue {
OldQue=$Que
Que=""; Nrun=0
for PID in $OldQue; do
if [[ -d /proc/$PID ]]; then
PushQue $PID
fi
done
}
function ChkQue {
OldQue=$Que
for PID in $OldQue; do
if [[ ! -d /proc/$PID ]] ; then
GenQue; break
fi
done
}
for i in $(seq -s " " -f %04g $Fjob $Njob); do
CMD $i &
PID=$!
PushQue $PID
while [[ $Nrun -ge $Nproc ]]; do
ChkQue
sleep 1
done
done
wait
# PID=()
# for((i=1; i<=$Njob; )); do
# for((Ijob=0; Ijob<$Nproc; Ijob++)); do
# if [[ $i -gt $Njob ]]; then
# break;
# fi
# if [[ ! "${PID[Ijob]}"]] || ! kill -0 ${PID[Ijob]} 2> log.txt; then
# CMD $i $Ijob &
# PID[Ijob]=$!
# i=$((i+1))
# fi
# done
# sleep 10
# done
# wait