Skip to content

Commit

Permalink
New part 10: advanced workflow constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Jul 14, 2016
1 parent b5ba47b commit 754635f
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 0 deletions.
84 changes: 84 additions & 0 deletions docs/programmers/tutorials/workflows/fig/3n+1.fig
@@ -0,0 +1,84 @@
#FIG 3.2 Produced by xfig version 3.2.5b
Landscape
Center
Metric
A4
100.00
Single
-2
1200 2
6 56 630 4470 7335
6 56 630 607 7200
6 56 1080 607 2610
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
307 1105 307 2585
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
81 1557 582 1557 582 2058 81 2058 81 1557
4 0 0 50 -1 3 20 0.0000 0 315 90 257 1883 f\001
-6
6 56 3150 607 4680
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
307 3175 307 4655
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
81 3627 582 3627 582 4128 81 4128 81 3627
4 0 0 50 -1 3 20 0.0000 0 315 90 257 3953 f\001
-6
6 56 5265 607 6795
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
307 5290 307 6770
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
81 5742 582 5742 582 6243 81 6243 81 5742
4 0 0 50 -1 3 20 0.0000 0 315 90 257 6068 f\001
-6
4 0 0 50 -1 0 24 0.0000 0 270 195 234 900 1\001
4 0 0 50 -1 0 24 0.0000 0 270 195 234 3015 4\001
4 0 0 50 -1 0 24 0.0000 0 270 195 234 5040 2\001
4 0 0 50 -1 0 24 0.0000 0 270 195 234 7200 1\001
-6
6 1564 630 2115 3060
6 1564 1080 2115 2610
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
1815 1105 1815 2585
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
1589 1557 2090 1557 2090 2058 1589 2058 1589 1557
4 0 0 50 -1 3 20 0.0000 0 315 90 1765 1883 f\001
-6
4 0 0 50 -1 0 24 0.0000 0 270 195 1742 900 2\001
4 0 0 50 -1 0 24 0.0000 0 270 195 1742 3060 1\001
-6
6 3825 630 4470 7335
6 3872 1125 4423 2655
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
4123 1150 4123 2630
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
3897 1602 4398 1602 4398 2103 3897 2103 3897 1602
4 0 0 50 -1 3 20 0.0000 0 315 90 4073 1928 f\001
-6
6 3872 3420 4423 4950
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
4123 3445 4123 4925
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
3897 3897 4398 3897 4398 4398 3897 4398 3897 3897
4 0 0 50 -1 3 20 0.0000 0 315 90 4073 4223 f\001
-6
6 3872 5400 4423 6930
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
4123 5425 4123 6905
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
3897 5877 4398 5877 4398 6378 3897 6378 3897 5877
4 0 0 50 -1 3 20 0.0000 0 315 90 4073 6203 f\001
-6
4 0 0 50 -1 3 24 0.0000 0 270 255 4020 900 N\001
4 0 0 50 -1 3 24 0.0000 0 375 645 3825 3150 f(N)\001
4 0 0 50 -1 0 24 0.0000 0 30 450 3922 5220 . . .\001
4 0 0 50 -1 0 24 0.0000 0 270 195 4050 7335 1\001
-6
4 0 0 50 -1 0 36 0.0000 0 75 750 2700 705 . . .\001
-6
Binary file added docs/programmers/tutorials/workflows/fig/3n+1.pdf
Binary file not shown.
23 changes: 23 additions & 0 deletions docs/programmers/tutorials/workflows/fig/A.fig
@@ -0,0 +1,23 @@
#FIG 3.2 Produced by xfig version 3.2.5b
Landscape
Center
Metric
A4
100.00
Single
-2
1200 2
6 0 0 1170 3105
6 317 765 868 2295
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
568 790 568 2270
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
342 1242 843 1242 843 1743 342 1743 342 1242
4 0 0 50 -1 3 20 0.0000 0 315 90 518 1568 f\001
-6
2 4 0 4 17 7 50 -1 -1 0.000 0 0 7 0 0 5
1125 3060 45 3060 45 45 1125 45 1125 3060
4 0 0 50 -1 3 24 0.0000 0 270 255 465 540 N\001
4 0 0 50 -1 3 24 0.0000 0 375 645 270 2790 f(N)\001
-6
Binary file added docs/programmers/tutorials/workflows/fig/A.pdf
Binary file not shown.
45 changes: 45 additions & 0 deletions docs/programmers/tutorials/workflows/fig/S.fig
@@ -0,0 +1,45 @@
#FIG 3.2 Produced by xfig version 3.2.5b
Landscape
Center
Metric
A4
100.00
Single
-2
1200 2
6 0 0 1665 7425
6 495 450 1140 7155
6 542 945 1093 2475
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
793 970 793 2450
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
567 1422 1068 1422 1068 1923 567 1923 567 1422
4 0 0 50 -1 3 20 0.0000 0 315 90 743 1748 f\001
-6
6 542 3240 1093 4770
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
793 3265 793 4745
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
567 3717 1068 3717 1068 4218 567 4218 567 3717
4 0 0 50 -1 3 20 0.0000 0 315 90 743 4043 f\001
-6
6 542 5220 1093 6750
2 1 0 2 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
1 1 2.00 33.42 66.84
793 5245 793 6725
2 2 0 2 0 7 50 -1 20 0.000 0 0 -1 0 0 5
567 5697 1068 5697 1068 6198 567 6198 567 5697
4 0 0 50 -1 3 20 0.0000 0 315 90 743 6023 f\001
-6
4 0 0 50 -1 3 24 0.0000 0 270 255 690 720 N\001
4 0 0 50 -1 3 24 0.0000 0 375 645 495 2970 f(N)\001
4 0 0 50 -1 0 24 0.0000 0 30 450 592 5040 . . .\001
4 0 0 50 -1 0 24 0.0000 0 270 195 720 7155 1\001
-6
2 4 1 2 17 7 50 -1 -1 8.000 0 0 7 0 0 5
1350 3240 270 3240 270 225 1350 225 1350 3240
2 4 0 3 17 7 50 -1 -1 0.000 0 0 7 0 0 5
1620 7380 1620 45 45 45 45 7380 1620 7380
-6
Binary file added docs/programmers/tutorials/workflows/fig/S.pdf
Binary file not shown.
Binary file modified docs/programmers/tutorials/workflows/part10.pdf
Binary file not shown.
160 changes: 160 additions & 0 deletions docs/programmers/tutorials/workflows/part10.tex
Expand Up @@ -143,6 +143,166 @@
\+
\ldots specifying dependencies among them.
\end{frame}


