1 | #!/bin/sh |
---|
2 | |
---|
3 | #-----[ variable ]------------------------------------------ |
---|
4 | declare -a COMMAND; |
---|
5 | declare -i NB_PROCESS; |
---|
6 | declare -i CPT; |
---|
7 | declare FILE_CMD; |
---|
8 | declare FILE_CPT; |
---|
9 | declare FILE_CPU; |
---|
10 | declare ID="cpu-$HOSTNAME-$$" |
---|
11 | |
---|
12 | #-----[ usage ]--------------------------------------------- |
---|
13 | function usage () |
---|
14 | { |
---|
15 | echo "Usage : $0 file [ nb_process ]"; |
---|
16 | echo " * file : list of command"; |
---|
17 | echo " * nb_process : number of process (default (and maximum) is the number of processor)"; |
---|
18 | echo ""; |
---|
19 | echo "Note - This script, for each command, create a directory : Task_X (X is the number of command), and execute the command in this directory."; |
---|
20 | echo " - Two file is generate : \"output\" is the output of the execution, and \"command\" is the command lunch."; |
---|
21 | echo " - A command empty (no command on a line of file1) is a synchronisation with all process" |
---|
22 | echo " - Don't forgot the final end of line (else the last command is not executed"; |
---|
23 | echo ""; |
---|
24 | exit; |
---|
25 | } |
---|
26 | |
---|
27 | #-----[ nb_cpu ]-------------------------------------------- |
---|
28 | function nb_cpu () |
---|
29 | { |
---|
30 | local FILE_CPUINFO=/proc/cpuinfo; |
---|
31 | if test ! -f $FILE_CPUINFO; then |
---|
32 | echo "\"$FILE_CPUINFO\" don't exist." |
---|
33 | usage; |
---|
34 | fi; |
---|
35 | |
---|
36 | eval "$1=`grep -c \"processor\" $FILE_CPUINFO`"; |
---|
37 | } |
---|
38 | |
---|
39 | #-----[ test_usage ]---------------------------------------- |
---|
40 | function test_usage () |
---|
41 | { |
---|
42 | if test $# -ne 1 -a $# -ne 2; then |
---|
43 | usage; |
---|
44 | fi; |
---|
45 | |
---|
46 | if test ! -f $1; then |
---|
47 | echo "File \"$1\" don't exist"; |
---|
48 | usage; |
---|
49 | fi; |
---|
50 | |
---|
51 | if test ! -s $1; then |
---|
52 | echo "File \"$1\" is empty"; |
---|
53 | usage; |
---|
54 | fi; |
---|
55 | } |
---|
56 | |
---|
57 | #-----[ main ]---------------------------------------------- |
---|
58 | function main () |
---|
59 | { |
---|
60 | nb_cpu NB_PROCESS; |
---|
61 | |
---|
62 | test_usage $*; |
---|
63 | |
---|
64 | if test $# -eq 2; then |
---|
65 | if test $2 -lt $NB_PROCESS; then |
---|
66 | NB_PROCESS=$2; |
---|
67 | fi; |
---|
68 | fi; |
---|
69 | |
---|
70 | FILE_CMD=$1; |
---|
71 | FILE_CPT="$HOME/control-"`basename $1`; |
---|
72 | FILE_CPU="$HOME/$ID"; |
---|
73 | |
---|
74 | echo "<$0>" ; |
---|
75 | echo " * Initialisation ...." ; |
---|
76 | echo " - host name : $HOSTNAME" ; |
---|
77 | echo " - number of process : $NB_PROCESS" ; |
---|
78 | |
---|
79 | local -i IT_NB_PROCESS=1; |
---|
80 | local -i PID=$$; |
---|
81 | |
---|
82 | echo "$NB_PROCESS" > $FILE_CPU; |
---|
83 | |
---|
84 | # create the same number of thread that processor |
---|
85 | while test $IT_NB_PROCESS -le $NB_PROCESS; do |
---|
86 | execute.sh $FILE_CMD $FILE_CPT $FILE_CPU & |
---|
87 | IT_NB_PROCESS=$(($IT_NB_PROCESS+1)); |
---|
88 | |
---|
89 | if test "$$" -ne $PID; then |
---|
90 | break; |
---|
91 | fi; |
---|
92 | done |
---|
93 | } |
---|
94 | |
---|
95 | #-----[ Corps ]--------------------------------------------- |
---|
96 | main $*; |
---|