[Swift-commit] r6892 - SwiftTutorials/CIC_2013-08-09/app

wilde at ci.uchicago.edu wilde at ci.uchicago.edu
Mon Aug 19 19:27:02 CDT 2013


Author: wilde
Date: 2013-08-19 19:27:02 -0500 (Mon, 19 Aug 2013)
New Revision: 6892

Added:
   SwiftTutorials/CIC_2013-08-09/app/addsims.sh
   SwiftTutorials/CIC_2013-08-09/app/genrand.sh
   SwiftTutorials/CIC_2013-08-09/app/simulate2.sh
Modified:
   SwiftTutorials/CIC_2013-08-09/app/simulate.sh
Log:
Adjust apps

Added: SwiftTutorials/CIC_2013-08-09/app/addsims.sh
===================================================================
--- SwiftTutorials/CIC_2013-08-09/app/addsims.sh	                        (rev 0)
+++ SwiftTutorials/CIC_2013-08-09/app/addsims.sh	2013-08-20 00:27:02 UTC (rev 6892)
@@ -0,0 +1,8 @@
+#! /bin/bash
+
+while read f1 ; do
+  read -u 3 f2 
+  if [ _$f1 = _ ]; then f1=0; fi
+  if [ _$f2 = _ ]; then f2=0; fi
+  echo $(($f1+$f2)) 
+done <$1 3<$2


Property changes on: SwiftTutorials/CIC_2013-08-09/app/addsims.sh
___________________________________________________________________
Added: svn:executable
   + *

Copied: SwiftTutorials/CIC_2013-08-09/app/genrand.sh (from rev 6868, SwiftTutorials/CIC_2013-08-09/app/simulate.sh)
===================================================================
--- SwiftTutorials/CIC_2013-08-09/app/genrand.sh	                        (rev 0)
+++ SwiftTutorials/CIC_2013-08-09/app/genrand.sh	2013-08-20 00:27:02 UTC (rev 6892)
@@ -0,0 +1,38 @@
+#! /bin/bash
+
+log() {
+  printf "Start time: "; /bin/date
+  printf "Job is running on node: "; /bin/hostname
+  printf "Job running as user: "; /usr/bin/id
+
+  echo "Environment:"
+  /bin/env | /bin/sort
+}
+
+runtime=${1:-0}
+range=${2:-100}
+biasfile=${3:-nobias}
+scale=${4:-1}
+n=${5:-1}
+
+if [ $biasfile = nobias ]; then
+  offset=0
+else
+  read offset <$biasfile
+fi
+
+# run for some number of "timesteps"
+
+sleep $runtime
+
+# emit n "simulation results", scaled and biased by the specified argument values
+
+for ((i=0;i<n;i++)); do
+  value=$(((($RANDOM)*32768)+$RANDOM))
+  echo $(( ($value%range)*scale+offset))
+done
+
+# log environmental data
+
+log 1>&2
+

Modified: SwiftTutorials/CIC_2013-08-09/app/simulate.sh
===================================================================
--- SwiftTutorials/CIC_2013-08-09/app/simulate.sh	2013-08-19 21:42:07 UTC (rev 6891)
+++ SwiftTutorials/CIC_2013-08-09/app/simulate.sh	2013-08-20 00:27:02 UTC (rev 6892)
@@ -1,5 +1,14 @@
 #! /bin/bash
 
+log() {
+  printf "Start time: "; /bin/date
+  printf "Job is running on node: "; /bin/hostname
+  printf "Job running as user: "; /usr/bin/id
+
+  echo "Environment:"
+  /bin/env | /bin/sort
+}
+
 runtime=${1:-0}
 range=${2:-100}
 biasfile=${3:-nobias}
@@ -22,3 +31,8 @@
   value=$(((($RANDOM)*32768)+$RANDOM))
   echo $(( ($value%range)*scale+offset))
 done
+
+# log environmental data
+
+log 1>&2
+

