-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlecture17.tex
467 lines (356 loc) · 11.6 KB
/
lecture17.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
%Template
%Copyright (C) 2019 Patrick Diehl
%
%This program is free software: you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation, either version 3 of the License, or
%(at your option) any later version.
%This program is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%GNU General Public License for more details.
%You should have received a copy of the GNU General Public License
%along with this program. If not, see <http://www.gnu.org/licenses/>.
\providecommand\classoption{12pt}
\documentclass[\classoption]{beamer}
\input{./template/packages}
\input{template/variables.tex}
% frame slide
\title{\coursename}
\subtitle{Lecture 17: Distributed implementation of the 1D heat equation}
\author{\tiny Patrick Diehl \orcid{0000-0003-3922-8419}}
%\institute {
% \href{}{\tt \scriptsize \today}
%}
\date {
\tiny \url{\courseurl}
\vspace{2cm}
\doclicenseThis
}
\usepackage{ifxetex}
\ifxetex
\usepackage{fontspec}
\setmainfont{Raleway}
\fi
\ifluatex
\usepackage{fontspec}
\setmainfont{Raleway}
\fi
\begin{document} {
\setbeamertemplate{footline}{}
\frame {
\titlepage
}
}
\frame{
\tableofcontents
}
\AtBeginSection[]{
\begin{frame}
\vfill
\centering
\begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
\usebeamerfont{title}\insertsectionhead\par%
\end{beamercolorbox}
\vfill
\end{frame}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Reminder}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Lecture 16}
\begin{block}{What you should know from last lecture}
\begin{itemize}
\item Serialization
\item Distributed computing
\begin{itemize}
\item Plain actions
\item Components
\item Components actions
\end{itemize}
\end{itemize}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Serialization}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Adding serialization}
Note even if all the code in this iteration runs for now only one one locality (node), we have to add serialization since all arguments passed to an action have to support serialization.
\vspace{0.5cm}
\begin{lstlisting}
// We have to add this class as a friend
friend class hpx::serialization::access;
// Add a function to serialize all arguments
template <typename Archive>
void serialize(Archive& ar,
const unsigned int version) const {}
\end{lstlisting}
Note that we will implement this function in the next lecture when we prepare the code to run on multiple localities.
\end{frame}
\begin{frame}[fragile]{Extending the partition data with serialization}
\begin{lstlisting}
class partition_data
{
private:
// Note we have to make the unique_ptr to
// a shared_ptr since we share the data
std::shared_ptr<double[]> data_;
std::size_t size_;
friend class hpx::serialization::access;
template <typename Archive>
void serialize(Archive& ar,
const unsigned int version) const {}
};
\end{lstlisting}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Adding components and actions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Adding a server to handle the partitions I}
\begin{lstlisting}
struct partition_server
: hpx::components::component_base<partition_server>
{
// construct new instances
partition_server() {}
partition_server(partition_data const& data)
: data_(data)
{}
private:
partition_data data_;
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Adding component action to the server II}
\begin{lstlisting}
struct partition_server
: hpx::components::component_base<partition_server>
{
// access data
partition_data get_data() const
{
return data_;
}
// Every member function which has to be invoked
// remotely needs to be wrapped into a
// component action.
HPX_DEFINE_COMPONENT_DIRECT_ACTION(
partition_server,
get_data, get_data_action);
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Register the component and component action}
\begin{lstlisting}
// Register the component
typedef hpx::components::component<partition_server>
partition_server_type;
HPX_REGISTER_COMPONENT(partition_server_type,
partition_server);
// Register the component action
typedef partition_server::get_data_action
get_data_action;
HPX_REGISTER_ACTION(get_data_action);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Writing the client helper class I}
\begin{lstlisting}
struct partition
: hpx::components::client_base<partition,
partition_server>
{
typedef hpx::components::client_base<partition,
partition_server> base_type;
partition() {}
// Create new component on locality 'where'
// and initialize the held data
partition(hpx::id_type where, std::size_t size,
double initial_value)
: base_type(hpx::new_
<partition_server>(where, size,
initial_value))
{}
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Writing the client helper class II}
\begin{lstlisting}
struct partition
: hpx::components::client_base<partition,
partition_server>
{
// Create a new component on the locality co-located
// to the id 'where'. The new instance will be
// initialized from the given partition_data.
partition(hpx::id_type where,
partition_data && data)
: base_type(hpx::new_<partition_server>
(hpx::colocated(where), std::move(data)))
{}
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Writing the client helper class III}
\begin{lstlisting}
struct partition
: hpx::components::client_base<partition,
partition_server>
{
// Attach a future representing a
// (possibly remote) partition.
partition(hpx::future<hpx::id_type> && id)
: base_type(std::move(id))
{}
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Writing the client helper class IV}
\begin{lstlisting}
struct partition
: hpx::components::client_base<partition,
partition_server>
{
// Unwrap a future<partition> (a partition already
// holds a future to the id of the referenced object,
// thus unwrapping accesses this inner future).
partition(hpx::future<partition> && c)
: base_type(std::move(c))
{}
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Writing the client helper class V}
\begin{lstlisting}
struct partition
: hpx::components::client_base<partition,
partition_server>
{
// Invoke the (remote) member function which
// gives us access to the data.
hpx::future<partition_data> get_data() const
{
return hpx::async(get_data_action(), get_id());
}
};
\end{lstlisting}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Preparing the simulation control to be distributed}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Updating the computation of the heat}
\begin{lstlisting}
static partition heat_part(partition const& left,
partition const& middle,partition const& right)
{
return dataflow(
unwrapping(
[middle](partition_data const& l,
partition_data const& m,
partition_data const& r)
{
// The new partition_data will be allocated
// on the same locality as 'middle'.
return partition(middle.get_id(),
heat_part_data(l, m, r));
}
),
left.get_data(), middle.get_data(),
right.get_data());
}
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Updating the computation of the heat II}
\begin{lstlisting}
stepper::space stepper::do_work(std::size_t np,
std::size_t nx, std::size_t nt)
{
// Initial conditions: f(0, i) = i
for (std::size_t i = 0; i != np; ++i)
U[0][i] = partition(hpx::find_here(),
nx, double(i));
}
\end{lstlisting}
\vspace{0.25cm}
Note that we only use \lstinline|hpx::find_here()| the code will run one one logicality only.
\end{frame}
\begin{frame}[fragile]{Updating the computation of the heat III}
\begin{lstlisting}
// Generate place holder for the changing arguments
using hpx::util::placeholders::_1;
using hpx::util::placeholders::_2;
using hpx::util::placeholders::_3;
// Pass the fixed argument to the function
auto Op = hpx::util::bind(heat_part_action(),
hpx::find_here(), _1, _2, _3);
next[i] = dataflow(
hpx::launch::async, Op,
current[idx(i, -1, np)],
current[i],
current[idx(i, +1, np)]
);
\end{lstlisting}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Scaling results}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Scaling for 10000000 discrete mesh points}
\begin{center}
\begin{tikzpicture}
\mode<beamer>{
\begin{axis}[xlabel=Grid points,ylabel=Execution time, grid=both,title= Stencil 2,legend pos=north west,legend style = {text=white,fill=background,draw=background}]
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_1cpu_1000000.dat};
\addlegendentry{1 CPU}
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_2cpu_1000000.dat};
\addlegendentry{2 CPU}
\end{axis}
}
\mode<handout>{
\selectcolormodel{gray}
\begin{axis}[xlabel=Partitions,ylabel=Execution time, grid=both,title=Stencil 5,legend style={at={(0.5,0.5)},anchor=west}]
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_1cpu_1000000.dat};
\addlegendentry{1 CPU}
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_2cpu_1000000.dat};
\addlegendentry{2 CPU}
\end{axis}
}
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}{Scaling for increasing amount of work}
\begin{center}
\begin{tikzpicture}
\mode<beamer>{
\begin{axis}[xlabel=Grid points,ylabel=Execution time, grid=both,title= Stencil 2,legend pos=north west,legend style = {text=white,fill=background,draw=background}]
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_1cpu_scaling.dat};
\addlegendentry{1 CPU}
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_2cpu_scaling.dat};
\addlegendentry{2 CPU}
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_4cpu_scaling.dat};
\addlegendentry{4 CPU};
\end{axis}
}
\mode<handout>{
\selectcolormodel{gray}
\begin{axis}[xlabel=Partitions,ylabel=Execution time, grid=both,title=Stencil 5,legend pos=north west]
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_1cpu_scaling.dat};
\addlegendentry{1 CPU}
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_2cpu_scaling.dat};
\addlegendentry{2 CPU}
\addplot table [x=Partitions, y=Execution_Time_sec, col sep=comma] {./data/stencil_5_4cpu_scaling.dat};
\addlegendentry{4 CPU};
\end{axis}
}
\end{tikzpicture}
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Summary}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Summary}
\begin{block}{After this lecture, you should know}
\begin{itemize}
\item How to use components and actions to make remote function calls
\end{itemize}
\end{block}
\end{frame}
\end{document}