Changeset 112 for trunk/IPs/systemC/processor/Morpheo/Script/execute_n.sh
- Timestamp:
- Mar 18, 2009, 11:36:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/IPs/systemC/processor/Morpheo/Script/execute_n.sh
r85 r112 5 5 #----------------------------------------------------------- 6 6 7 #-----[ variable ]------------------------------------------ 8 declare -a COMMAND; 9 declare -i NB_PROCESS; 10 declare -i CPT; 11 declare FILE_CMD; 12 declare FILE_CPT; 13 declare FILE_CPU; 14 declare ID="cpu-${HOSTNAME}-$$" 7 #-----[ global variable ]----------------------------------- 15 8 16 #-----[ usage ]---------------------------------------------17 function usage()9 #-----[ nb_cpu ]-------------------------------------------- 10 function nb_cpu () 18 11 { 19 echo "Usage : $0 file [ nb_process ]"; 12 local FILE_CPUINFO=/proc/cpuinfo; 13 if test ! -f ${FILE_CPUINFO}; then 14 echo "\"${FILE_CPUINFO}\" don't exist." 15 usage; 16 fi; 17 18 #eval "${1}=`grep -c \"processor\" ${FILE_CPUINFO}`"; 19 grep -c "processor" ${FILE_CPUINFO}; 20 } 21 22 #-----[ execute_n_usage ]----------------------------------- 23 function execute_n_usage () 24 { 25 echo "Usage : ${0} word_dir file [ nb_process ]"; 20 26 echo "Arguments : "; 27 echo " * work_dir : directory to execute command"; 21 28 echo " * file : list of command"; 22 29 echo " * nb_process : number of process (default (and maximum) is the number of processor)"; … … 25 32 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 33 echo " * Two file is generate : \"output\" is the output of the execution, and \"command\" is the command lunch."; 27 28 echo " * Don't forgot the final end of line (else the last command is not executed ";34 # echo " * A command empty (no command on a line of file) is a synchronisation with all process" 35 echo " * Don't forgot the final end of line (else the last command is not executed)"; 29 36 echo ""; 30 37 exit; 31 38 } 32 39 33 #-----[ nb_cpu ]--------------------------------------------34 function nb_cpu()40 #-----[ execute_n_test_usage ]------------------------------ 41 function execute_n_test_usage () 35 42 { 36 local FILE_CPUINFO=/proc/cpuinfo; 37 if test ! -f $FILE_CPUINFO; then 38 echo "\"${FILE_CPUINFO}\" don't exist." 39 usage; 43 if test ${#} -ne 2 -a ${#} -ne 3; then 44 execute_n_usage; 40 45 fi; 41 46 42 eval "$1=`grep -c \"processor\" ${FILE_CPUINFO}`"; 43 } 44 45 #-----[ test_usage ]---------------------------------------- 46 function test_usage () 47 { 48 if test $# -ne 1 -a $# -ne 2; then 49 usage; 47 if test ! -d ${1}; then 48 echo "Directory ${1} is invalid"; 50 49 fi; 51 50 52 if test ! -f $1; then53 echo "File \"$1\" don't exist";54 51 if test -z "${MORPHEO_SCRIPT}"; then 52 echo "Environment variable MORPHEO_SCRIPT is not set"; 53 distexe_usage; 55 54 fi; 56 55 57 if test ! -s $1; then 58 echo "File \"$1\" is empty"; 59 usage; 56 if test ! -f ${2}; then 57 echo "File \"${2}\" don't exist"; 58 execute_n_usage; 59 fi; 60 61 if test ! -s ${2}; then 62 echo "File \"${2}\" is empty"; 63 execute_n_usage; 60 64 fi; 61 65 } 62 66 63 #-----[ main ]----------------------------------------------64 function main ()67 #-----[ execute_n_main ]------------------------------------ 68 function execute_n () 65 69 { 66 nb_cpu NB_PROCESS; 70 local -i NB_PROCESS=$(nb_cpu); 71 local -i CPT; 72 local WORK_DIR=${1}; 73 local FILE_CMD=${2}; 74 local FILE_CPT; 75 local FILE_CPU; 76 local ID="cpu-${HOSTNAME}-$$" 67 77 68 test_usage $*;78 execute_n_test_usage ${*}; 69 79 70 if test $ #-eq 2; then71 if test $ 2 -lt $NB_PROCESS; then72 NB_PROCESS=$ 2;80 if test ${#} -eq 2; then 81 if test ${3} -lt ${NB_PROCESS}; then 82 NB_PROCESS=${3}; 73 83 fi; 74 84 fi; 75 85 76 FILE_CMD=$1; 77 FILE_CPT="$HOME/control-"`basename $1`; 78 FILE_CPU="$HOME/$ID"; 86 FILE_CPT="${WORK_DIR}/control-"$(basename ${FILE_CMD}); 87 FILE_CPU="${WORK_DIR}/${ID}"; 79 88 80 echo "<$0>" ; 81 echo " * Initialisation ...." ; 82 echo " - host name : $HOSTNAME" ; 83 echo " - number of process : $NB_PROCESS" ; 89 echo " * <${HOSTNAME}> ${NB_PROCESS} process"; 84 90 85 91 local -i IT_NB_PROCESS=1; 86 92 local -i PID=$$; 87 93 88 echo "$ NB_PROCESS" > $FILE_CPU;94 echo "${NB_PROCESS}" > ${FILE_CPU}; 89 95 90 96 # create the same number of thread that processor 91 while test $ IT_NB_PROCESS -le $NB_PROCESS; do92 execute.sh $FILE_CMD $FILE_CPT $FILE_CPU&93 IT_NB_PROCESS=$(($ IT_NB_PROCESS+1));97 while test ${IT_NB_PROCESS} -le ${NB_PROCESS}; do 98 ${MORPHEO_SCRIPT}/execute.sh ${WORK_DIR} ${FILE_CMD} ${FILE_CPT} ${FILE_CPU} & 99 IT_NB_PROCESS=$((${IT_NB_PROCESS}+1)); 94 100 95 if test "$$" -ne $ PID; then101 if test "$$" -ne ${PID}; then 96 102 break; 97 103 fi; … … 100 106 101 107 #-----[ Corps ]--------------------------------------------- 102 main $*;108 execute_n ${*};
Note: See TracChangeset
for help on using the changeset viewer.