annotate PLIDflow/scripts/parallel_launch.sh @ 2:afd5b5ffc38f draft

Uploaded
author bitlab
date Tue, 14 Jan 2020 07:52:48 -0500
parents 6fcfa4756040
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
1 #!/bin/bash
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
2
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
3 # PIDs are not re-used until PID_MAX_DEFAULT is reached.
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
4
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
5 #requirement for the workflow
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
6 #source /home/galaxy-bitlab/galaxy/tools/proteindocking/scripts/ADT_VENV/bin/activate
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
7
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
8
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
9 # Reads a text file with commands to execute
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
10 if [ $# -lt 1 ]; then
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
11 echo " ==== ERROR ... ====."
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
12 echo ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
13 echo " usage: $0 <execution file> [max cores]"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
14 echo ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
15 echo " MANDATORY <execution file>: a text file containing one command per line"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
16 echo " OPTIONAL [max cores] : number of cores to use. Default is available cores minus one"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
17 echo ""
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
18 exit -1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
19 fi
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
20
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
21 input=$1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
22 cores=$(grep -c ^processor /proc/cpuinfo)
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
23 cores=`expr $cores - 1`
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
24 current_jobs=0
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
25 pidArray=()
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
26 jobsArray=()
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
27 totalJobs=0
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
28 executedJobs=0
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
29 finishedJobs=0
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
30
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
31 if [ $# -eq 2 ]; then
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
32 cores=$2
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
33 fi
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
34
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
35 echo "Using $cores cores"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
36
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
37
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
38 #initialize
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
39 for ((i=0 ; i < $cores ; i++))
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
40 do
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
41 pidArray[$i]=-1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
42 done
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
43
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
44 # read execution guide and launch jobs
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
45 while IFS= read -r var
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
46 do
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
47
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
48 jobsArray[$totalJobs]=$var
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
49 #echo "${jobsArray[$totalJobs]}"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
50 totalJobs=`expr $totalJobs + 1`
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
51
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
52 done < "$input"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
53
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
54
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
55 # control them and only launch as many as specified
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
56 while [[ $executedJobs -lt $totalJobs || $finishedJobs -lt $totalJobs ]]; do
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
57
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
58 # Execute job
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
59
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
60 if [[ $current_jobs -lt $cores ]]; then
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
61
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
62 ${jobsArray[$executedJobs]} &
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
63 pid=$!
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
64 for ((i=0 ; i < $cores ; i++))
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
65 do
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
66
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
67
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
68 if [[ ${pidArray[$i]} -eq -1 && $executedJobs -lt $totalJobs ]]; then
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
69 pidArray[$i]=$pid
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
70 current_jobs=`expr $current_jobs + 1`
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
71 echo "PID: $pid JOBS: $current_jobs LAUNCHING: ${jobsArray[$executedJobs]}"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
72 executedJobs=`expr $executedJobs + 1`
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
73 break
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
74 fi
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
75 done
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
76
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
77
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
78 fi
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
79
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
80 for ((i=0 ; i < $cores ; i++))
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
81 do
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
82 pid=${pidArray[$i]}
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
83 if [[ $pid -ne -1 ]]; then
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
84
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
85 ps -p $pid > /dev/null
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
86 if [[ $? == 1 ]]; then
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
87 current_jobs=`expr $current_jobs - 1`
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
88 finishedJobs=`expr $finishedJobs + 1`
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
89 echo "PID: $pid finished! Completed: $finishedJobs from total: $totalJobs"
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
90 pidArray[$i]=-1
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
91 fi
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
92
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
93 fi
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
94 done
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
95
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
96 sleep .01
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
97
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
98 done
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
99
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
100
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
101 #deactivate
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
102
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
103
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
104 #for job in `jobs -p`
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
105 #do
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
106 #echo $job
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
107 # wait $job
6fcfa4756040 Uploaded
bitlab
parents:
diff changeset
108 #done