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

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

modif distexe script

  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1#!/bin/bash
2
3#-----------------------------------------------------------
4# $Id: execute_n.sh 126 2009-06-17 18:10:41Z 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_cmd file_cpt [ nb_process ]";
30    echo "Arguments : ";
31    echo " * path_work  : directory to execute command";
32    echo " * file_cmd   : list of command";
33    echo " * file_cpt   : file to control";
34    echo " * nb_process : number of process (default (and maximum) is the number of processor)";
35    echo "";
36    echo "Note      : ";
37    echo " * This script, for each command, create a directory : Task_X (X is the number of command), and execute the command in this directory.";
38    echo " * Two file is generate : \"output\" is the output of the execution, and \"command\" is the command lunch.";
39#   echo " * A command empty (no command on a line of file) is a synchronisation with all process"
40    echo " * Don't forgot the final end of line (else the last command is not executed)";
41    echo "";
42    exit;
43}
44
45#-----[ execute_n_test_usage ]------------------------------
46function execute_n_test_usage ()
47{
48    if test ${#} -ne 3 -a ${#} -ne 4; then
49        execute_n_usage;
50    fi;
51
52    if test ! -d ${1}; then
53        echo "Directory ${1} is invalid";
54    fi;
55
56    if test -z "${MORPHEO_SCRIPT}"; then
57        echo "Environment variable MORPHEO_SCRIPT is not set";
58        execute_n_usage;
59    fi;
60
61    if test ! -f ${2}; then
62        echo "File \"${2}\" don't exist";
63        execute_n_usage;
64    fi;
65
66    if test ! -s ${2}; then
67        echo "File \"${2}\" is empty";
68        execute_n_usage;
69    fi;
70}
71
72#-----[ execute_n_main ]------------------------------------
73function execute_n ()
74{
75    local -i NB_PROCESS=$(nb_cpu);
76    local -i CPT;
77    local    PATH_WORK=${1};
78    local    FILE_CMD=${2};
79    local    FILE_CPT=${3};
80    local    FILE_CPU;
81    local    ID="cpu-${HOSTNAME}-$$"
82
83    execute_n_test_usage ${*};
84
85    if test ${#} -eq 4; then
86        if test ${4} -lt ${NB_PROCESS}; then
87            NB_PROCESS=${4};
88        fi;   
89    fi;
90
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.