[Swift-commit] r5683 - trunk/examples/tutorial
wilde at ci.uchicago.edu
wilde at ci.uchicago.edu
Sun Feb 26 12:08:24 CST 2012
Author: wilde
Date: 2012-02-26 12:08:23 -0600 (Sun, 26 Feb 2012)
New Revision: 5683
Added:
trunk/examples/tutorial/gensweep.sh
trunk/examples/tutorial/simulate.sh
trunk/examples/tutorial/sweep.sh
trunk/examples/tutorial/sweep.swift
Log:
Initial version.
Added: trunk/examples/tutorial/gensweep.sh
===================================================================
--- trunk/examples/tutorial/gensweep.sh (rev 0)
+++ trunk/examples/tutorial/gensweep.sh 2012-02-26 18:08:23 UTC (rev 5683)
@@ -0,0 +1,36 @@
+#! /bin/sh
+
+#
+# gensweep.sh - Generate per-member and common parameter files
+# for a parameter sweep (an ensemble of simulations).
+# Generates 2-column files of the form: "paramter value"
+
+# echo gensweep.sh: $0 $* >/dev/tty # For debugging on localhost
+
+# Determine the filename patterns from the supplied zero'th file names
+
+nMembers=$1
+mBase=$(basename $2 .0)
+mDir=$(dirname $2)
+mName=$mDir/$mBase
+
+nCommon=$3
+cBase=$(basename $4 .0)
+cDir=$(dirname $4)
+cName=$cDir/$cBase
+
+# Generate an input file for each simulation in the ensemble
+
+for (( m=0; m<nMembers; m++ )); do
+ echo n $m >$mName.$m
+ echo rate $RANDOM >>$mName.$m
+ echo dx $RANDOM >>$mName.$m
+done
+
+# Generate the input files common to all simulations in the ensemble
+
+for (( c=0; c<nCommon; c++ )); do
+ echo c $c >$cName.$c
+ echo alpha $RANDOM >>$cName.$c
+ echo beta $RANDOM >>$cName.$c
+done
Property changes on: trunk/examples/tutorial/gensweep.sh
___________________________________________________________________
Added: svn:executable
+
Added: trunk/examples/tutorial/simulate.sh
===================================================================
--- trunk/examples/tutorial/simulate.sh (rev 0)
+++ trunk/examples/tutorial/simulate.sh 2012-02-26 18:08:23 UTC (rev 5683)
@@ -0,0 +1,18 @@
+#! /bin/sh
+
+#
+# simulate.sh - a tiny script to model a "simulation application"
+# Reads N files of 2-column lines of the form "parameter value"
+# Computes a random function of (some of) the inputs
+
+awk ' # Prints a single text line result with a random function of (some of) the input parameters
+
+{ param[$1] = $2 } # read in the parameter values (for this member plus common files)
+
+END {
+ srand(param["n"] * param["rate"]) / param["beta"]; # the "simulation" :)
+ printf ("Simulation number: %d alpha: %f beta: %f: result: %f\n", param["n"],
+ param["alpha"], param["beta"], rand());
+}
+
+' $* # member-file common-files...
Property changes on: trunk/examples/tutorial/simulate.sh
___________________________________________________________________
Added: svn:executable
+
Added: trunk/examples/tutorial/sweep.sh
===================================================================
--- trunk/examples/tutorial/sweep.sh (rev 0)
+++ trunk/examples/tutorial/sweep.sh 2012-02-26 18:08:23 UTC (rev 5683)
@@ -0,0 +1,42 @@
+#! /bin/sh
+
+# Create new runNNN directory
+
+rundir=$( echo run??? | sed -e 's/^.*run//' | awk '{ printf("run%03d\n", $1+1)}' )
+mkdir $rundir
+
+cat >$rundir/cf <<END
+
+wrapperlog.always.transfer=true
+sitedir.keep=true
+execution.retries=0
+lazy.errors=false
+
+END
+
+cat >$rundir/local.xml <<END
+
+<config>
+ <pool handle="local">
+ <execution provider="local" />
+ <profile namespace="karajan" key="jobThrottle">.23</profile>
+ <profile namespace="karajan" key="initialScore">10000</profile>
+ <filesystem provider="local"/>
+ <workdirectory>$PWD/swiftwork</workdirectory>
+ </pool>
+</config>
+
+END
+
+cat >$rundir/tc <<END
+
+local gensweep $PWD/gensweep.sh
+local simulate $PWD/simulate.sh
+
+END
+
+cp sweep.swift $rundir
+
+cd $rundir
+echo Running in directory $rundir
+swift -config cf -tc.file tc -sites.file local.xml sweep.swift $* 2>&1 | tee swift.out
Property changes on: trunk/examples/tutorial/sweep.sh
___________________________________________________________________
Added: svn:executable
+
Added: trunk/examples/tutorial/sweep.swift
===================================================================
--- trunk/examples/tutorial/sweep.swift (rev 0)
+++ trunk/examples/tutorial/sweep.swift 2012-02-26 18:08:23 UTC (rev 5683)
@@ -0,0 +1,62 @@
+type file;
+
+# Application to generate the parameter and data files
+
+app (file m[], file c[]) genSweep (int nm, int nc)
+{
+ gensweep nm @filename(m[0]) nc @filename(c[0]);
+}
+
+# Application to perform a "simulation"
+
+app (file o) simulation (file f, file common[])
+{
+ simulate stdout=@filename(o) @filename(f) @filenames(common);
+}
+
+# Set the size of the parameter sweep
+
+int nMembers = @toInt(@arg("nMembers","5")); // number of members in the simulation
+int nCommon = @toInt(@arg("nCommon","3")); // number of common files to each sim
+tracef("Running parameter sweep ensemble of %i members with %i common files\n", nMembers, nCommon);
+
+# Generate the file names to use
+
+string mName[];
+string oName[];
+string cName[];
+
+foreach i in [0:nMembers-1] {
+ mName[i] = @sprintf("member.%i",i);
+ oName[i] = @sprintf("result.%i",i);
+}
+
+foreach i in [0:nCommon-1] {
+ cName[i] = @sprintf("common.%i",i);
+}
+
+# Set the file names to use
+
+file mFile[] <array_mapper; files=mName>;
+file cFile[] <array_mapper; files=cName>;
+file oFile[] <array_mapper; files=oName>;
+
+# Generate the files for the ensemble run
+
+(mFile, cFile) = genSweep(nMembers, nCommon);
+
+# Perform the ensemble of parallel simulations
+
+foreach f, i in mFile {
+ oFile[i] = simulation(f, cFile);
+}
+
+
+
+/* For debugging:
+
+trace("mFiles", at filenames(mFile));
+trace("oFiles", at filenames(oFile));
+trace("cFiles", at filenames(cFile));
+
+*/
\ No newline at end of file
More information about the Swift-commit
mailing list