-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpar-scan.tex
64 lines (57 loc) · 1.4 KB
/
par-scan.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
\subsection{Scans}
\begin{frame}[t]{Scan pattern}
\begin{itemize}
\item A \textmark{scan} pattern computes a sequence of
partial reductions on a dataset.
\begin{itemize}
\item A scan on $x_0$, $x_1$, $x_2$, \ldots
\item Results in the sequence:
\begin{itemize}
\item $x_0$
\item $x_0 + x_1$
\item $x_0 + x_1 + x_2$
\item \ldots
\end{itemize}
\end{itemize}
\vfill
\item Two alternatives:
\begin{itemize}
\item \cppid{std::exclusive\_scan()}
\item \cppid{std::inclusive\_scan()}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}[t,fragile]{Computing CDF}
\begin{lstlisting}
auto compute_cdf(const std::vector<int> & histogram)
{
std::vector<int> cdf(histogram.size());
std::inclusive_scan(std::execution::par,
histogram.begin(), histogram.end(),
cdf.begin(),
0
);
return cdf;
}
\end{lstlisting}
\end{frame}
\begin{frame}[t,fragile]{Combining transform and scan}
\begin{lstlisting}
auto compute_cdf(const std::vector<int> & histogram)
{
std::vector<int> cdf(histogram.size());
std::transform_inclusive_scan(std::execution::par,
histogram.begin(), histogram.end(),
cdf.begin(),
0,
[](auto x, auto y) { return x+y; }
[](auto x) {
if (x<0) return 0;
if (x>255) return 255;
return x;
}
);
return cdf;
}
\end{lstlisting}
\end{frame}