-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlecture16.tex
396 lines (298 loc) · 9.64 KB
/
lecture16.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
%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 16: Preparation for distributed computing }
\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 15}
\begin{block}{What you should know from last lecture}
\begin{itemize}
\item Parallel partition-based implementation
\item Allocating and deallocating memory with the \lstinline|new| and \lstinline|delete| expression
\end{itemize}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Serialization}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{What is this serialization thingy}
If we want to send ab object or a bunch of objects over the network to another node of the cluster:
\begin{itemize}
\item The sender needs to flatten the object(s) to a one-dimensional stream of bits.
\item The receiver needs to unflatten the one-dimensional stream of bits and convert it back to the objects(s)
\end{itemize}
You have to decide whether to serialize
\begin{itemize}
\item human-readable (text)
\item non-human-readable (binary)
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Serialization in HPX~\cite{ac:2017}}
\begin{block}{Initialize data}
\begin{lstlisting}
size_t size = 5;
double* data = new double[size];
\end{lstlisting}
\end{block}
\begin{block}{Serialization}
\begin{lstlisting}
using hpx::serialization::serialize_buffer;
serialize_buffer<double> serializable_data(
data, size,
serialize_buffer<double>::init_mode::reference);
\end{lstlisting}
\end{block}
\begin{block}{Deserialization}
\begin{lstlisting}
double* copied_data = serializable_data.data();
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}{Sending data over the network}
\begin{center}
\begin{tikzpicture}
\draw (0,0) rectangle ++(3,-0.75) node[pos=.5] {Allocate data};
\draw (0,-1.25) rectangle ++(3,-.75) node[pos=.5] {Serialize data};
\draw (0,-2.5) rectangle ++(3,-.75) node[pos=.5] {Send parcel};
\draw (-0.1,0.1) rectangle ++(3.2,-3.75);
\node[above] at (1.5,0) {Locality 1};
\draw (6,0) rectangle ++(3,-0.75) node[pos=.5] {Deserialize data};
\draw (6,-1.25) rectangle ++(3,-.75) node[pos=.5] {Allocate data};
\draw (6,-2.5) rectangle ++(3,-.75) node[pos=.5] {Receive parcel};
\draw (5.9,0.1) rectangle ++(3.2,-3.75);
\node[above] at (7.5,0) {Locality 2};
\draw (1.5,-0.75) -- (1.5,-1.23) ;
\draw (1.5,-2.) -- (1.5,-2.5) ;
\draw (3,-2.875) -- (6,-2.875) ;
\draw (7.5,-0.75) -- (7.5,-1.23) ;
\draw (7.5,-2.) -- (7.5,-2.5) ;
\end{tikzpicture}
\end{center}
The communication between the localities (nodes) is handled by the so-called parcel port~\cite{kaiser2009parallex}. HPX uses MPI or libfrabric for communication between nodes.
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Components}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Components and Actions}
For distributed computations within HPX, we need to look into following
\begin{enumerate}
\item Server (Component) \\
The server represents the global data and is a so-called HPX component which allows to create and access the data remotely through a global address space (AGAS~\cite{kaiser2014hpx}) using \lstinline|hpx::id_type|.
\item Component action \\
Each function of the component needs to be wrapped into a component action to be remotely available.
\item Plain actions \\
Allows to wrap global (\lstinline|static|) functions in an action. So this function can be called remotely on a given locality.
\end{enumerate}
\end{frame}
\begin{frame}[fragile]{Server (Component)}
\begin{lstlisting}
struct data_server
: hpx::components::component_base<data_server>{
data_server(size_t size)
{
data = std::shared_ptr<double[]>(new double[size]);
}
private:
// This data will be in the global address space
std::shared_ptr<double[]> data;
};
\end{lstlisting}
Note that we need component actions to call the public functions of the server.
\end{frame}
\begin{frame}[fragile]{Component actions}
\begin{lstlisting}
struct data_server
: hpx::components::component_base<data_server>{
// This function needs to be wrapped in an action
hpx::serialization::serialize_buffer<double> getData()
{
typedef hpx::serialization::serialize_buffer<double>
buffer;
return buffer(data.get(), size,
buffer::init_mode::reference);
}
// Define the action for remote access
HPX_DEFINE_COMPONENT_DIRECT_ACTION(data_server,
getData, getData_action);
};
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Component actions}
\begin{lstlisting}
// Define the action for remote access
HPX_DEFINE_COMPONENT_DIRECT_ACTION(
data_server,
getData,
getData_action);
\end{lstlisting}
where
\begin{itemize}
\item The first argument is the name of the component
\item The second argument is the name of the function
\item The third argument is the name of the action
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Registering components and actions}
\begin{lstlisting}
// Generation of the code, which is needed to call
// the component action remotely
// Registering the component
typedef hpx::components::component<data_server>
data_server_type;
HPX_REGISTER_COMPONENT(data_server_type,
data_server);
// Registering the component actions
typedef data_server::getData_action getData_action;
HPX_REGISTER_ACTION(getData_action);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{The data client I}
\begin{lstlisting}
struct data
: hpx::components::client_base<data,data_server>
{
// Define client base
typedef hpx::components::client_base<data,
data_server> base_type;
// Constructor to generate the data_server object
// The where argument specifies where the object is
// allocated
data(hpx::naming::id_type where,std::size_t size) :
base_type(hpx::new_<data_server>(where,size)){}
);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{The data client II}
\begin{lstlisting}
struct data
: hpx::components::client_base<data,data_server>
{
// Wrap the actions into futures
hpx::future<size_t> getSize(){
return hpx::async(getSize_action(),get_id());
}
typedef hpx::serialization::serialize_buffer<double>
buffer;
hpx::future<buffer>getData(){
return hpx::async(getData_action(),get_id());
}
);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Global functions}
\begin{block}{Function definition}
\begin{lstlisting}
static void square(double a ){
std::cout << a * a << std::endl;
}
\end{lstlisting}
\end{block}
\begin{block}{Define the action}
\begin{lstlisting}
HPX_PLAIN_ACTION(square, square_action);
\end{lstlisting}
where
\begin{itemize}
\item The first argument is the name of the function
\item The second argument is the name of the action
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[fragile]{Knowing where you are}
\begin{block}{Getting the ID of your locality}
\begin{lstlisting}
hpx::find_here();
\end{lstlisting}
\end{block}
\begin{block}{Getting the ID of the component's locality}
\begin{lstlisting}
hpx::get_colocation_id(hpx::launch::sync, get_id();
\end{lstlisting}
\end{block}
\begin{block}{Getting the ID of the component's locality}
\begin{lstlisting}
bool is_local
= (hpx::get_colocation_id(hpx::launch::sync,
get_id()) == hpx::find_here());
\end{lstlisting}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Summary}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Summary}
\begin{block}{After this lecture, you should know}
\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{References}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t, allowframebreaks]
\frametitle{References}
\bibliographystyle{plain}
\bibliography{bib}
\end{frame}
\end{document}