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

Last change on this file since 124 was 124, checked in by rosiere, 15 years ago

1) Add test and configuration
2) Fix Bug
3) Add log file in load store unit
4) Fix Bug in environment

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1#!/bin/bash
2
3#-----------------------------------------------------------
4# $Id: execute_n.sh 124 2009-06-17 12:11:25Z rosiere $
5#-----------------------------------------------------------
6
7#-----[ my_date ]-------------------------------------------
8function my_date ()
9{
10    date +"%F %T";
11}
12
13#-----[ nb_cpu ]--------------------------------------------
14function nb_cpu ()
15{
16    local FILE_CPUINFO=/proc/cpuinfo;
17    if test ! -f ${FILE_CPUINFO}; then
18        echo "\"${FILE_CPUINFO}\" don't exist."
19        usage;
20    fi;
21
22    #eval "${1}=`grep -c \"processor\" ${FILE_CPUINFO}`";
23    grep -c "processor" ${FILE_CPUINFO};
24}
25
26#-----[ execute_n_usage ]-----------------------------------
27function execute_n_usage ()
28{
29    echo "Usage     : ${0} path_word file [ nb_process ]";
30    echo "Arguments : ";
31    echo " * path_work  : directory to execute command";
32    echo " * file       : list of command";
33    echo " * nb_process : number of process (default (and maximum) is the number of processor)";
34    echo "";
35    echo "Note      : ";
36    echo " * This script, for each command, create a directory : Task_X (X is the number of command), and execute the command in this directory.";
37    echo " * Two file is generate : \"output\" is the output of the execution, and \"command\" is the command lunch.";
38#   echo " * A command empty (no command on a line of file) is a synchronisation with all process"
39    echo " * Don't forgot the final end of line (else the last command is not executed)";
40    echo "";
41    exit;
42}
43
44#-----[ execute_n_test_usage ]------------------------------
45function execute_n_test_usage ()
46{
47    if test ${#} -ne 2 -a ${#} -ne 3; then
48        execute_n_usage;
49    fi;
50
51    if test ! -d ${1}; then
52        echo "Directory ${1} is invalid";
53    fi;
54
55    if test -z "${MORPHEO_SCRIPT}"; then
56        echo "Environment variable MORPHEO_SCRIPT is not set";
57        execute_n_usage;
58    fi;
59
60    if test ! -f ${2}; then
61        echo "File \"${2}\" don't exist";
62        execute_n_usage;
63    fi;
64
65    if test ! -s ${2}; then
66        echo "File \"${2}\" is empty";
67        execute_n_usage;
68    fi;
69}
70
71#-----[ execute_n_main ]------------------------------------
72function execute_n ()
73{
74    local -i NB_PROCESS=$(nb_cpu);
75    local -i CPT;
76    local    PATH_WORK=${1};
77    local    FILE_CMD=${2};
78    local    FILE_CPT;
79    local    FILE_CPU;
80    local    ID="cpu-${HOSTNAME}-$$"
81
82    execute_n_test_usage ${*};
83
84    if test ${#} -eq 3; then
85        if test ${3} -lt ${NB_PROCESS}; then
86            NB_PROCESS=${3};
87        fi;   
88    fi;
89
90    FILE_CPT="${PATH_WORK}/control-"$(basename ${FILE_CMD});
91    FILE_CPU="${PATH_WORK}/${ID}";
92
93    echo "  * {"$(my_date)"} <${HOSTNAME}> ${NB_PROCESS} process";
94
95    local -i IT_NB_PROCESS=1;
96    local -i PID=$$;
97
98    echo "${NB_PROCESS}" > ${FILE_CPU};
99
100    # create the same number of thread that processor
101    while test ${IT_NB_PROCESS} -le ${NB_PROCESS}; do
102        ${MORPHEO_SCRIPT}/execute.sh ${PATH_WORK} ${FILE_CMD} ${FILE_CPT} ${FILE_CPU} "${HOSTNAME}-${IT_NB_PROCESS}" &
103        IT_NB_PROCESS=$((${IT_NB_PROCESS}+1));
104
105        if test "$$" -ne ${PID}; then
106            break;
107        fi;
108    done
109
110    echo "  * {"$(my_date)"} <${HOSTNAME}> all process working";
111}
112
113#-----[ Corps ]---------------------------------------------
114execute_n ${*};
Note: See TracBrowser for help on using the repository browser.