-
Notifications
You must be signed in to change notification settings - Fork 23
/
part10.tex
311 lines (252 loc) · 6.86 KB
/
part10.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
\documentclass[english,serif,mathserif,xcolor=pdftex,dvipsnames,table]{beamer}
\usetheme{gc3}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{gc3}
\title[Advanced workflows]{%
More on workflows
}
\author[R. Murri, S3IT UZH]{%
Riccardo Murri \texttt{<riccardo.murri@uzh.ch>}
\\[1ex]
\emph{S3IT: Services and Support for Science IT}
\\[1ex]
University of Zurich
}
\date{July~11--14, 2016}
\begin{document}
% title frame
\maketitle
\begin{frame}[fragile]
\frametitle{Automatic arrangement of tasks}
Want to avoid arranging tasks in parallel- and sequential- task collections?
Use a \texttt{DepedentTaskCollection}!
\+
\begin{python}
from gc3libs.workflow \
import DependentTaskCollection
class MyWorkflow~\HL{(DependentTaskCollection)}~:
# ...
def __init__(self, ...):
DependentTaskCollection.__init__(self)
app1 = AnApp(...)
app2 = AnotherApp(...)
app3 = AThirdApp(...)
self.add(app1)
self.add(app2)
self.add(app3, after=[app1, app2])
\end{python}
\end{frame}
\begin{frame}[fragile]
\frametitle{Usage of DependentTaskCollection}
\begin{python}
from gc3libs.workflow \
import DependentTaskCollection
class MyWorkflow(DependentTaskCollection):
# ...
def __init__(self, ...):
~\HL{DependentTaskCollection.\_\_init\_\_(self)}~
app1 = AnApp(...)
app2 = AnotherApp(...)
app3 = AThirdApp(...)
self.add(app1)
self.add(app2)
self.add(app3, after=[app1, app2])
\end{python}
\+
Initialize the base class.
\end{frame}
\begin{frame}[fragile]
\frametitle{Usage of DependentTaskCollection}
\begin{python}
from gc3libs.workflow \
import DependentTaskCollection
class MyWorkflow(DependentTaskCollection):
# ...
def __init__(self, ...):
DependentTaskCollection.__init__(self)
~\HL{app1 = AnApp(...)}~
~\HL{app2 = AnotherApp(...)}~
~\HL{app3 = AThirdApp(...)}~
self.add(app1)
self.add(app2)
self.add(app3, after=[app1, app2])
\end{python}
\+
\ldots then initialize tasks that you want to run \ldots
\end{frame}
\begin{frame}[fragile]
\frametitle{Usage of DependentTaskCollection}
\begin{python}
from gc3libs.workflow \
import DependentTaskCollection
class MyWorkflow(DependentTaskCollection):
# ...
def __init__(self, ...):
DependentTaskCollection.__init__(self)
app1 = AnApp(...)
app2 = AnotherApp(...)
app3 = AThirdApp(...)
~\HL{self.add(app1)}~
~\HL{self.add(app2)}~
~\HL{self.add(app3, after=[app1, app2])}~
\end{python}
\+
\ldots then add tasks to the collection, one by one\ldots
\end{frame}
\begin{frame}[fragile]
\frametitle{Usage of DependentTaskCollection}
\begin{python}
from gc3libs.workflow \
import DependentTaskCollection
class MyWorkflow(DependentTaskCollection):
# ...
def __init__(self, ...):
DependentTaskCollection.__init__(self)
app1 = AnApp(...)
app2 = AnotherApp(...)
app3 = AThirdApp(...)
self.add(app1)
self.add(app2)
self.add(app3, ~\HL{after=[app1, app2]}~)
\end{python}
\+
\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:
%%% mode: latex
%%% TeX-master: t
%%% End: