-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequencing.tex
533 lines (487 loc) · 16.3 KB
/
sequencing.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%
%% Structured Dagger %%
%% %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]
\frametitle{Chares are reactive}
\begin{itemize}
\item The way we described Charm++ so far, a chare is a reactive entity:
\begin{itemize}
\item If it gets this method invocation, it does this action,
\item If it gets that method invocation then it does that action
\item But what does it do?
\item In typical programs, chares have a \emph{life-cycle}
\end{itemize}
\item How to express the life-cycle of a chare in code?
\begin{itemize}
\item Only when it exists
\begin{itemize}
\item i.e. some chars may be truly reactive, and the programmer does
not know the life cycle
\end{itemize}
\item But when it exists, its form is:
\begin{itemize}
\item Computations depend on remote method invocations, and completion
of other local computations
\item A DAG (Directed Acyclic Graph)!
\end{itemize}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Consider Fibonacci Chare}
\begin{itemize}
\item The Fibonacci chare gets created
\item If its not a leaf,
\begin{itemize}
\item It fires two chares
\item When both children return results (by calling \code{response}):
\begin{itemize}
\item It can compute my result and send it up, or print it
\end{itemize}
\item But in our, this logic is hidden in the flags and counters $\ldots$
\begin{itemize}
\item This is simple for this simple example, but $\ldots$
\end{itemize}
\item Lets look at how this would look with a little notational support
\end{itemize}
\end{itemize}
\end{frame}
% \begin{frame}[fragile]
% \frametitle{What is Structured Dagger?}
% \begin{itemize}
% \item Describe in a sequence the flow of control for a parallel object
% \item Explicitly order and count message delivery and the blocks of code to
% executed under the proper conditions
% \end{itemize}
% \end{frame}
%if -> while -> for
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{when} construct}
\begin{itemize}
\item The \code{when} construct
\begin{itemize}
\item Declare the actions to perform when a message is received
\item In sequence, it acts like a blocking receive
\end{itemize}
\begin{lstlisting}[basicstyle=\normalsize]
entry void someMethod() {
when entryMethod1(parameters) { /* block2 */ }
when entryMethod2(parameters) { /* block3 */ }
};
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{A \code{serial} block}
\begin{itemize}
\item The \code{serial} construct
\begin{itemize}
\item A sequential block of C++ code in the .ci file
\item The keyword \code{serial} means that the code block will be
executed without interruption/preemption, like an entry method
\end{itemize}
\item Examples (.ci file):
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{lstlisting}[basicstyle=\tiny]
entry void method1(parameters) {
serial {
thisProxy.invokeMethod(10);
callSomeFunction();
}
};
\end{lstlisting}
\end{column}
\begin{column}{0.5\textwidth}
\begin{lstlisting}[basicstyle=\tiny]
entry void method2(parameters) {
serial "setValue" {
value = 10;
}
};
\end{lstlisting}
\end{column}
\end{columns}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{when} construct}
\begin{lstlisting}[basicstyle=\footnotesize]
entry void someMethod() {
serial { /* block1 */ }
when entryMethod1(parameters) serial { /* block2 */ }
when entryMethod2(parameters) serial { /* block3 */ }
};
\end{lstlisting}
\begin{itemize}
\item Sequence
\pause
\begin{itemize}
\item Sequentially execute \code{/* block1 */}
\pause
\item Wait for \code{entryMethod1} to arrive, if it has not, return control
back to the Charm++ scheduler, otherwise, execute \code{/* block2 */}
\pause
\item Wait for \code{entryMethod2} to arrive, if it has not, return control
back to the Charm++ scheduler, otherwise, execute \code{/* block3 */}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{when} construct}
\begin{itemize}
\item Execute \code{/* further code */} when \code{myMethod} arrives
\begin{lstlisting}[basicstyle=\scriptsize]
when myMethod(int param1, int param2)
/* further code */
\end{lstlisting}
\item Execute \code{/* further code */} when \code{myMethod1} and \code{myMethod2} arrive
\begin{lstlisting}[basicstyle=\scriptsize]
when myMethod1(int param1, int param2),
myMethod2(bool param3)
/* further code */
\end{lstlisting}
\item Syntactical sugar for:
\begin{lstlisting}[basicstyle=\scriptsize]
when myMethod1(int param1, int param2)
when myMethod2(bool param3)
/* further code */
\end{lstlisting}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Structured Dagger}
\framesubtitle{Boilerplate}
\begin{itemize}
\item Structured Dagger can be used in any entry method (except for a constructor)
\begin{itemize}
\item Can be used in a \code{mainchare}, \code{chare}, or \code{array}
\end{itemize}
\item For any class that has Structured Dagger in it you must insert two
calls:
\begin{itemize}
\item The Structured Dagger macro: \code{[ClassName]\_SDAG\_CODE}
% \item Call the \code{\_\_sdag\_init()} initializer in the constructor
\item For later: call the \code{\_\_sdag\_pup()} in the \code{pup} method
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{Boilerplate}
The .ci file:
\begin{lstlisting}
[mainchare,chare,array] MyFoo {
...
entry void method(parameters) {
// ... structured dagger code here ...
};
...
}
\end{lstlisting}
The .cpp file:
\begin{lstlisting}
class MyFoo : public CBase_MyFoo {
MyFoo_SDAG_CODE /* insert SDAG macro */
public:
MyFoo() { }
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Fibonacci with Structured Dagger}
\lstinputlisting[basicstyle=\scriptsize]{code/fibSDAG.ci}
\end{frame}
\begin{frame}[fragile]
\frametitle{Fibonacci with Structured Dagger}
\lstinputlisting[basicstyle=\tiny]{code/fibSDAG.cc}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{when} construct}
\begin{itemize}
\item What is the sequence?
\begin{lstlisting}[basicstyle=\scriptsize]
when myMethod1(int param1, int param2) {
when myMethod2(bool param3),
myMethod3(int size, int arr[size]) /* sdag block1 */
when myMethod4(bool param4) /* sdag block2 */
}
\end{lstlisting}
\pause
\item Sequence:
\begin{itemize}
\item Wait for \code{myMethod1}, upon arrival execute body of \code{myMethod1}
\pause
\item Wait for \code{myMethod2} and \code{myMethod3}, upon arrival of
both, execute \code{/* sdag block1 */}
\pause
\item Wait for \code{myMethod4}, upon arrival execute \code{/* sdag block2 */}
\end{itemize}
\item Question: if \code{myMethod4} arrives first what will happen?
\end{itemize}
\end{frame}
% \begin{frame}[fragile]
% \frametitle{Structured Dagger Constructs: Reference Numbers}
% \begin{itemize}
% \item Entry methods can be \emph{tagged} with a \emph{reference number}
% \item A reference number is a special field in the envelope of the message
% that is sent
% \item By default, the reference number is a \code{short}
% \item This can be changed when compiling charm:
% \begin{itemize}
% \item Add this to the build flags:
% \code{--with-refnum-type=int}
% \item For example, compiling on BG/P with the IBM XLC compiler:
% \end{itemize}
% \end{itemize}
% \code{./build charm++ bluegenep xlc --with-refnum-type=int -g -O0}
% \end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger Constructs}
\framesubtitle{The \code{when} construct}
\begin{itemize}
\item The \code{when} clause can wait on a certain reference number
\item If a reference number is specified for a \code{when}, the first
parameter for the \code{when} must be the reference number
\item Semantic: the \code{when} will ``block'' until a message arrives with
that reference number
\end{itemize}
\begin{lstlisting}
when method1[100](int ref, bool param1)
/* sdag block */
serial {
proxy.method1(200, false); /* will not be delivered to the when */
proxy.method1(100, true); /* will be delivered to the when */
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{if-then-else} construct}
\begin{itemize}
\item The \code{if-then-else} construct:
\begin{itemize}
\item Same as the typical C if-then-else semantics and syntax
\end{itemize}
\end{itemize}
\begin{lstlisting}
if (thisIndex.x == 10) {
when method1[block](int ref, bool someVal) /* code block1 */
} else {
when method2(int payload) serial {
//... some C++ code
}
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{for} construct}
\begin{itemize}
\item The \code{for} construct:
\begin{itemize}
\item Defines a sequenced \code{for} loop (like a sequential C for loop)
\item Once the body for the $i$th iteration completes, the $i+1$ iteration
is started
\end{itemize}
\end{itemize}
\begin{lstlisting}
for (iter = 0; iter < maxIter; ++iter) {
when recvLeft[iter](int num, int len, double data[len])
serial { computeKernel(LEFT, data); }
when recvRight[iter](int num, int len, double data[len])
serial { computeKernel(RIGHT, data); }
}
\end{lstlisting}
\begin{itemize}
\item \code{iter} must be defined in the class as a member
\end{itemize}
\begin{lstlisting}
class Foo : public CBase_Foo {
public: int iter;
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{while} construct}
\begin{itemize}
\item The \code{while} construct:
\begin{itemize}
\item Defines a sequenced \code{while} loop (like a sequential C while loop)
\end{itemize}
\end{itemize}
\begin{lstlisting}
while (i < numNeighbors) {
when recvData(int len, double data[len]) {
serial {
/* do something */
}
when method1() /* block1 */
when method2() /* block2 */
}
serial { i++; }
}
\end{lstlisting}
\end{frame}
% \begin{frame}[fragile]
% \frametitle{Structured Dagger Constructs: \code{when}}
% \begin{itemize}
% \item Another example:
% \end{itemize}
% .ci file:
% \begin{lstlisting}
% chare MyChare {
% entry MyChare();
% entry void startWork() {
% serial { myRef = 100; }
% when method1[myRef1](int ref, bool param1) /* block1 */
% when method2[myRef2](int ref, bool param1) /* block2 */
% };
% }
% \end{lstlisting}
% .cpp file:
% \begin{lstlisting}
% class MyChare : public CBase_MyChare {
% int myRef1, myRef2;
% MyChare() : myRef2(200) { }
% };
% \end{lstlisting}
% \end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{overlap} construct}
\begin{itemize}
\item The \code{overlap} construct:
\begin{itemize}
\item By default, Structured Dagger defines a sequence that is followed sequentially
\item \code{overlap} allows multiple independent clauses to execute in any order
\item Any constructs in the body of an \code{overlap} can happen in any
order
\item An \code{overlap} finishes in sequence when all the statements in it
are executed
\item Syntax: \code{overlap \{ /* sdag constructs */ \}}
\end{itemize}
\end{itemize}
What are the possible execution sequences?
\begin{lstlisting}
serial { /* block1 */ }
overlap {
serial { /* block2 */ }
when entryMethod1[100](int ref_num, bool param1) /* block3 */
when entryMethod2(char myChar) /* block4 */
}
serial { /* block5 */ }
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Illustration of a long ``overlap''}
\begin{columns}
\begin{column}{0.6\textwidth}
\begin{itemize}
\item Overlap can be used to get back some of the asynchrony within a chare
\begin{itemize}
\item But it is constrained
\item Makes for more disciplined programming,
\begin{itemize}
\item with fewer race conditions
\end{itemize}
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.4\textwidth}
\includegraphics[width=0.8\textwidth]{figures/overlapFlow.png}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\frametitle{Structured Dagger}
\framesubtitle{The \code{forall} construct}
\begin{itemize}
\item The \code{forall} construct:
\begin{itemize}
\item Has ``do-all'' semantics: iterations may execute an any order
\item Syntax: \code{forall [<ident>] (<min> : <max>, <stride>) <body>}
\item The range from \code{<min>} to \code{<max>} is inclusive
\end{itemize}
\end{itemize}
\begin{lstlisting}
forall [block] (0 : numBlocks - 1, 1) {
when method1[block](int ref, bool someVal) /* code block1 */
}
\end{lstlisting}
\begin{itemize}
\item Assume \code{block} is declared in the class as \code{public: int block;}
\end{itemize}
\end{frame}
% \begin{frame}[fragile]
% \frametitle{Determinant MP0 Solution: .ci file}
% \lstinputlisting[basicstyle=\footnotesize]{code/det.ci}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Determinant MP0 Solution: .cpp file (part 1)}
% \lstinputlisting[basicstyle=\tiny]{code/detp1.C}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Determinant MP0 Solution: .cpp file (part 2)}
% \lstinputlisting[basicstyle=\tiny]{code/detp2.C}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Determinant MP0 Structered Dagger: .ci file}
% \lstinputlisting[basicstyle=\scriptsize]{code/detSDAG.ci}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Determinant MP0 Structered Dagger: .cpp file}
% \lstinputlisting[basicstyle=\tiny]{code/detSDAG.C}
% \end{frame}
\begin{frame}[fragile]
\frametitle{5-point Stencil}
\begin{center} \includegraphics[width=0.85\textwidth]{figures/2DJacobi_Decomposition.jpg} \end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{5-point Stencil}
\begin{center} \includegraphics[width=0.6\textwidth]{figures/2DJacobi_NeighborComm.jpg} \end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{5-point Stencil}
\begin{center} \includegraphics[width=0.8\textwidth]{figures/2DJacobi_LogicFlow.jpg} \end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{Jacobi: .ci file}
\lstinputlisting[basicstyle=\footnotesize]{code/jacobi3dELL.ci}
\end{frame}
\begin{frame}[fragile]
\frametitle{Jacobi: .ci file}
\lstinputlisting[basicstyle=\tiny,linerange={22-49}]{code/jacobi3dSYNC.ci}
\end{frame}
\begin{frame}[fragile]
\frametitle{Jacobi: .ci file (with \textbf{asynchronous} reductions)}
\lstinputlisting[basicstyle=\tiny,linerange={22-50}]{code/jacobi3d.ci}
\end{frame}
% \begin{frame}[fragile]
% \frametitle{Jacobi: .cpp file}
% \lstinputlisting[basicstyle=\tiny,linerange={40-46,89-103}]{code/jacobi3d.C}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Jacobi: .cpp file}
% \lstinputlisting[basicstyle=\tiny,linerange={109-139}]{code/jacobi3d.C}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Jacobi: .cpp file}
% \lstinputlisting[basicstyle=\tiny,linerange={109-138}]{code/jacobi3d.C}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Jacobi: .cpp file}
% \lstinputlisting[basicstyle=\tiny,linerange={164-190}]{code/jacobi3d.C}
% \end{frame}
% \begin{frame}[fragile]
% \frametitle{Jacobi: .cpp file}
% \lstinputlisting[basicstyle=\tiny,linerange={201-230}]{code/jacobi3d.C}
% \end{frame}