Parcourir la source

Add unipbs script to run a jobs at the PBS

Nikita arei Ermakov il y a 5 ans
Parent
commit
9cc5015783
1 fichiers modifiés avec 165 ajouts et 0 suppressions
  1. 165 0
      dc-scripts/unipbs

+ 165 - 0
dc-scripts/unipbs

@@ -0,0 +1,165 @@
+#!/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
+  -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 "^nev" inputfile | tr -s " " | tail -1 | cut -d" " -f2)"
+  if grep -q "^rsd" inputfile; then
+    sed -i "s;^rsd.*;rsd $seed;g" inputfile
+  else
+    sed -i "s;^xxx;rsd $seed\nxxx;g" 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"
+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