[Swift-commit] r8409 - in SwiftApps/subjobs: . simanalyze simanalyze/app simanalyze/part05 simanalyze/part06

ketan at ci.uchicago.edu ketan at ci.uchicago.edu
Tue Mar 24 14:55:06 CDT 2015


Author: ketan
Date: 2015-03-24 14:55:06 -0500 (Tue, 24 Mar 2015)
New Revision: 8409

Added:
   SwiftApps/subjobs/simanalyze/
   SwiftApps/subjobs/simanalyze/app/
   SwiftApps/subjobs/simanalyze/app/simulate
   SwiftApps/subjobs/simanalyze/app/stats
   SwiftApps/subjobs/simanalyze/part05/
   SwiftApps/subjobs/simanalyze/part05/cetus.conf
   SwiftApps/subjobs/simanalyze/part05/p5.swift
   SwiftApps/subjobs/simanalyze/part05/runcetus.sh
   SwiftApps/subjobs/simanalyze/part05/swift.properties
   SwiftApps/subjobs/simanalyze/part06/
   SwiftApps/subjobs/simanalyze/part06/cetus.conf
   SwiftApps/subjobs/simanalyze/part06/p6.swift
   SwiftApps/subjobs/simanalyze/part06/runcetus.sh
   SwiftApps/subjobs/simanalyze/part06/swift.properties
Log:
simanalyze under subjobs

Added: SwiftApps/subjobs/simanalyze/app/simulate
===================================================================
--- SwiftApps/subjobs/simanalyze/app/simulate	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/app/simulate	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,135 @@
+#! /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 as user: "; /usr/bin/id
+  printf "Running on node: "; /bin/hostname
+  printf "Node IP address: "; /bin/hostname -I
+  printparams
+  printf "\nEnvironment:\n\n"
+  printenv | sort
+}
+
+addsims() {
+  while read f1 ; do
+    read -u 3 f2 
+    if [ _$f1 = _ ]; then f1=$lastf1; fi
+    if [ _$f2 = _ ]; then f2=$lastf2; fi
+    printf "%${width}d\n" $(($f1+$f2)) 
+    lastf1=$f1
+    lastf2=$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 $( basename $0 ): usage:
+  cat <<END
+    -b|--bias       offset bias: add this integer to all results
+    -B|--biasfile   file of integer biases to add to results
+    -l|--log        generate a log in stderr if not null
+    -n|--nvalues    print this many values per simulation            
+    -r|--range      range (limit) of generated results
+    -s|--seed       use this integer [0..32767] as a seed
+    -S|--seedfile   use this file (containing integer seeds [0..32767]) one per line
+    -t|--timesteps  number of simulated "timesteps" in seconds (determines runtime)
+    -x|--scale      scale the results by this integer
+    -h|-?|?|--help  print this help
+END
+}
+
+# FIXME: NOT YET IMPLEMENTED:
+#    -p|--paramfile  take these parameters (in form param=value) from this file 
+#    -p|--paramfile) paramfile=$2 ;;
+
+while [ $# -gt 0 ]; do
+  case $1 in
+    -b|--bias)      bias=$2      ;;
+    -B|--biasfile)  biasfile=$2  ;;
+    -l|--log)       log=$2       ;;
+    -n|--nvalues)   nvalues=$2   ;;       
+    -s|--seed)      initseed=$2  ;;
+    -S|--seedfile)  seedfile=$2  ;;
+    -t|--timesteps) timesteps=$2 ;;
+    -r|--range)     range=$2     ;;   
+    -w|--width)     width=$2     ;;
+    -x|--scale)     scale=$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 (nvalues) "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
+  addsims $simout $biasfile
+else
+  cat $simout
+fi
+rm $simout
+
+# log environmental data
+
+if [ $log != off ]; then
+  log 1>&2
+fi


Property changes on: SwiftApps/subjobs/simanalyze/app/simulate
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftApps/subjobs/simanalyze/app/stats
===================================================================
--- SwiftApps/subjobs/simanalyze/app/stats	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/app/stats	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+log() {
+  printf "\nCalled as: $0: $cmdargs\n\n"
+  printf "Start time: "; /bin/date
+  printf "Running as user: "; /usr/bin/id
+  printf "Running on node: "; /bin/hostname
+  printf "Node IP address: "; /bin/hostname -I
+  printf "\nEnvironment:\n\n"
+  printenv | sort
+}
+
+awk '
+
+{ sum += $1}
+
+END { printf("%d\n",sum/NR) }
+' $*
+log 1>&2


Property changes on: SwiftApps/subjobs/simanalyze/app/stats
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftApps/subjobs/simanalyze/part05/cetus.conf
===================================================================
--- SwiftApps/subjobs/simanalyze/part05/cetus.conf	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part05/cetus.conf	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1 @@
+link ../../conf/cetus.conf
\ No newline at end of file


Property changes on: SwiftApps/subjobs/simanalyze/part05/cetus.conf
___________________________________________________________________
Added: svn:special
   + *

