diff --git a/exercises_presentation/figures/poisson.png b/exercises_presentation/figures/poisson.png new file mode 100644 index 0000000..4bd9777 Binary files /dev/null and b/exercises_presentation/figures/poisson.png differ diff --git a/exercises_presentation/figures/poisson.py b/exercises_presentation/figures/poisson.py new file mode 100644 index 0000000..67c66b9 --- /dev/null +++ b/exercises_presentation/figures/poisson.py @@ -0,0 +1,19 @@ +import numpy as np +import matplotlib.pyplot as plt + + +N = 1000 +dx = 1 / N + +x, y = np.mgrid[slice(0, 1, dx), slice(0, 1, dx)] +z = -200.0 * np.pi**2 * np.sin(10.0 * np.pi * x) * np.sin(10.0 * np.pi * y) + +fig, ax = plt.subplots() +p = ax.pcolormesh(x, y, z) + +ax.set_xlabel('x') +ax.set_ylabel('y') + +plt.show() + +fig.savefig('poisson.png') diff --git a/exercises_presentation/figures/stencil.pdf b/exercises_presentation/figures/stencil.pdf new file mode 100644 index 0000000..3ab6ee1 Binary files /dev/null and b/exercises_presentation/figures/stencil.pdf differ diff --git a/exercises_presentation/figures/stencil.svg b/exercises_presentation/figures/stencil.svg new file mode 100644 index 0000000..552efe6 --- /dev/null +++ b/exercises_presentation/figures/stencil.svg @@ -0,0 +1,181 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + Ui, j + + + + Ui-1, j + + + + Ui+1, j + + + + Ui, j+1 + + + + Ui, j-1 + + + diff --git a/exercises_presentation/phys_743_exercises_presentation.tex b/exercises_presentation/phys_743_exercises_presentation.tex new file mode 100644 index 0000000..958a87b --- /dev/null +++ b/exercises_presentation/phys_743_exercises_presentation.tex @@ -0,0 +1,350 @@ +\documentclass[8pt,aspectratio=169,notes]{beamer} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage[english]{babel} +\usepackage[most, minted]{tcolorbox} +\usepackage{xcolor} +\usepackage{graphicx} +\usepackage{fancyvrb} +\usepackage{tikz} +\usepackage{colortbl} +\usepackage{booktabs} +\usepackage[super]{nth} +\usepackage{amssymb} +\usepackage[binary-units=true]{siunitx} +\usepackage{booktabs} +\usepackage{pgfpages} + +% \setbeameroption{show notes on second screen=left} + +\usemintedstyle{emacs} + +\makeatletter +% Define commands to select the folder where the Beamer theme lies in +\def\beamer@calltheme#1#2#3{% + \def\beamer@themelist{#2} + \@for\beamer@themename:=\beamer@themelist\do + {\usepackage[{#1}]{\beamer@themelocation/#3\beamer@themename}}} + +\def\usefolder#1{ + \def\beamer@themelocation{#1} +} +\def\beamer@themelocation{} + +% Patch Table of Content to insert fixed spaces between items instead of vfills +\patchcmd{\beamer@sectionintoc} +{\vfill} +{\vskip\itemsep} +{} +{} + +% New counter for line numbers +\newcounter{verbatim@cnt} + +% This is for color band on the linenos in listings +\AtEndEnvironment{Verbatim}{% + \stepcounter{verbatim@cnt}% + \protected@write\@auxout{}{% + \global\protect\@namedef{verbatim@numwidth@\the\c@verbatim@cnt}{% + \ifnum\c@FancyVerbLine>999 + 7.5mm% + \else\ifnum\c@FancyVerbLine>99 + 6mm% + \else + 4mm% + \fi\fi + }% + }% +} + +\def\minted@auto@numwidth#1{% + \ifcsname verbatim@numwidth@\the\numexpr\c@verbatim@cnt#1\relax\endcsname + \csname verbatim@numwidth@\the\numexpr\c@verbatim@cnt#1\relax\endcsname + \else + 4mm% + \fi +} + +\tcbset{bashstyle/.style={ + colframe=black!70, + listing engine=minted, + listing only, + minted style=colorful, + minted language=console, + size=fbox, + breakable, + enhanced, + minted options={ + autogobble=true, + breaklines=true, + breakbefore=., + numbersep=2mm, + }, + }} + +\tcbset{cxx/.style={ + colframe=black!70, + listing engine=minted, + listing only, + minted style=emacs, + minted language=C++, + size=fbox, + breakable, + enhanced, + minted options={ + autogobble=true, + linenos, + breaklines=true, + breakbefore=., + numbersep=2mm, + escapeinside=||, + }, + overlay={% + \begin{tcbclipinterior} + \fill[gray!25] (frame.south west) rectangle ([xshift=\dimexpr\minted@auto@numwidth{}\relax]frame.north west); + \end{tcbclipinterior} + }, + % in "left", \c@verbatim@cnt is not stepped yet, hence the argument "+1" + left=\dimexpr\minted@auto@numwidth{+1}\relax, + }} + +% \EscMintinline[options]{}{} +\def\EscMintinline{% + \FVExtraRobustCommand + \RobustEscMintinline + \FVExtraUnexpandedReadOArgMArgEscVArg} + +\NewExpandableDocumentCommand \FVExtraUnexpandedReadOArgMArgEscVArg { o m m } {% + \IfNoValueTF{#1} + {\FVExtraAlwaysUnexpanded + {\FVExtraUnexpandedReadOArgMArgEscVArg{#2}{#3}}} + {\FVExtraAlwaysUnexpanded + {\FVExtraUnexpandedReadOArgMArgEscVArg[#1]{#2}{#3}}}% +} + +\newrobustcmd\RobustEscMintinline[2][]{% + % similar to \mintinline + \begingroup + \setboolean{minted@isinline}{true}% + \minted@configlang{#2}% + \setkeys{minted@opt@cmd}{#1}% + \minted@fvset + \begingroup + \@ifnextchar\bgroup + {\FVExtraDetokenizeREscVArg{\minted@inline@iii}}% + {\PackageError{minted}% + {\string\EscMintinline\space delimiters must be paired curly braces in this context}% + {Delimit argument with curly braces}}} +\makeatother + +\newtcblisting{bashcode}{% + colframe=black!70, + width=\linewidth, + bashstyle, +} + +\newtcblisting{consoleoutput}{% + colback=black, + colupper=gray!50, + colframe=black!70, + listing engine=minted, + listing only, + minted style=monokai, + minted language=console, + size=fbox, + breakable, + enhanced, + minted options={ + autogobble=true, + breaklines=true, + breakbefore=., + numbersep=2mm, + }, + % width=80ex, +} + +\newtcblisting{cxxcode}[2][]{ + cxx, + title={#2}, + #1, +} + +\newtcbinputlisting{cxxfile}[2][]{% + cxx, + minted options app={ + fontsize=\small, + }, + listing file={#2}, + % width=80ex, + #1 +} + +\newcommand{\cxxinline}[1]{\EscMintinline{C++}{#1}} +\newcommand{\cmd}[1]{\EscMintinline[style=colorful]{console}{#1}} +% newmintinline[cmd]{console}{style=colorful,autogobble} +\newcommand{\code}[1]{\texttt{\bf #1}} + +\DeclareSIUnit\flop{FLOP} +\DeclareSIUnit\transfer{T} +\DeclareSIUnit\cycle{c} +\DeclareSIUnit\flops{\flop\per\second} +\DeclareSIUnit\chf{CHF} +\sisetup{per-mode=symbol} +\sisetup{exponent-product = \cdot} +\sisetup{group-separator={\mathrm{'}}} + +\definecolor{blue0}{HTML}{002255} +\definecolor{blue1}{HTML}{003380} +\definecolor{blue2}{HTML}{0044AA} +\definecolor{blue3}{HTML}{0055D4} +\definecolor{blue4}{HTML}{0066FF} +\definecolor{blue5}{HTML}{2A7FFF} +\definecolor{blue6}{HTML}{5599FF} +\definecolor{blue7}{HTML}{80B3FF} +\definecolor{blue8}{HTML}{AACCFF} +\definecolor{blue9}{HTML}{D5E5FF} + +\definecolor{yellowbrown0}{HTML}{554400} +\definecolor{yellowbrown1}{HTML}{806600} +\definecolor{yellowbrown2}{HTML}{AA8800} +\definecolor{yellowbrown3}{HTML}{D4AA00} +\definecolor{yellowbrown4}{HTML}{FFCC00} +\definecolor{yellowbrown5}{HTML}{FFD42A} +\definecolor{yellowbrown6}{HTML}{FFDD55} +\definecolor{yellowbrown7}{HTML}{FFE680} +\definecolor{yellowbrown8}{HTML}{FFEEAA} +\definecolor{yellowbrown9}{HTML}{FFF6D5} + +\definecolor{colShellBg}{HTML}{F5EDE4} +\definecolor{links}{HTML}{2A1B81} +\hypersetup{colorlinks,linkcolor=,urlcolor=links} + +\usefolder{scitas_theme} +\usetheme{scitas} + +\newcommand{\FIGREP}{figures} +\renewcommand{\arraystretch}{1.3} + +% Remove numbering from the ToC when it's spread on multiple frames +\setbeamertemplate{frametitle continuation}{} + +\title{{\huge Parallel Programming}\\Presentation of the exercises} +\author[N. Richart, E. Lanti]{Nicolas Richart \\ Emmanuel Lanti} +\date{\nth{14} - \nth{18} of November 2022} + +\begin{document} +\begin{frame}[plain] + \titlepage +\end{frame} + +\begin{frame}[t,fragile] + \frametitle{PI} + \framesubtitle{} + + \begin{itemize} + \item The goal of this exercise is to compute an approximate value of $\pi$ + \item To compute $\pi$, we will use two identities: + \begin{equation} + \label{eq:1} + \arctan(1) = \frac{\pi}{4} + \end{equation} + \begin{equation} + \label{eq:2} + \int_{0}^{x} \frac{1}{1+y^{2}} {\rm d}y = arctan(x) + \end{equation} + Then, it follows that + \begin{equation} + \label{eq:4} + \pi = 4 \int_{0}^{1} \frac{1}{1+x^{2}} {\rm d}x + \end{equation} + \item Using a Riemann sum, we can approximate the integral in Eq.\,\eqref{eq:2} + \begin{equation} + \label{eq:3} + \pi \approx \frac{4}{n}\sum_{i=0}^{n}\frac{1}{1+(i/n)^{2}} + \end{equation} + \end{itemize} +\end{frame} + +\begin{frame}[t,fragile] + \frametitle{Poisson} + \framesubtitle{} + + \begin{itemize} + \item Let us consider the following Poisson problem + \begin{equation} + \label{eq:5} + \left\{ \begin{array}{rcl} + \Delta u = f(x, y) & \text{in} & \Omega, \\ + u(x, y) = 0 & \text{on} & \partial\Omega. + \end{array}\right. + \end{equation} + \end{itemize} +\end{frame} + +\begin{frame}[t,fragile] + \frametitle{Poisson} + \framesubtitle{} + + \begin{itemize} + \item The 2D domain is uniformly discretized using $N+1$ points in each + direction: + \begin{equation} + \label{eq:6} + \left\{ \begin{array}{l} + (x_{i}, y_{j}), \\ + \{x_{i}\}, i = 1, ..., N+1, \\ + \{j_{i}\}, i = 1, ..., N+1. + \end{array}\right. + \end{equation} + The grid spacings are + $\Delta x = \Delta y = 1 / N$ (we assume domains of length one). + \item The Laplacian is approximated using second-order centered + finite-differences: + \begin{align*} + \Delta u(x, y) &= \frac{\partial^{2} u}{\partial x^{2}} + \frac{\partial^{2} u}{\partial y^{2}} \approx \frac{u_{i+1, j}- 2u_{i,j} + u_{i-1, j}}{\Delta x^{2}} + \frac{u_{i, j+1}- 2u_{i,j} + u_{i, j-1}}{\Delta y^{2}}\\ + &= \frac{u_{i+1, j} + u_{i-1, j} + u_{i, j+1} + u_{i, j-1} - 4u_{i, j}}{\Delta x^{2}} + \end{align*} + \end{itemize} +\end{frame} + +\begin{frame}[t, fragile] + \frametitle{Poisson} + \framesubtitle{} + + \begin{itemize} + \item This defines a 4-point stencil + \end{itemize} + \vspace{4cm} + \begin{itemize} + \item The system of linear equations is solved using the Jacobi method + \item Iterations are done until the error is lower than a prescribed tolerance + \end{itemize} + + \addimage[width=3cm]{figures/stencil}{6.5cm}{3.8cm} +\end{frame} + +\begin{frame}[t,fragile] + \frametitle{Poisson} + \framesubtitle{} + + \begin{itemize} + \item Let solve the Poisson problem with + \begin{equation} + u(x, y) = 0\label{eq:8} + \end{equation} + on the boundaries and + \begin{equation} + f = -200\pi^{2}\sin(10\pi x)\sin(10\pi y)\label{eq:7} + \end{equation} + \end{itemize} + + \addimage[width=6.5cm]{figures/poisson}{4.5cm}{0.5cm} +\end{frame} + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-command-extra-options: "-shell-escape" +%%% TeX-master: t +%%% End: diff --git a/exercises_presentation/scitas_theme/beamercolorthemescitas.sty b/exercises_presentation/scitas_theme/beamercolorthemescitas.sty new file mode 100644 index 0000000..608649b --- /dev/null +++ b/exercises_presentation/scitas_theme/beamercolorthemescitas.sty @@ -0,0 +1,21 @@ +\mode + +\definecolor{greyEPFL}{rgb}{0.2549, 0.2352, 0.2274} +\definecolor{redEPFL}{rgb}{0.8867,0.0235,0.0745} +\definecolor{orangeEPFL}{RGB}{243,152,105} +\definecolor{greenEPFL}{RGB}{194,221,176} +\definecolor{acierEPFL}{RGB}{79,143,204} +\definecolor{carotteEPFL}{RGB}{236,102,8} +\definecolor{zinzolinEPFL}{RGB}{92,36,131} + +% Settings +\setbeamercolor*{title page header}{fg=white} +\setbeamercolor*{author}{fg=white} +\setbeamercolor*{date}{fg=white} +\setbeamercolor*{normal text}{fg=greyEPFL} +\setbeamercolor{section in toc}{fg=greyEPFL} +\setbeamercolor{subsection in toc}{fg=greyEPFL} +\setbeamercolor{subsubsection in toc}{fg=greyEPFL} + +\mode + diff --git a/exercises_presentation/scitas_theme/beamerinnerthemescitas.sty b/exercises_presentation/scitas_theme/beamerinnerthemescitas.sty new file mode 100644 index 0000000..68051fe --- /dev/null +++ b/exercises_presentation/scitas_theme/beamerinnerthemescitas.sty @@ -0,0 +1,82 @@ +\mode + + +\setbeamertemplate{background}{ + \begin{tikzpicture}[overlay,remember picture] + \begin{scope}[shift={(current page.south west)}] + \ifnum\thepage=1\relax% + % EPFL logo + \node[anchor=west, inner sep=0pt] at (0.5cm, 8.5cm) {\includegraphics[width=2cm]{scitas_theme/figures/EPFL_logo.pdf}}; + % SCITAS logo + \node[anchor=west, inner sep=0pt] at (0.2cm, 0.5cm) {\includegraphics[width=1cm]{scitas_theme/figures/SCITAS_logo.png}}; + % SCITAS background + \node[anchor=south west, inner sep=0pt] at (3cm, 1.7cm) {\includegraphics[width=13cm]{scitas_theme/figures/SCITAS.jpg}}; + % Draw red rectangle + \fill[color=redEPFL, anchor=south west] (3cm, 0cm) rectangle (17cm,3cm); + \else + % EPFL logo + \node[anchor=west, inner sep=0pt] at (0.2cm, 8.5cm) {\includegraphics[width=1.6cm]{scitas_theme/figures/EPFL_logo.pdf}}; + % SCITAS logo + \node[anchor=west, inner sep=0pt] at (0.2cm, 0.25cm) {\includegraphics[width=0.8cm]{scitas_theme/figures/SCITAS_logo.png}}; + \fi + \end{scope} + \end{tikzpicture} +} + +% Title page +\defbeamertemplate*{title page}{scitas}[1][] +{ + \vskip6.0cm% + \begin{beamercolorbox}[wd=15.5cm,leftskip=3cm,sep=0pt,#1]{title page header} + \usebeamerfont{title}\textbf{\inserttitle}\par% + \end{beamercolorbox}% + \vskip0.5cm% + \begin{beamercolorbox}[wd=12cm,leftskip=3.0cm,sep=0pt,#1]{author} + \usebeamerfont{author}\textbf{\insertauthor}% + \end{beamercolorbox} + \vskip0.0cm% + \begin{beamercolorbox}[wd=12cm,leftskip=3.0cm,sep=0pt,#1]{date} + \usebeamerfont{author}\scriptsize\insertdate% + \end{beamercolorbox} + \vskip0.0cm% + \begin{beamercolorbox}[wd=12cm,leftskip=3.0cm,sep=0pt,#1]{date} + \usebeamerfont{author}\scriptsize\insertinstitute% + \end{beamercolorbox} + \vfill +} + +\setbeamertemplate{footline} +{ + \leavevmode% + \hbox{% + \begin{beamercolorbox}[wd=.33\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}% + \end{beamercolorbox}% + \begin{beamercolorbox}[wd=.33\paperwidth,ht=2.25ex,dp=1ex,center] {author in head/foot}% + \usebeamerfont{author in head/foot}\textcolor{greyEPFL!60}{\insertshortauthor} + \end{beamercolorbox}% + \begin{beamercolorbox}[wd=.33\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}% + \textcolor{greyEPFL!60}{\insertframenumber{} / \inserttotalframenumber}\hspace*{2ex} + \end{beamercolorbox}}% + \vskip0.1cm% +} + +\setbeamertemplate{itemize item}{% + \begin{tikzpicture} + \fill[color=redEPFL, anchor=south west, transform canvas={xshift=1mm,yshift=0.3mm}] (0,0) rectangle (0.1633,0.14); + \end{tikzpicture} +} + +\setbeamertemplate{itemize subitem}{\color{redEPFL}$\blacktriangleright$} +\setbeamertemplate{itemize subsubitem}{\color{redEPFL}$\bullet$} + +\setbeamertemplate{section in toc}{% + {% + \begin{tikzpicture} + \fill[color=redEPFL, anchor=south west, transform canvas={xshift=1mm,yshift=0.3mm}] (0,0) rectangle (0.1633,0.14); + \end{tikzpicture} + }% + ~\inserttocsection} + +\setbeamertemplate{subsection in toc}{\hspace{1.2em}{\color{redEPFL}$\blacktriangleright$}~\inserttocsubsection\par} + +\mode diff --git a/exercises_presentation/scitas_theme/beamerouterthemescitas.sty b/exercises_presentation/scitas_theme/beamerouterthemescitas.sty new file mode 100644 index 0000000..a293eb1 --- /dev/null +++ b/exercises_presentation/scitas_theme/beamerouterthemescitas.sty @@ -0,0 +1,33 @@ +\mode +% Frame title +\defbeamertemplate*{frametitle}{top box color}[1][greyEPFL] +{ + \begin{beamercolorbox}[wd=\paperwidth,ht=1.2cm]{frametitle} + \begin{tikzpicture}[overlay,remember picture] + \begin{scope}[shift={(current page.south west)}] + % Draw grey rectangle + \fill[color=#1, anchor=south west] (2cm, 8cm) rectangle (17cm,9cm); + \node[anchor=west, white,font=\large] at (2cm, 8.75cm){\textbf{\insertframetitle}}; + \node[anchor=west, white,font=\large] at (2cm, 8.25cm){\small\insertframesubtitle}; + \end{scope} + \end{tikzpicture} +\end{beamercolorbox} +} +\setbeamersize{text margin left=18mm,text margin right=30mm} + +% The following is to define an ``exercise'' template for the frames +% It will change the color of the header to redEPFL + +% Set the default behavior for each new slide +\BeforeBeginEnvironment{frame}{% + \setbeamertemplate{frametitle}[top box color]% +} + +% Define label for the \begin{frame}[