From 3610a259bafab91b5aa0fd8e2ef9d35ac9b28623 Mon Sep 17 00:00:00 2001 From: Pariksheet Nanda Date: Tue, 21 Jul 2026 13:57:54 -0400 Subject: [PATCH] Review C++ lambda syntax for legacy slides 33-39/72 (#162) Thanks to Patrick for suggesting the cppreference URL for students to learn more later and talking through how best to briefly describe C++ lambdas. --- .../sections/Section_DataParallelPatterns.tex | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Content/Presentations/sections/Section_DataParallelPatterns.tex b/Content/Presentations/sections/Section_DataParallelPatterns.tex index c01881c9..38b5ec2c 100644 --- a/Content/Presentations/sections/Section_DataParallelPatterns.tex +++ b/Content/Presentations/sections/Section_DataParallelPatterns.tex @@ -271,6 +271,8 @@ @gray);@gray \end{code} + (Will review C\texttt{++} Lambdas on the next slide) + \pause A lambda is not \textit{magic}, it is the compiler \textbf{auto-generating} a \textbf{functor} for you. @@ -291,6 +293,36 @@ %========================================================================== +\begin{frame}[fragile]{Quick review of C\texttt{++} Lambda syntax} + \url{https://cppreference.com/cpp/language/lambda} + + C++ Lambdas auto-generate the variable capture code: + + \begin{code}[keywords={}, frame=single, numbers=left] +@grayKokkos::parallel_for(numberOfAtoms,@gray + [@pattern=@pattern] (const int64_t atomIndex) { // copy by value, implicit + @darkgreenatomForces@darkgreen[atomIndex] = calculateForce(@darkreddata@darkred); + } +@gray);@gray +\end{code} + +\begin{code}[keywords={}, frame=single, numbers=left, firstnumber=2] + [@patternatomForces, data@pattern] (const int64_t atomIndex) { // explicit +\end{code} + +\pause + +\begin{code}[keywords={}, frame=single, numbers=left, firstnumber=2] + [@pattern&@pattern] (const int64_t atomIndex) { // by reference, implicit +\end{code} + +\begin{code}[keywords={}, frame=single, numbers=left, firstnumber=2] + [@pattern&atomForces, &data@pattern] (const int64_t atomIndex) { // explicit +\end{code} +\end{frame} + +%========================================================================== + \begin{frame}[fragile]{parallel\_for examples} \textbf{How does this compare to OpenMP?}