Added: SwiftTutorials/CIC_2013-08-09/app/simulate2.sh
===================================================================
--- SwiftTutorials/CIC_2013-08-09/app/simulate2.sh	                        (rev 0)
+++ SwiftTutorials/CIC_2013-08-09/app/simulate2.sh	2013-08-20 00:27:02 UTC (rev 6892)
@@ -0,0 +1,131 @@
+#! /bin/bash
+
+printparams()
+{
+  printf "\nSimulation parameters:\n\n"
+  echo bias=$bias
+  echo biasfile=$biasfile
+  echo initseed=$initseed
+  echo log=$log
+  echo paramfile=$paramfile
+  echo range=$range
+  echo scale=$scale
+  echo seedfile=$seedfile
+  echo timesteps=$timesteps
+  echo output width=$width
+}
+
+log() {
+  printf "\nCalled as: $0: $cmdargs\n\n"
+  printf "Start time: "; /bin/date
+  printf "Running on node: "; /bin/hostname
+  printf "Running as user: "; /usr/bin/id
+  printparams
+  printf "\nEnvironment:\n\n"
+  /bin/env | /bin/sort
+}
+
+addsims() {
+  while read f1 ; do
+    read -u 3 f2 
+    if [ _$f1 = _ ]; then f1=0; fi
+    if [ _$f2 = _ ]; then f2=0; fi
+    printf "%${width}d\n" $(($f1+$f2)) 
+  done <$1 3<$2
+}
+
+# set defaults
+
+bias=0
+biasfile=none
+initseed=none
+log=yes
+paramfile=none
+range=100
+scale=1
+seedfile=none
+timesteps=0
+nvalues=1
+width=8
+cmdargs="$*"
+
+usage()
+{
+  echo $0: usage:
+  cat <<END
+    -t|--timesteps  number of simulated "timesteps" in seconds (determines runtime)
+    -r|--range      range (limit) of generated results
+    -B|--biasfile   file of integer biases to add to results
+    -l|--log        generate a log in stderr if not null
+    -x|--scale      scale the results by this integer
+    -n|--nvalues    print this many values per simulation            
+    -S|--seedfile   use this file (containing integer seeds [0..32767]) one per line
+    -i|--seed       use this integer [0..32767] as a seed
+    -b|--bias       offset bias: add this integer to all results
+    -p|--paramfile  take these parameters (in form param=value) from this file
+    -h|-?|?|--help  print this help
+END
+}
+
+while [ $# -gt 0 ]; do
+  case $1 in
+    -t|--timesteps) timesteps=$2 ;;
+    -r|--range)     range=$2     ;;   
+    -B|--biasfile)  biasfile=$2  ;;
+    -l|--log)       log=$2       ;;
+    -x|--scale)     scale=$2     ;;
+    -n|--nvalues)   nvalues=$2   ;;       
+    -S|--seedfile)  seedfile=$2  ;;
+    -s|--seed)      initseed=$2  ;;
+    -b|--bias)      bias=$2      ;;
+    -p|--paramfile) paramfile=$2 ;;
+    -w|--width)     width=$2     ;;
+    -h|-?|--help|*) usage; exit  ;;
+  esac
+  shift 2
+done
+    
+# process initial seed
+
+if [ $initseed != none ]; then
+  RANDOM=$initseed
+fi
+
+# process file of seeds
+
+if [ $seedfile != none ]; then
+  seed=0
+  while read $seedfile s; do
+    seed=$(($seed+$s))
+  done <$seedfile
+  RANDOM=$seed
+fi
+
+# run for some number of "timesteps"
+
+sleep $timesteps
+
+# emit n "simulation results" scaled and biased by argument values
+
+simout=$(mktemp simout.XXXX)
+for ((i=0;i<nvalues;i++)); do
+  # value=$(( (($RANDOM)*(2**16))+$RANDOM ))
+  value=$(( (($RANDOM)*(2**48)) + (($RANDOM)*(2**32)) + (($RANDOM)*(2**16)) + $RANDOM ))
+  printf "%${width}d\n" $(( ($value%range)*scale+bias))
+done  >$simout
+
+# process file of biases
+
+if [ $biasfile != none ]; then
+  printf "\nMerged:\n\n"
+  addsims $simout $biasfile
+else
+  cat $simout
+fi
+rm $simout
+
+# log environmental data
+
+if [ $log != none ]; then
+  log 1>&2
+fi


Property changes on: SwiftTutorials/CIC_2013-08-09/app/simulate2.sh
___________________________________________________________________
Added: svn:executable
   + *




More information about the Swift-commit mailing list