-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlecture11.tex
383 lines (281 loc) · 9.59 KB
/
lecture11.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
%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 11: Introduction to HPX}
\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 10}
\begin{block}{What you should know from last lecture}
\begin{itemize}
\item Conjugate Gradient method
\item Solving equation systems using BlazeIterative
\end{itemize}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{What is HPX}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Description of HPX\footnote{\tiny\url{https://github.com/STEllAR-GROUP/hpx}}$^,$\footnote{\tiny\url{https://stellar-group.github.io/hpx/docs/sphinx/branches/master/html/index.html}}}
HPX (High Performance ParalleX) is a general purpose C++ runtime system for parallel and distributed applications of any scale. It strives to provide a unified programming model which transparently utilizes the available resources to achieve unprecedented levels of scalability. This library strictly adheres to the C++11 Standard and leverages the Boost C++ Libraries which makes HPX easy to use, highly optimized, and very portable.
\end{frame}
\begin{frame}{HPX's features}
\begin{itemize}
\item HPX exposes a uniform, standards-oriented API for ease of programming parallel and \textcolor{blue}{distributed} applications.
\item HPX provides unified syntax and semantics for \textcolor{blue}{local and remote} operations.
\item HPX exposes a uniform, flexible, and extendable performance counter framework which can enable runtime adaptivity
\item HPX has been designed and developed for systems of any scale, from hand-held devices to very large scale systems (Raspberry Pi, Android, Server, up to super computers).
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Compilation and running}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Compilation and running}
\begin{block}{CMake}
\begin{lstlisting}[language=bash]
cmake_minimum_required(VERSION 3.3.2)
project(my_hpx_project CXX)
find_package(HPX REQUIRED)
add_hpx_executable(my_hpx_program
SOURCES main.cpp
)
\end{lstlisting}
\end{block}
\begin{block}{Running}
\begin{lstlisting}[language=bash]
cmake .
make
./my_hpx_program --hpx:threads=4
\end{lstlisting}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Hello World}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{A small HPX program}
\begin{block}{C++}
\begin{lstlisting}
int main()
{
std::cout << "Hello World!\n" << hpx::flush;
return 0;
}
\end{lstlisting}
\end{block}
\begin{block}{HPX}
\begin{lstlisting}
#include <hpx/hpx_main.hpp>
#include <iostream>
int main()
{
std::cout << "Hello World!\n" << std::endl;
return 0;
}
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]{Hello world using \lstinline{hpx::init}}
\begin{lstlisting}
#include <hpx/hpx_init.hpp>
#include <iostream>
int hpx_main(int, char**)
{
// Say hello to the world!
std::cout << "Hello World!\n" << std::endl;
return hpx::finalize();
}
int main(int argc, char* argv[])
{
return hpx::init(argc, argv);
}
\end{lstlisting}
\begin{center}
Note that here we initialize the HPX runtime explicitly.
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Asynchronous programming}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Futurization\footnote{\tiny\href{https://stellar-group.github.io/hpx/docs/sphinx/latest/html/examples/fibonacci_local.html?highlight=async}{Example: hpx::async}}}
\begin{lstlisting}
#include <hpx/hpx_init.hpp>
#include <hpx/incldue/lcos.hpp>
int square(int a)
{
return a*a;
}
int main()
{
hpx::future<int> f1 = hpx::async(square,10);
hpx::cout << f1.get() << hpx::flush;
return EXIT_SUCCESS;
}
\end{lstlisting}
\vspace{-0.25cm}
\begin{center}
Note that we just replaced \lstinline|std| by the namespace \lstinline|hpx|
\end{center}
\end{frame}
\begin{frame}[fragile]{Advanced synchronization\footnote{\tiny\href{https://stellar-group.github.io/hpx/docs/sphinx/latest/html/api.html?highlight=when_all\#_CPPv4IDpEN3hpx8when_allE6futureI5tupleIDp6futureI1TEEEDpRR1T}{Documentation: hpx::when\_all}}}
\begin{lstlisting}
std::vector<hpx::future<int>> futures;
futures.push_back(hpx::async(square,10);
futures.push_back(hpx::async(square,100);
hpx::when_all(futures).then([](auto&& f){
auto futures = f.get();
std::cout << futures[0].get()
<< " and " << futures[1].get();
});
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Synchronization\footnote{\tiny\href{https://stellar-group.github.io/hpx/docs/sphinx/latest/html/terminology.html\#term-lco}{Documentation: LCO}}}
\begin{itemize}
\item \lstinline|when_all| \\
It \textit{AND}-composes all the given futures and returns a new future containing all the given futures.
\item \lstinline|when_any| \\
It \textit{OR}-composes all the given futures and returns a new future containing all the given futures.
\item \lstinline|when_each| \\
It \textit{AND}-composes all the given futures and returns a new future containing all futures being ready.
\item \lstinline|when_some| \\
It \textit{AND}-composes all the given futures and returns a new future object representing the same list of futures after n of them finished.
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Parallel algorithms}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Example: Reduce}
\begin{block}{C++}
\begin{lstlisting}
#include<algorithm>
#include<execution>
std::reduce(std::execution::par,
values.begin(),values.end(),0);
\end{lstlisting}
\end{block}
\begin{block}{HPX}
\begin{lstlisting}
#include<hpx/include/parallel_reduce.hpp>
#include<vector>
hpx::ranges::reduce(
hpx::execution::par,
values.begin(),values.end(),0);
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]{Example: Reduce with future}
\begin{lstlisting}
auto f =
hpx::ranges::reduce(
hpx::execution::par(
hpx::execution::task),
values.begin(),
values.end(),0);
std::cout<< f.get();
\end{lstlisting}
\begin{itemize}
\item \lstinline|hpx::execution::par| Parallel execution
\item \lstinline|hpx::execution::seq| Sequential execution
\item \lstinline|hpx::execution::task| Task-based execution
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Execution parameters}
\begin{lstlisting}
#include<hpx/include/parallel_executor_parameters.hpp>
hpx::execution::static_chunk_size scs(10);
hpx::ranges::reduce(
hpx::execution::par.with(scs),
values.begin(),
values.end(),0);
\end{lstlisting}
\begin{itemize}
\item \lstinline|hpx::execution::static_chunk_size| \\
Loop iterations are divided into pieces of a given size and then assigned to threads.
\item \lstinline|hpx::execution::auto_chunk_size| \\
Pieces are determined based on the first 1\% of the total loop iterations.
\item \lstinline|hpx::execution::dynamic_chunk_size| \\
Dynamically scheduled among the cores and if one core finished it gets dynamically assigned a new chunk.
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Example: Range-based for loops}
\begin{lstlisting}
#include<vector>
#include<iostream>
#include<hpx/include/parallel_for_loop.hpp>
std::vector<double> values = {1,2,3,4,5,6,7,8,9};
hpx::for_loop(
hpx::execution::par,
0,
values.size();
[](boost::uint64_t i)
{
std::cout<< values[i] << std::endl;
}
);
\end{lstlisting}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Summary}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Summary}
\begin{block}{After this lecture, you should know}
\begin{itemize}
\item What is HPX
\item Asynchronous programming using HPX
\item Shared memory parallelism using HPX
\end{itemize}
\end{block}
\end{frame}
\end{document}