Skip to content

Commit 4988e7c

Browse files
committed
Merge branch 'thrust-for-each' into 'master'
add for_each fixes and presentation See merge request correaa/boost-multi!1763
2 parents 92621ea + a24270c commit 4988e7c

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

talk/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
*.pdf
88
*.fdb_latexmk
99
*.fls
10-
*.synctex.gz
11-
10+
*.synctex*
11+
*.vrb

talk/presentation.tex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,35 @@
193193
\end{frame}
194194

195195

196+
\begin{frame}[fragile]{Algorithms}
197+
Take a 64x64x64 array ($\sim 250$k elements) \lstinline|A|, apply a compute-bound op.
198+
199+
\only<1>{
200+
\begin{lstlisting}
201+
for(auto&& plane : A) {
202+
for(auto&& row : plane) {
203+
for(auto&& elem : row) {
204+
elem = op(elem);
205+
}
206+
}
207+
}
208+
\end{lstlisting}
209+
}
210+
211+
\only<2>{
212+
\begin{lstlisting}
213+
std::for_each(A.begin(), A.end(), [](auto&& plane) {
214+
for(auto&& row : plane) {
215+
for(auto&& elem : row) {
216+
elem = op(elem);
217+
}
218+
}
219+
});
220+
\end{lstlisting}
221+
}
222+
223+
timing: \textbf{0.0026 sec}
224+
\end{frame}
225+
226+
196227
\end{document}

test/for_each.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ auto main() -> int { // NOLINT(bugprone-exception-escape)
6262
auto cpu_own = multi::array<T, 3>({64, 64, 64}, 0);
6363

6464
auto&& cpu = cpu_own();
65+
{
66+
auto_timer const _{"triple nested for"};
67+
for(auto&& plane : cpu) { // NOLINT(modernize-use-ranges)
68+
for(auto&& row : plane) { // NOLINT(altera-unroll-loops)
69+
for(auto&& elem : row) { // NOLINT(altera-unroll-loops)
70+
elem += std::sqrt(std::pow(elem, 1.5) + std::sin(elem));
71+
}
72+
}
73+
}
74+
}
75+
6576
{
6677
auto_timer const _{"std::for_each"};
6778
std::for_each(cpu.begin(), cpu.end(), [](auto&& plane) { // NOLINT(modernize-use-ranges)

0 commit comments

Comments
 (0)