Added: SwiftApps/subjobs/simanalyze/part05/p5.swift
===================================================================
--- SwiftApps/subjobs/simanalyze/part05/p5.swift	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part05/p5.swift	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,29 @@
+type file;
+
+app (file out, file log) simulation (int sim_steps, int sim_range, int sim_values)
+{
+  bgsh "/home/ketan/swift-tutorial/app/simulate" "--timesteps" sim_steps "--range" sim_range "--nvalues" sim_values stdout=@out stderr=@log;
+}
+
+app (file out, file log) analyze (file s[])
+{
+  bgsh "/home/ketan/swift-tutorial/app/stats" filenames(s) stdout=@out stderr=@log;
+}
+
+int nsim   = toInt(arg("nsim",   "10"));
+int steps  = toInt(arg("steps",  "1"));
+int range  = toInt(arg("range",  "100"));
+int values = toInt(arg("values", "5"));
+
+file sims[];
+
+foreach i in [0:nsim-1] {
+  file simout <single_file_mapper; file=strcat("output/sim_",i,".out")>;
+  file simlog <single_file_mapper; file=strcat("output/sim_",i,".log")>;
+  (simout,simlog) = simulation(steps,range,values);
+  sims[i] = simout;
+}
+
+file stats_out<"output/average.out">;
+file stats_log<"output/average.log">;
+(stats_out, stats_log) = analyze(sims);

Added: SwiftApps/subjobs/simanalyze/part05/runcetus.sh
===================================================================
--- SwiftApps/subjobs/simanalyze/part05/runcetus.sh	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part05/runcetus.sh	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+/home/ketan/swift-k/dist/swift-svn/bin/swift -config cetus.conf -reducedLogging -minimalLogging p5.swift
+


Property changes on: SwiftApps/subjobs/simanalyze/part05/runcetus.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftApps/subjobs/simanalyze/part05/swift.properties
===================================================================
--- SwiftApps/subjobs/simanalyze/part05/swift.properties	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part05/swift.properties	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,3 @@
+site=westmere
+site.westmere.slurm.reservation=workshop
+site.westmere.slurm.exclusive=false

Added: SwiftApps/subjobs/simanalyze/part06/cetus.conf
===================================================================
--- SwiftApps/subjobs/simanalyze/part06/cetus.conf	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part06/cetus.conf	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1 @@
+link ../../conf/cetus.conf
\ No newline at end of file


Property changes on: SwiftApps/subjobs/simanalyze/part06/cetus.conf
___________________________________________________________________
Added: svn:special
   + *

Added: SwiftApps/subjobs/simanalyze/part06/p6.swift
===================================================================
--- SwiftApps/subjobs/simanalyze/part06/p6.swift	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part06/p6.swift	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,53 @@
+type file;
+
+# app() functions for application programs to be called:
+
+app (file out) genseed (int nseeds)
+{
+  bgsh "/home/ketan/swift-tutorial/app/simulate" "-r" 2000000 "-n" nseeds stdout=@out;
+}
+
+app (file out) genbias (int bias_range, int nvalues)
+{
+  bgsh "/home/ketan/swift-tutorial/app/simulate" "-r" bias_range "-n" nvalues stdout=@out;
+}
+
+app (file out, file log) simulation (int timesteps, int sim_range, file bias_file, 
+                                     int scale, int sim_count, file seed_file)
+{
+  bgsh "/home/ketan/swift-tutorial/app/simulate" "-t" timesteps "-r" sim_range "-B" @bias_file "-x" scale
+           "-n" sim_count "-S" @seed_file stdout=@out stderr=@log;
+}
+
+app (file out, file log) analyze (file s[])
+{
+  bgsh "/home/ketan/swift-tutorial/app/stats" filenames(s) stdout=@out stderr=@log;
+}
+
+# Command line arguments
+
+int   nsim = toInt(arg("nsim",   "10"));  # number of simulation programs to run
+int  steps = toInt(arg("steps",  "1"));   # number of timesteps (seconds) per simulation
+int  range = toInt(arg("range",  "100")); # range of the generated random numbers
+int values = toInt(arg("values", "10"));  # number of values generated per simulation
+
+# Main script and data
+file seedfile <"output/seed.dat">;        # Dynamically generated bias for simulation ensemble
+
+tracef("\n*** Script parameters: nsim=%i range=%i num values=%i\n\n", nsim, range, values);
+seedfile = genseed(1);
+
+file sims[];                      # Array of files to hold each simulation output
+
+foreach i in [0:nsim-1] {
+  file biasfile <single_file_mapper; file=strcat("output/bias_",i,".dat")>;
+  file simout   <single_file_mapper; file=strcat("output/sim_",i,".out")>;
+  file simlog   <single_file_mapper; file=strcat("output/sim_",i,".log")>;
+  biasfile = genbias(1000, 20);
+  (simout,simlog) = simulation(steps, range, biasfile, 1000000, values, seedfile);
+  sims[i] = simout;
+}
+
+file stats_out<"output/average.out">;
+file stats_log<"output/average.log">;
+(stats_out,stats_log) = analyze(sims);

Added: SwiftApps/subjobs/simanalyze/part06/runcetus.sh
===================================================================
--- SwiftApps/subjobs/simanalyze/part06/runcetus.sh	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part06/runcetus.sh	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,4 @@
+#! /bin/sh
+
+/home/ketan/swift-k/dist/swift-svn/bin/swift -config cetus.conf -reducedLogging -minimalLogging p6.swift
+


Property changes on: SwiftApps/subjobs/simanalyze/part06/runcetus.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: SwiftApps/subjobs/simanalyze/part06/swift.properties
===================================================================
--- SwiftApps/subjobs/simanalyze/part06/swift.properties	                        (rev 0)
+++ SwiftApps/subjobs/simanalyze/part06/swift.properties	2015-03-24 19:55:06 UTC (rev 8409)
@@ -0,0 +1,3 @@
+site=westmere
+site.westmere.slurm.reservation=workshop
+site.westmere.slurm.exclusive=false




More information about the Swift-commit mailing list