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

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

modif distexe script

  • Property svn:keywords set to Id
File size: 3.1 KB
RevLine 
[85]1#!/bin/bash
2
[82]3#-----------------------------------------------------------
4# $Id: execute_n.sh 126 2009-06-17 18:10:41Z rosiere $
5#-----------------------------------------------------------
[2]6
[124]7#-----[ my_date ]-------------------------------------------
8function my_date ()
9{
10    date +"%F %T";
11}
[2]12
[112]13#-----[ nb_cpu ]--------------------------------------------
14function nb_cpu ()
[2]15{
[112]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{
[126]29    echo "Usage     : ${0} path_word file_cmd file_cpt [ nb_process ]";
[78]30    echo "Arguments : ";
[124]31    echo " * path_work  : directory to execute command";
[126]32    echo " * file_cmd   : list of command";
33    echo " * file_cpt   : file to control";
[78]34    echo " * nb_process : number of process (default (and maximum) is the number of processor)";
[2]35    echo "";
[78]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.";
[112]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)";
[2]41    echo "";
42    exit;
43}
44
[112]45#-----[ execute_n_test_usage ]------------------------------
46function execute_n_test_usage ()
[2]47{
[126]48    if test ${#} -ne 3 -a ${#} -ne 4; then
[112]49        execute_n_usage;
[2]50    fi;
51
[112]52    if test ! -d ${1}; then
53        echo "Directory ${1} is invalid";
54    fi;
[2]55
[112]56    if test -z "${MORPHEO_SCRIPT}"; then
57        echo "Environment variable MORPHEO_SCRIPT is not set";
[124]58        execute_n_usage;
[2]59    fi;
60
[112]61    if test ! -f ${2}; then
62        echo "File \"${2}\" don't exist";
63        execute_n_usage;
[2]64    fi;
65
[112]66    if test ! -s ${2}; then
67        echo "File \"${2}\" is empty";
68        execute_n_usage;
[2]69    fi;
70}
71
[112]72#-----[ execute_n_main ]------------------------------------
73function execute_n ()
[2]74{
[112]75    local -i NB_PROCESS=$(nb_cpu);
76    local -i CPT;
[124]77    local    PATH_WORK=${1};
[112]78    local    FILE_CMD=${2};
[126]79    local    FILE_CPT=${3};
[112]80    local    FILE_CPU;
81    local    ID="cpu-${HOSTNAME}-$$"
[2]82
[112]83    execute_n_test_usage ${*};
[2]84
[126]85    if test ${#} -eq 4; then
86        if test ${4} -lt ${NB_PROCESS}; then
87            NB_PROCESS=${4};
[124]88        fi;   
[2]89    fi;
90
[124]91    FILE_CPU="${PATH_WORK}/${ID}";
[2]92
[124]93    echo "  * {"$(my_date)"} <${HOSTNAME}> ${NB_PROCESS} process";
[2]94
95    local -i IT_NB_PROCESS=1;
96    local -i PID=$$;
97
[112]98    echo "${NB_PROCESS}" > ${FILE_CPU};
[2]99
100    # create the same number of thread that processor
[112]101    while test ${IT_NB_PROCESS} -le ${NB_PROCESS}; do
[124]102        ${MORPHEO_SCRIPT}/execute.sh ${PATH_WORK} ${FILE_CMD} ${FILE_CPT} ${FILE_CPU} "${HOSTNAME}-${IT_NB_PROCESS}" &
[112]103        IT_NB_PROCESS=$((${IT_NB_PROCESS}+1));
[2]104
[112]105        if test "$$" -ne ${PID}; then
[2]106            break;
107        fi;
108    done
[124]109
110    echo "  * {"$(my_date)"} <${HOSTNAME}> all process working";
[2]111}
112
113#-----[ Corps ]---------------------------------------------
[112]114execute_n ${*};
Note: See TracBrowser for help on using the repository browser.