\begin{frame}
\frametitle{The \emph{3n+1} conjecture, a fictitious use case}
\label{sec:7a}

\+
\begin{columns}[c]
\column{0.5\linewidth}
\includegraphics[height=0.8\textheight]{fig/3n+1}

\column{0.5\linewidth}
Define a function $f$, for $n$ positive integer:
\begin{itemize}
\item if $n$ is even, then $f(n) = n / 2$,
\item if $n$ is odd, then $f(n) = 3n+1$,
\end{itemize}

\+
For every positive integer $n$, form the sequence $S(n)$:
$n \to f(n) \to f(f(n)) \to f(f(f(n))) \to \ldots$

\+
\textbf{Conjecture:} For every positive integer $n$, the sequence $S(n)$
eventually hits $1$.
\end{columns}
\end{frame}

\begin{frame}
\frametitle{The \emph{3n+1} conjecture, \emph{(I)}}
\label{sec:7}

\+
\begin{columns}[c]
\column{0.5\linewidth}
\includegraphics[height=0.8\textheight]{fig/3n+1_A}

\column{0.5\linewidth}
A computational job $J(n,k)$, applies
function $f$ to the result of $J(n,k)$.
\end{columns}
\end{frame}

\begin{frame}
\frametitle{The \emph{3n+1} conjecture, \emph{(II)}}
\label{sec:7b}

\+
\begin{columns}[c]
\column{0.5\linewidth}
\includegraphics[height=0.8\textheight]{fig/3n+1_S}

\column{0.5\linewidth}
A sequence $H(n)$ of jobs computes the chain $n \to f(n) \to
... \to 1$.
\end{columns}
\end{frame}

\begin{frame}
\frametitle{The \emph{3n+1} conjecture, \emph{(III)}}
\label{sec:7c}

\+
\begin{columns}[c]
\column{0.5\linewidth}
\includegraphics[height=0.8\textheight]{fig/3n+1_P}

\column{0.5\linewidth}
Run one sequence $H(n)$ per each $n = 1, \ldots, N$.

\+
The can all run in \textbf{parallel}.
\end{columns}
\end{frame}

\begin{frame}[fragile]
\frametitle{The \emph{3n+1} conjecture (IV)}
\label{sec:10}

\begin{columns}
\column{0.3\linewidth}
\begin{center}
\includegraphics[height=0.8\textheight]{fig/A}
\end{center}

\column{0.7\linewidth}
Let's define the simple application that computes~$f$:
\begin{lstlisting}
class HotpoApplication(Application):
def __init__(self, n):
Application.__init__(
self,
executable = '/usr/bin/expr',
arguments = (
# run `expr n / 2` if n is even
[n, '/', n] if n % 2 == 0
# run `expr 1 + 3 * n` if n is odd
else [1, '+', 3, '*', n]),
stdout = "stdout.txt",
)
\end{lstlisting}
\end{columns}
\end{frame}

\begin{frame}[fragile]
\frametitle{The \emph{3n+1} conjecture (V)}
\label{sec:14}

\begin{columns}
\column{0.2\linewidth}
\begin{center}
\includegraphics[height=0.8\textheight]{fig/S}
\end{center}

\column{0.8\linewidth}
Now string together applications to compute a
single sequence:
\begin{lstlisting}
class HotpoSequence(SequentialTask):

def __init__(self, n):
# compute first iteration of $f$
self.tasks = [ HotpoApplication(n) ]
SequentialTask.__init__(self, self.tasks)

def next(self, k):
last = self.tasks[k].result
if last == 1:
return TERMINATED
else:
self.tasks.append(MyApplication(last)
return RUNNING
\end{lstlisting}
\end{columns}
\end{frame}

\begin{frame}[fragile]
\frametitle{The \emph{3n+1} conjecture (VI)}
\label{sec:15}

\begin{columns}
\column{0.5\linewidth}
\begin{center}
\includegraphics[height=0.8\textheight]{fig/3n+1_P}
\end{center}

\column{0.5\linewidth}
Parallel tasks are independent by definition, so it's even easier to
create a collection:
\begin{lstlisting}
tasks =
ParallelTaskCollection([
HotpoSequence(n)
for n in range(1, N) ])
\end{lstlisting}

We can run such a collection like any other \texttt{Task}.
\end{columns}
\end{frame}

\end{document}

%%% Local Variables:
Expand Down

0 comments on commit 754635f

Please sign in to comment.