[Swift-commit] r8385 - www/Swift-T
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Thu Mar 5 13:23:40 CST 2015
Author: wozniak
Date: 2015-03-05 13:23:39 -0600 (Thu, 05 Mar 2015)
New Revision: 8385
Modified:
www/Swift-T/gallery.html
Log:
Update gallery
Modified: www/Swift-T/gallery.html
===================================================================
--- www/Swift-T/gallery.html 2015-03-03 20:27:11 UTC (rev 8384)
+++ www/Swift-T/gallery.html 2015-03-05 19:23:39 UTC (rev 8385)
@@ -773,10 +773,8 @@
<div class="listingblock">
<div class="content">
<pre><code>import io;
-main
-{
- printf("Hello world!");
-}</code></pre>
+
+printf("Hello world!");</code></pre>
</div></div>
</div>
</div>
@@ -792,12 +790,9 @@
"od" "-b" i @stdout=o;
}
-main
-{
- file x = input("mtc1.swift");
- file y<"mtc1.octal">;
- y = f(x);
-}</code></pre>
+file x = input("mtc1.swift");
+file y<"mtc1.octal">;
+y = f(x);</code></pre>
</div></div>
<div class="paragraph"><p>This script splits itself into lines, where line <em>i</em> is in file <code>out-</code>
<em>i</em> <code>.txt</code></p></div>
@@ -812,13 +807,10 @@
"/bin/echo" s @stdout=o;
}
-main
+string lines[] = file_lines(input("mtc2.swift"));
+foreach line,i in lines
{
- string lines[] = file_lines(input("mtc2.swift"));
- foreach line,i in lines
- {
- file y <sprintf("out-%i.txt",i)> = f(line);
- }
+ file y <sprintf("out-%i.txt",i)> = f(line);
}</code></pre>
</div></div>
<div class="paragraph"><p>Note that each <code>/bin/echo</code> is eligible to run concurrently. See
@@ -827,8 +819,42 @@
</div>
</div>
<div class="sect1">
-<h2 id="_reductions">3. Reductions</h2>
+<h2 id="_running_many_tasks_on_a_cluster">3. Running many tasks on a cluster</h2>
<div class="sectionbody">
+<div class="paragraph"><p>It’s easy to launch these kinds of workloads on a cluster.</p></div>
+<div class="paragraph"><p>If using a plain host list:</p></div>
+<div class="paragraph"><p><strong>File:</strong> <code>mtc/hosts.txt</code></p></div>
+<div class="listingblock">
+<div class="content">
+<pre><code>machine1.some.edu
+machine2.some.edu
+machine3.some.edu
+machine4.some.edu</code></pre>
+</div></div>
+<div class="paragraph"><p>Just run with:</p></div>
+<div class="listingblock">
+<div class="content">
+<pre><code>stc mtc1.swift
+turbine -f hosts.txt -n 4 mtc1.tic</code></pre>
+</div></div>
+<div class="paragraph"><p>As shown, <code>turbine</code> accepts an MPI hosts file and number of
+processes, just like <code>mpiexec</code>.</p></div>
+<div class="paragraph"><p>A shorter, equivalent form of that command sequence is:</p></div>
+<div class="listingblock">
+<div class="content">
+<pre><code>swift-t -t:f hosts.txt -n 4 mtc1.swift</code></pre>
+</div></div>
+<div class="paragraph"><p>On a PBS system, run with:</p></div>
+<div class="listingblock">
+<div class="content">
+<pre><code>swift-t -m pbs -n 4 mtc1.swift</code></pre>
+</div></div>
+<div class="paragraph"><p>Many <a href="turbine-sites.html">other systems</a> are supported!</p></div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="_reductions">4. Reductions</h2>
+<div class="sectionbody">
<div class="paragraph"><p>A simplified version of the MapReduce model is to just compute many
things and assemble them together at the end.</p></div>
<div class="paragraph"><p>This script splits itself into lines, then reassembles the original
@@ -845,24 +871,21 @@
"/bin/echo" s @stdout=o;
}
-main
+string lines[] = file_lines(input("mtc2.swift"));
+file fragments[];
+foreach line,i in lines
{
- string lines[] = file_lines(input("mtc2.swift"));
- file fragments[];
- foreach line,i in lines
- {
- file y <sprintf("out-%i.txt",i)> = g(line);
- fragments[i] = y;
- }
- file result <"assembled.txt"> = cat(fragments);
-}</code></pre>
+ file y <sprintf("out-%i.txt",i)> = g(line);
+ fragments[i] = y;
+}
+file result <"assembled.txt"> = cat(fragments);</code></pre>
</div></div>
<div class="paragraph"><p>Note that leading whitespace is trimmed by <code>file_lines()</code>, and <code>cat()</code>
is part of the Swift/T standard library in module <code>unix</code>.</p></div>
</div>
</div>
<div class="sect1">
-<h2 id="_recursion">4. Recursion</h2>
+<h2 id="_recursion">5. Recursion</h2>
<div class="sectionbody">
<div class="paragraph"><p>This script computes the given
<a href="https://en.wikipedia.org/wiki/Fibonacci_number">Fibonacci number</a>:</p></div>
@@ -887,11 +910,8 @@
}
}
-main
-{
- int n = toint(argv("n"));
- trace(fib(n));
-}</code></pre>
+int n = toint(argv("n"));
+trace(fib(n));</code></pre>
</div></div>
<div class="paragraph"><p>Run it as:</p></div>
<div class="paragraph"><p><strong>File:</strong> <code>fib/run.sh</code></p></div>
@@ -938,27 +958,69 @@
}
}
-main
-{
- file result <"sorted.txt"> = merge(0,7);
-}</code></pre>
+file result <"sorted.txt"> = merge(0,7);</code></pre>
</div></div>
<div class="paragraph"><p>This code runs the <code>sort</code> invocations concurrently, limited only by
available processors and data dependencies.</p></div>
</div>
</div>
<div class="sect1">
-<h2 id="_python_and_numpy">5. Python and Numpy</h2>
+<h2 id="_python_and_numpy">6. Python and Numpy</h2>
<div class="sectionbody">
<div class="paragraph"><p>See this section for information about calling Python or Numpy:
<a href="guide.html#_external_scripting_support">Swift/T Guide: Python</a></p></div>
</div>
</div>
+<div class="sect1">
+<h2 id="_static_executables">7. Static executables</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>This section demonstrates a complete, concrete example of the
+<a href="guide.html#mkstatic">static executable</a> feature. First, compose a
+Swift script.</p></div>
+<div class="paragraph"><p><strong>File:</strong> <code>static-exec/hello.swift</code></p></div>
+<div class="listingblock">
+<div class="content">
+<pre><code>import io;
+printf("HELLO");</code></pre>
+</div></div>
+<div class="paragraph"><p>Then, copy Turbine’s example manifest file and edit.
+This manifest has all comments removed for simplicity.</p></div>
+<div class="paragraph"><p><strong>File:</strong> <code>static-exec/hello.manifest</code></p></div>
+<div class="listingblock">
+<div class="content">
+<pre><code>pkg_name = hello
+pkg_version = 0.1
+
+main_script = hello.tic</code></pre>
+</div></div>
+<div class="paragraph"><p>Then, build:</p></div>
+<div class="paragraph"><p><strong>File:</strong> <code>static-exec/build.sh</code></p></div>
+<div class="listingblock">
+<div class="content">
+<pre><code>#!/bin/bash
+set -eu
+
+# Obtain the Turbine build configuration variables
+TURBINE=/homes/wozniak/sfw/fusion/compute/turbine-static
+source ${TURBINE}/scripts/turbine-build-config.sh
+
+# Generate hello.tic
+stc hello.swift
+# Bundle hello.tic and Turbine into hello_main.c
+mkstatic.tcl hello.manifest -c hello_main.c
+
+# Compile hello_main.c and link as standalone, static executable
+CFLAGS=-std=gnu99
+gcc -c ${CFLAGS} ${TURBINE_INCLUDES} hello_main.c
+mpicc -static -o hello.x hello_main.o ${TURBINE_LIBS} ${TURBINE_RPATH}</code></pre>
+</div></div>
</div>
+</div>
+</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
-Last updated 2014-12-19 16:24:35 CST
+Last updated 2015-03-05 13:19:55 CST
</div>
</div>
</body>
More information about the Swift-commit
mailing list