Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-19 23:20:32

0001 #!/bin/bash
0002 
0003 # vim: tabstop=2:softtabstop=2:shiftwidth=2:expandtab
0004 
0005 #  .
0006 # ..: P. Chang, philip@physics.ucsd.edu
0007 
0008 usage()
0009 {
0010   echo "Usage:"
0011   echo "   sh $0 [-n NCORE=36] COMMAND_LIST.txt [PATTERN]"
0012   exit
0013 }
0014 
0015 # Command-line opts
0016 while getopts ":n:xh" OPTION; do
0017   case $OPTION in
0018     n) CORE=${OPTARG};;
0019     h) usage;;
0020     :) usage;;
0021   esac
0022 done
0023 
0024 # To shift away the parsed options
0025 shift $(($OPTIND - 1))
0026 
0027 if [ -z ${CORE} ]; then CORE=36; fi
0028 
0029 cores=${CORE}
0030 
0031 # must provide the job
0032 if [ "x${1}" == "x" ]; then
0033   echo "Error: Must provide the job commands txt file"
0034   usage
0035   exit
0036 fi
0037 
0038 JOBTXTFILE=$1
0039 
0040 MACRONAME=$(mktemp stupid_numbers_XXXXXXXXX)
0041 MACRO=/tmp/${MACRONAME}.txt
0042 rm $MACRONAME
0043 
0044 # filter some jobs
0045 if [ "x${2}" != "x" ]; then
0046   cat $1 | grep -v '^#' | grep $2 > ${MACRO}
0047 else
0048   cat $1 | grep -v '^#' > ${MACRO}
0049 fi
0050 
0051 # run the job in parallel
0052 xargs --arg-file=${MACRO} \
0053       --max-procs=$cores  \
0054       --replace \
0055       --verbose \
0056       /bin/sh -c "{}"
0057 
0058 #eof