123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #!/bin/sh -efu
- #
- # The 'unipbs' allows users to launch a specified UrQMD input file
- # in the Portable Batch System. It creates and spawns a number of jobs
- # at the node.
- #
- # Copyright (C) 2019 Nikita (arei) Ermakov <coffe92@gmail.com>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
- #
- PROG="unipbs"
- show_help()
- {
- cat <<EOF
- $PROG - create and spawn jobs to Portable Batch System
- Usage: $PROG <options> -- [<PBS options>]
- Options:
- -j --jobs number of jobs
- -i --input input file path
- -o --output output directory to place files (default: out)
- -u --urqmd path to the UrQMD executable
- -g --unigen path to the urqmd2u converter executable
- -f --fake do not submit jobs, just create tree structure
- -n --nowait do not wait a few seconds before building and running jobs
- -h --help print this help
- PBS options: this optional arguments will be transfered directly to the qsub command.
- EOF
- exit 0
- }
- fatal()
- {
- echo "$@"
- exit 1
- }
- # Parse input arguments
- if [ "$#" = "0" ]; then
- show_help
- fi
- OPTS="$(getopt -n "$PROG" -o "j:,i:,o:,h,u:,g:,f,n" -l "jobs:,input:,output:,help,urqmd:,unigen:,fake,nowait" -- "$@")" ||
- show_help
- eval set -- "$OPTS"
- while :; do
- case "$1" in
- --) shift; break
- ;;
- -j|--jobs) shift; njobs="$1"
- ;;
- -i|--input) shift; infile="$1"
- ;;
- -o|--output) shift; outdir="$1"
- ;;
- -g|--unigen) shift; unigen="$1"
- ;;
- -u|--urqmd) shift; urqmd="$1"
- ;;
- -h|--help) show_help
- ;;
- -f|--fake) fake=1
- ;;
- -n|--nowait) nowait=1
- ;;
- *) fatal "Unrecognized option: $1"
- ;;
- esac
- shift
- done
- # Create or go to the output directory
- outdir="${outdir-out}"
- [ -d "${outdir}" ] || mkdir -p "$outdir"
- # Check UrQMD
- urqmd="$(readlink -f "${urqmd-}")"
- [ -x "${urqmd}" ] || fatal "Can't find UrQMD at ${urqmd} or it is not an executable (links was resolved)"
- # Check unigen
- unigen="$(readlink -f "${unigen-}")"
- [ -x "${unigen}" ] || fatal "Can't find unigen at ${unigen} or it is not an executable (links was resolved)"
- # Check infile
- infile="$(readlink -f "${infile-}")"
- [ -f "${infile}" ] || fatal "Can't find input file at ${infile} (links was resolved)"
- # Wait few sec to take a time to user to check settings
- ftn="$(grep -i "^#f1[0-9]" $infile | tail -1 | sed -e "s;#f;;gI")"
- pro="$(grep -i "^pro" $infile | tail -1 | tr -s " " | sed -e "s;^pro ;;gI")"
- tar="$(grep -i "^tar" $infile | tail -1 | tr -s " " | sed -e "s;^tar ;;gI")"
- imp="$(grep -i "^imp" $infile | tail -1 | tr -s " " | sed -e "s;^imp ;;gI")"
- cat << EOF
- Using UrQMD: $urqmd
- Using urqmd2u: $unigen
- Using inputfile: $infile
- Output directory: $outdir
- ------- INPUT FILE DETAILS -------
- Output file type will be f$ftn
- Projectile: $pro
- Target: $tar
- Impact: $imp
- EOF
- if [ "${nowait-}" = "" ]; then
- echo "Preparing to run jobs..."
- for (( i=5; i > 0; i=i-1 )); do
- echo -ne "$i sec... "
- sleep 1
- done
- fi
- pushd "$outdir" >/dev/null
- # Create jobs directories
- for (( i=0; i < njobs; i=i+1 )); do
- echo -ne "\nBuilding the job $i... "
- temp="$(mktemp -d "job.$i.XXXXXXX")"
- pushd "$temp" >/dev/null
- cp "$infile" inputfile
- seed="$(printf "%d" 0x$(xxd -l 3 -ps -c 10 /dev/random))"
- events="$(grep -i "^nev" inputfile | tr -s " " | tail -1 | cut -d" " -f2)"
- if grep -i -q "^rsd" inputfile; then
- sed -i "s;^rsd.*;rsd $seed;gI" inputfile
- else
- sed -i "s;^xxx;rsd $seed\nxxx;gI" inputfile
- fi
- ln -s "$urqmd" urqmd
- ln -s "$unigen" unigen
- cat > script << EOF
- #!/bin/sh -efu
- # This script was automatically generated at $(date -R) by unipbs
- export ftn09="inputfile"
- export ftn$ftn="out_$seed.$ftn"
- export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(dirname $unigen)"
- export UNIGEN="$(dirname $unigen)"
- time ./urqmd
- time ./unigen "out_$seed.$ftn" "out_${seed}_$ftn.root" "$events"
- EOF
- chmod +x script
- echo "DONE"
- if [ "${fake-}" = "" ]; then
- qsub "$@" script
- else
- echo "qsub $@ script"
- fi
- popd >/dev/null
- done
- # Go back
- popd >/dev/null
|