-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlecture13.tex
317 lines (244 loc) · 7.95 KB
/
lecture13.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
%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 13: Futurization 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 12}
\begin{block}{What you should know from last lecture}
\begin{itemize}
\item One-dimensional heat equation
\item Serial implementation of the one-dimensional heat equation
\end{itemize}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{HPX features}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{A ready future}
Some times, we need a future, which is already ready, since there is no computation needed.
\begin{lstlisting}
hpx::lcos::future<double> f
= hpx::make_ready_future(1);
\end{lstlisting}
\begin{block}{Example}
\begin{lstlisting}
auto f = hpx::make_ready_future(1);
/*
* Since the future is ready the output will happen
* and there will be no barrier.
*/
std::cout << f.get() << std::endl;
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}[fragile]{Data flow I}
\begin{lstlisting}
std::vector<hpx::lcos::future<int>> futures;
futures.push_back(hpx::async(square,10));
futures.push_back(hpx::async(square,100));
// When all returns a future containing the vector
// of futures
hpx::when_all(futures).then([](auto&& f){
// We need to unwrap this future to get
// the content of it
auto futures = f.get();
int result = 0;
for(size_t i = 0; i < futures.size();i++)
result += futures[i].get();
std::cout << result << std::endl;
});
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Data flow II}
\begin{lstlisting}
hpx::dataflow(hpx::launch::sync,[](auto f){
int result = 0;
for(size_t i = 0; i < f.size();i++)
result += f[i].get();
std::cout << result << std::endl;
},futures);
\end{lstlisting}
\begin{block}{Parameters}
\begin{enumerate}
\item \lstinline|hpx::launch::async| or \lstinline|hpx::launch::sync|
\item The function to call
\item Futures to the arguments to the arguments of the function
\end{enumerate}
\end{block}
\end{frame}
\begin{frame}[fragile]{Passing futures}
\begin{lstlisting}
void sum(int first, int second){
std:: cout << first + second << std::endl;
}
auto f1 = hpx::async(square,10);
auto f2 = hpx::async(square,100);
// We have to call .get() to pass
// the values of the future
sum(f1.get(),f2.get());
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Unwrapping futures}
\begin{lstlisting}
void sum(int first, int second){
std:: cout << first + second << std::endl;
}
// We can unwrapp the function
auto fp = hpx::util::unwrapping(sum);
// After unwrapping, we can pass the future
// directly to the function
hpx::dataflow(hpx::launch::sync,fp,f1,f2);
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]{Shared future}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{lstlisting}
hpx::lcos::future
\end{lstlisting}
\begin{itemize}
\item Exclusive ownership model
\item If the future is out of the scope, it will be not available anymore.
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\begin{lstlisting}
hpx::shared_future
\end{lstlisting}
\begin{itemize}
\item Reference counting ownership model
\item All references to the object are counted and the object is only destroyed if there are zero references.
\end{itemize}
\end{column}
\end{columns}
\vspace{.5cm}
\begin{center}
Can be seen to be equal to \lstinline|std::unique_ptr| and \lstinline|std::shared_ptr|.
\end{center}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Scaling results}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Overhead}
\begin{center}
\begin{tikzpicture}
\mode<beamer>{
\begin{axis}[xlabel=Grid points,ylabel=Execution time, grid=both,title=1 CPU,legend style = {text=white,fill=background,draw=background}]
\addplot+ table [x=Grid_Points, y=Execution_Time_sec, col sep=comma, azure] {./data/stencil_serial.dat};
\addlegendentry{Serial}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma, awesome] {./data/stencil_2_1.dat};
\addlegendentry{Futurization}
\end{axis}
}
\mode<handout>{
\selectcolormodel{gray}
\begin{axis}[xlabel=Grid points,ylabel=Execution time, grid=both,title=1 CPU]
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma] {./data/stencil_serial.dat};
\addlegendentry{Serial}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma] {./data/stencil_2_1.dat};
\addlegendentry{Futurization}
\end{axis}
}
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}{Scaling}
\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=black,draw=black}]
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma,azure] {./data/stencil_2_1.dat};
\addlegendentry{1 CPU}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma,awesome] {./data/stencil_2_2.dat};
\addlegendentry{2 CPU}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma, asparagus] {./data/stencil_2_4.dat};
\addlegendentry{4 CPU}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma,atomictangerine] {./data/stencil_2_6.dat};
\addlegendentry{6 CPU}
\end{axis}
}
\mode<handout>{
\selectcolormodel{gray}
\begin{axis}[xlabel=Grid points,ylabel=Execution time, grid=both,title= Stencil 2,legend pos=north west]
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma] {./data/stencil_2_1.dat};
\addlegendentry{1 CPU}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma] {./data/stencil_2_2.dat};
\addlegendentry{2 CPU}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma] {./data/stencil_2_4.dat};
\addlegendentry{4 CPU}
\addplot table [x=Grid_Points, y=Execution_Time_sec, col sep=comma] {./data/stencil_2_6.dat};
\addlegendentry{6 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 \lstinline|hpx::make_ready_future|
\item \lstinline|hpx::dataflow|
\item \lstinline|hpx::util::unwrapping|
\item \lstinline|hpx::shared_future|
\end{itemize}
\end{block}
\end{frame}
\end{document}