source: trunk/IPs/systemC/processor/Morpheo/Script/execute_n.sh @ 85

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