%% Chapter 1
%
\chapter{BREAK: Expansion Sets of Words} % Chapter title
%
\label{ch:expand} % For referencing the chapter elsewhere, use \autoref{ch:name}
%
A typical text-based search engine system tokenizes queries and documents into words and uses heuristics to return a ranked list of relevant documents to the query.
This analogy can be extended towards string-related operations, where instead of dividing a sentence into words, one could divide a string into small chunks.

The \textit{k-grams} splitting technique illustrates the trivial chunking.
The word \textit{pizza} is split with $k = 2$ as: $\left\lbrace \langle \textit{s} \rangle \textit{p, pi, iz, zz, za, a} \langle / \textit{s} \rangle \right\rbrace$.
Here, $\langle \textit{s} \rangle$ is the start token and $\langle / \textit{s} \rangle$ is the stop token.
For the sake of the simplicity, we have ignored terminal tokens in the k-gram splits.
Hence, the split set looks like: $\left\lbrace \textit{p, pi, iz, zz, za, a} \right\rbrace$.
We would label this approach as BREAK-0 because it splits the words into smaller $k$-grams without any sequential information.

\section{BREAK-1: Sequencing from 1 End}
We argue that BREAK-0 could lead to an extremely generalized matching of tokens since an expansion set could be visualized a bag-of-words method.
Thus, we propose a positional k-gram splitting technique, BREAK-1 which introduces position number in the splits to incorporate the notion of the sequence of the tokens in the word.
For example, the word \textit{pizza} could be position-wise split with $k = 2$ as: $\left\lbrace \textit{1p, 2pi, 3iz, 4zz, 5za, 6a} \right\rbrace$.
Thus, the member \textit{4zz} simply means that it is the fourth member of the set.
The motivation behind this tweak is that it gives us a rough amount of sequential-insight for spelling splits when they are used in probabilistic retrieval ranking functions.

\section{BREAK-2: Sequencing from 2 Ends}
The main disadvantage of the BREAK-1 is that some misspellings can easily disturb the order of the set which leads to low similarity.
For example, if the misspelling (query) is \textit{ppizza}, the split set would be $\left\lbrace \textit{1p, 2pp, 3pi, 4iz, 5zz, 6za, 7a} \right\rbrace$.
The order of the members after \textit{2pp} is misplaced, thus this would lead to low similarity with the correct spelling (document) $\left\lbrace \textit{1p, 2pi, 3iz, 4zz, 5za, 6a} \right\rbrace$.
Only $\left\lbrace \textit{1p} \right\rbrace$ is common between correct and incorrect spell-splits.
Hence, we propose BREAK-2, a split algorithm which is robust against such displacements.

We attach position number to the left if the numbering begins from the start, and to the right if the numbering begins from the end.
Then the smallest position number would be selected between the two position numbers.
If the position numbers are equal, then we select the left position number as a convention.
Figure \ref{algo} gives an exemplification of this algorithm illustrated with splits of \textit{pizza} and \textit{hearts}.

%\begin{figure}[h]
%	\centering
%	\includegraphics[width=0.48\textwidth]{alg.pdf}
%	\caption{The process of BREAK-2. On the left, algorithm slices pizza into pieces. The output set would be $\left\lbrace \textit{1p, 2pi, 3iz, zz3, za2, a1} \right\rbrace$. On the right, algorithm breaks hearts into pieces. The output set would be $\left\lbrace \textit{1h, 2he, 3ea, 4ar, rt3, ts2, s1} \right\rbrace$. }
%	\label{algo}
%\end{figure}
If the misspelling is \textit{ppizza}, the double-end split set would be $\left\lbrace \textit{1p, 2pp, 3pi, 4iz, zz3, za2, a1} \right\rbrace$.
Thus it gives higher similarity with the correct spelling (document) as compared to positional split, as the set members $\left\lbrace \textit{1p, zz3, za2, a1} \right\rbrace$ would be matched.

\section{BREAK-Off: Sequencing with Offsets}
We propose another variant, BREAK-\textit{X}-Off, which introduces offsets in the split-sets.
(Here \textit{X} stands for the BREAK variant number used).
Let the BREAK-1 of pizza be $S_0 = \left\lbrace \textit{1p, 2pi, 3iz, 4zz, 5za, 6a} \right\rbrace$, which has no offsets.
An offset of $1$ would mean the counts would be displaced by 1, which is, $S_1 = \left\lbrace \textit{2p, 3pi, 4iz, 5zz, 6za, 7a} \right\rbrace$.
An offset of -1 would mean the counts would be displaced by -1, which is, $S_{-1} = \left\lbrace \textit{0p, 1pi, 2iz, 3zz, 4za, 5a} \right\rbrace$.
Now the complete split-up would be, thus , $S = S_{-1} \cup S_0 \cup S_1$.
Similarly, offsets can be applied to the BREAK-2 splits too.

The motivation behind BREAK-\textit{X}-Off is that inclusion of offsets would be robust against the incorrect query provided.
For example, a spelling typographical error could have been caused by the insertion or deletion of the letter.
Such insertions and deletions would displace the position sequences for the chunks.
So the key here is to already index these possible errors, like for insertion, it would have an offset of 1 and for deletion, it would have an offset of -1.

\section{BREAK-n: Sequential Splits for Longer Terms}

The main drawback of BREAK-2 algorithm is that the double-ended counts would be inefficient for the longer words.
With elongation, the advantage of having two extremities would fade away, causing a similar drawback like BREAK-1.
This is undesirable for the non-natural language processing tasks like genome sequence analysis where a typical genetic sequence can be of thousands of base-pairs long.
In this section, we tackle this problem by proposing BREAK-n algorithm, which would generalize BREAK-2 and workaround for longer words.
\subsection{Anchoring}
Here, we introduce the notion of the anchor points.
Notice that in BREAK-2 algorithm, we numbered the terms from two extremities.
Now, instead of 2 extremities here, we number the terms relative to the $n$ extremities or \textit{anchor points}.
For a sequence with a length $l$, divided into $k$-grams and $n$ anchor points, the position of the $i^{th}$ anchor point ($pos_i$) is given by,
\begin{align}
	\label{anchor}
	pos_i = 1 + \frac{(i - 1)(l + k - 1)}{n - 1}
\end{align}
Each anchor point $i$ would have a corresponding vector $t_{e,i}$ having $j$ entries.
Every $t_{e, ij}$ entry will have information about the distance between $i^{th}$ anchor point and their position $j$.
Or simply,
\begin{align}
	\label{relative}
	t_{e, ij} = |pos_i - j|
\end{align}
Here $e$ stands for entity which can be either a document $d$, or query $q$.
%We have illustrated a basic example in figure \ref{breakn} to exemplify this process.
%\begin{figure}[h]
%	\centering
%	\includegraphics[width=0.5\textwidth]{break-n.pdf}
%	\caption{In this example, the words \textit{piza} and \textit{pizza} are given as $q$ and $d$ respectively, split into 2-grams. If we chose 2 anchor points, the position according to equation \ref{anchor} would be at the first and the last (which are shown in arrows). Now we fill every $t_{e, ij}$ entry by calculating relative distance given in equation \ref{relative}.}
%	\label{breakn}
%\end{figure}

\subsection{Redefining Intersection}
Comparing the analogy from BREAK-2, we impose conditional intersection here.
A term $t_q$ in query and $t_d$ in document is said to be \textit{completely intersected} if any of their relative positions from anchor points are same.
To achieve this, we would investigate their column vectors at the matched positions.

Let the matching position for $t_q$ and $t_d$ be $p_1$ and $p_2$, respectively.
We would extract $p_1$ and $p_2$ column vectors and check their corresponding indices for every anchor point.
Afterwards, we extract $p_1$ and $p_2$ column vectors, $t_{q, :p_1}$ and $t_{d, :p_2}$ respectively.
Then we would see if any of their corresponding indices are same.
If this happens, we say that they are \textit{completely intersected}.
In other words, any of the cells in the absolute difference between $t_{q, :p_1}$ and $t_{d, :p_2}$ should be 0.
Mathematically,
\begin{align}
	\label{intersect}
	\prod_{i = 1}^{n} |t_{q, ip_1} - t_{d, ip_2}| = 0
\end{align}
where $n$ is the length of the column vector (number of the anchor points).
If the resulting product around 0 is achieved, we would say that the term intersects completely between query and document.

Continuing the example from figure \ref{breakn}, let's assess the term \textit{za} which is common between $t_q$ ($p_1 = 3$) and $t_d$ ($p_2 = 4$).
The $t_q$ column vector at $p_1 = 3$ is $t_{q, :3} = [3 \; 1]^T$ and for $t_d$ at $p_2 = 4$ is $t_{d, :4} = [4 \; 1]^T$.
Applying the equation \ref{intersect}, we get $\left(|3 - 4|\right) \left(|1 - 1|\right) = 0$, which means the term \textit{za} is completely intersected.
Analytically, this makes sense because position of \textit{za} from last is same in the two entities, and hence it should be completely intersected.
Although here we have shown the example of BREAK-n for a small word with two anchor points but BREAK-n can be logically extended to longer words with more anchor points.

\section{Combining BREAK with Ranking Functions}
Before indexing the documents, the dataset must be split according to the desired BREAK variant.
For the usage of BREAK-n, note that one can store the positional vectors while indexing the corresponding term, or generate the vector directly during evaluation.
This choice highly depends on the time-space tradeoff.
However, in our experiments we have stored the vectors during indexing, prioritizing faster evaluation.

We have also combined length penalization heuristics (BREAK-\textit{X}-L) with the probabilistic retrieval functions.
The role of these heuristics is to reward the documents which are in closer to the length of the query.
This can be useful in the spell correction and cognate detection experiments as misspellings do not much absolute length difference with the correct spelled ones.
These length penalization heuristics can replace the conventional length normalization heuristics which are used in BM25 and Dirichlet.
In addition, we have also introduced graphical error models (BREAK-\textit{X}-G) to analyze the confusion matrix generated during experimentation.
The motivation behind this creation of graphical error model is to aid the identification and suggestion of solutions to the most probabilistic errors.

%Any misspelled word given as a query and correctly spelled word as a document could make the use of the expansion sets.
%The word can be broken down into smaller constituents and are indexed accordingly.
%When the misspelling occurs, it is taken as a query, broken down into chunks and searched on the inverted index.
%In this section, we discuss some ways to expand the word into smaller chunks.
%
%\section{Basic k-gram splits}
%This is a well-known way to split the word which is used for spelling correction \cite{Manning:2008:IIR:1394399}.
%The word is split up into \textit{k-grams}.
%For example, the word \textit{pizza} is split with $k = 2$ as: $\left\lbrace \langle \textit{s} \rangle \textit{p, pi, iz, zz, za, a} \langle / \textit{s} \rangle \right\rbrace$.
%Here, $\langle \textit{s} \rangle$ is the start token and $\langle / \textit{s} \rangle$ is the stop token.
%For the sake of the simplicity, we have ignored tokens in the k-gram splits.
%Hence, the split set looks like: $\left\lbrace \textit{p, pi, iz, zz, za, a} \right\rbrace$.
%
%The other variants include incorporation of skip-grams \cite{jarvelin2007s}, probabilistic distance measures on k-grams \cite{harding1997probabilistic}, usage of similarity scores \cite{damashek1995gauging}, subsequences \cite{islam2009real}, noisy channel models and ranker systems \cite{gao2010large}.
%
%\section{Positional k-gram splits}
%We argue that basic k-gram splits could lead to extreme generalized matching of tokens, since an expansion set could be visualized a bag-of-words model.
%We introduce positions in the splits to incorporate the notion of sequence of the tokens in the word.
%For example, the word \textit{pizza} could be position-wise split with $k = 2$ as: $\left\lbrace \textit{1p, 2pi, 3iz, 4zz, 5za, 6a} \right\rbrace$.
%Thus, the member \textit{4zz} simply means that it is the fourth member of the set.
%The advantage of positional splits can be that it gives us some amount sequential-insight of spelling splits when they are used in probabilistic retrieval ranking functions.
%
%\section{Double-ended k-gram split:}
%The main disadvantage of the positional k-gram split is that any misspelling can easily disturb the order of the set which leads to low similarity.
%For example, if the misspelling (query) is \textit{ppizza}, the split set would be $\left\lbrace \textit{1p, 2pp, 3pi, 4iz, 5zz, 6za, 7a} \right\rbrace$.
%The order of the members after \textit{2pp} is misplaced, thus this would lead to low similarity with the correct spelling (document) $\left\lbrace \textit{1p, 2pi, 3iz, 4zz, 5za, 6a} \right\rbrace$.
%Only $\left\lbrace \textit{1p} \right\rbrace$ is common between correct and incorrect spell-splits.
%The goal here is to provide split algorithm which is robust against displacements.
%We introduce the double ended split algorithm, which depicts positions from the start as well the end of the spelling.
%We attach position number to the left if the numbering begins from the start, and to the right if the numbering begins from the end.
%Then the smallest position number would be selected between the two position numbers.
%If the position numbers are equal, then we select the left position number as a convention.
%Figure \ref{algo} gives a pictorial representation of this algorithm illustrated with splits of \textit{pizza} and \textit{hearts}.
%
%\begin{figure}[h]
%	\centering
%	\includegraphics[width=0.48\textwidth]{gfx/alg.pdf}
%	\caption{The process of double-ended split algorithm. On the left, algorithm slices pizza into pieces. The output set would be $\left\lbrace \textit{1p, 2pi, 3iz, zz3, za2, a1} \right\rbrace$. On the right, algorithm breaks hearts into pieces. The output set would be $\left\lbrace \textit{1h, 2he, 3ea, 4ar, rt3, ts2, s1} \right\rbrace$. }
%	\label{algo}
%\end{figure}
%If the misspelling is \textit{ppizza}, the double-end split set would be $\left\lbrace \textit{1p, 2pp, 3pi, 4iz, zz3, za2, a1} \right\rbrace$.
%Thus it gives higher similarity with the correct spelling (document) as compared to positional split, as the set members $\left\lbrace \textit{1p, zz3, za2, a1} \right\rbrace$ would be matched.
%
%\section{Positional splits with offsets:} Insertion and deletion of letters are fairly common as spelling errors.
%Insertion of an unnecessary letter displaces one position to the right.
%Similarly, deletion of the letter causes displacement of the position to the left.
%In order to introduce insight of displacements in the split sets, we incorporate positional offsets in the split sets.
%For insertion errors, positional offset of $1$ is included.
%This means we would add $1$ offset to every positional number.
%For example, the split set for \textit{pizza} which was originally $\left\lbrace \textit{1p, 2pi, 3iz, 4zz, 5za, 6a} \right\rbrace$, after adding positional offset of $1$ looks like: $\left\lbrace \textit{2p, 3pi, 4iz, 5zz, 6za, 7a} \right\rbrace$.
%Offset with double-ended split-set now looks like $\left\lbrace \textit{2p, 3pi, 4iz, zz4, za3, a2} \right\rbrace$.
%For deletion errors, positional offset of -1 is included.
%For example, the split set for \textit{pizza} after adding positional offset of -1 looks like: $\left\lbrace \textit{0p, 1pi, 2iz, 3zz, 4za, 5a} \right\rbrace$.
%Offset with double-ended split-set now looks like $\left\lbrace \textit{0p, 1pi, 2iz, zz2, za1, a0} \right\rbrace$.
%The complete split-set would include offsets of -1, 0 and 1.
%Thus, complete split-set of \textit{pizza} now looks like,
%\begin{equation*}
%	\begin{aligned}
%		&\lbrace \textit{0p, 1pi, 2iz, zz2, za1, a0, 1p, 2pi, 3iz,} \\
%		&\quad \textit{zz3, za2, a1, 2p, 3pi, 4iz, zz4, za3, a2} \rbrace
%	\end{aligned}
%\end{equation*}
%However, set members $\left\lbrace \textit{0p, a0, 2p, a2} \right\rbrace$ are unlikely to happen as the numbering always starts from 1.
%Hence we can ignore these members.
%The final set is now,
%\begin{equation*}
%	\begin{aligned}
%		C &= \lbrace \textit{1pi, 2iz, zz2, za1, 1p, 2pi, 3iz,} \\
%		&\quad \textit{zz3, za2, a1, 3pi, 4iz, zz4, za3} \rbrace
%	\end{aligned}
%\end{equation*}
%where $C$ is the correct split-set.
%
%Let the misspelling (query) be entered as \textit{piza}. The $I$, incorrect split-set by this method would be:
%\begin{equation*}
%	\begin{aligned}
%		I &= \lbrace \textit{1pi, 2iz, za1, 1p, 2pi,} \\
%		&\quad \textit{3iz, za2, a1, 3pi, 4iz, za3} \rbrace
%	\end{aligned}
%\end{equation*}
%Then the match $C \cap I$ is,
%\begin{equation*}
%	\begin{aligned}
%		C \cap I &= \lbrace \textit{1pi, 2iz, za1, 1p, 2pi,} \\
%		&\quad \textit{3iz, za2, a1, 3pi, 4iz, za3} \rbrace
%	\end{aligned}
%\end{equation*}
%Thus this method received more number of term matches, $ | C  \cap I | $ than any other methods. Similarly this method can be visualized for other types of spelling errors like insertion of letters.


\documentclass[10pt]{beamer}

\usetheme[progressbar=frametitle]{metropolis}
\usepackage{appendixnumberbeamer}

\usepackage{booktabs}
\usepackage[scale=2]{ccicons}

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\graphicspath{{figures/}}
\usepackage{subcaption}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
% \usepackage[font=small,labelfont=bf,tableposition=top]{caption}

\usepackage{tcolorbox}

\usepackage{xspace}
\newcommand{\themename}{\textbf{\textsc{metropolis}}\xspace}

\usefonttheme{serif} % default family is serif

\definecolor{Red}{RGB}{227,0,27}
\definecolor{Orange}{RGB}{230,159,0}
\definecolor{Black}{RGB}{0,0,0}
\definecolor{Grey}{HTML}{595959}
%\definecolor{LightGrey}{RGB}{216,216,216}
\definecolor{LightGrey}{RGB}{240,240,240}
\definecolor{White}{RGB}{255,255,255}
\setbeamercolor{title}{fg=Black}
\setbeamercolor{progress bar}{fg=Red}
\setbeamercolor{progress bar in head/foot}{fg=Orange}
\setbeamercolor{normal text}{fg=Grey}
\setbeamercolor{frametitle}{fg=Black, bg=LightGrey}
\setbeamercolor{background canvas}{bg=White}

\title{A High Performance Implementation of the Escape Time Algorithm to generate the Mandelbrot Set}
\subtitle{Parallel and high-performance computing}
% \date{\today}
\date{June 29, 2017}
\author{Emanuele Bugliarello\\\texttt{emanuele.bugliarello@epfl.ch}\\(SC-MA4)\vfill}
\institute{\centering\includegraphics[height=1.2cm]{logo_EPFL.png}}
% \titlegraphic{\vfill\hfill\includegraphics[height=1.5cm]{logo_EPFL.png}}
% \titlegraphic{\includegraphics[height=1.2cm]{logo_EPFL.png}\hfill\includegraphics[height=1.2cm]{logo_SCITAS.png}}

\begin{document}

\maketitle

\begin{frame}{Table of contents}
  \setbeamertemplate{section in toc}[ball unnumbered]
  \tableofcontents[hideallsubsections]
\end{frame}

% -------------------------------------------------------
% -------------------------------------------------------

\section{Scientific Background}

\begin{frame}[fragile]{Definition}

The Mandelbrot set is the set of complex numbers $c$ for which the function $f_{c}(z)=z^{2}+c$ does not diverge when iterated from $z=0$.

If we denote the Mandelbrot set by $M$, then by repeatedly applying the quadratic map
\[
\left\{
\begin{array}{ll}
z_0 = 0\\
z_{n+1} = z_n + c,
\end{array}
\right.
\]
$\forall$ complex number $c$, we have $c\in M\iff\limsup _{n\to \infty }|z_{n+1}|\leq 2$.

\end{frame}

\begin{frame}[fragile]{Generating Mandelbrot set images}

\begin{itemize}
	\item Sample complex numbers and iterate this function for each point $c$.
	If the function goes to infinity, the point belongs to the set.	\\[7pt]
	\item Each sampled point can be mapped on a $2D$ plane:
	\begin{itemize}
		\item[$\circ$] Treat its real and imaginary parts as image coordinates $(x+yi)$
		\item[$\circ$] Color this pixel according to how quickly $z_{n}^2 + c$ diverges
	\end{itemize}
\end{itemize}
\vfill
\begin{figure}[b]
	\vspace{-0.0cm}
	\centering
	\begin{subfigure}{.45\textwidth}
		\centering
		\includegraphics[width=.95\linewidth, clip, trim={3cm 0cm 2cm 0cm}]{red.pdf}
		\caption{Red-shaded}
		\label{fig:mandelbrot-red}
	\end{subfigure}%
	\begin{subfigure}{.45\textwidth}
		\centering
		\includegraphics[width=.95\linewidth, clip, trim={3cm 0cm 2cm 0cm}]{blue.pdf}
		\caption{Smooth, blue-shaded}
		\label{fig:mandelbrot-blue}
	\end{subfigure}
	\vspace{-0.5cm}
	\caption{Mandelbrot set drawings generated with our palettes.}
	\label{fig:both-mandelbrot}
\end{figure}

\end{frame}

\begin{frame}[fragile]{The Escape Time Algorithm}

\begin{algorithm}[H]
	\footnotesize
	\caption{Escape Time algorithm}\label{euclid}
	\begin{algorithmic}[1]
		%		\Procedure{}{}
		\For {each pixel (Px, Py) on the screen}
		\State $x_0 \gets$ scaled x coordinate of pixel
		\State $y_0 \gets$ scaled y coordinate of pixel
		\State $x \gets 0.0$
		\State $y \gets 0.0$
		\State $iteration \gets 0$
		\While {$(x\times x + y\times y < 2\times 2$  AND  $iteration < max\_iteration)$}
		\State $x_{temp} \gets x\times x - y\times y + x_0$
		\State $y \gets 2\times x\times y + y_0$
		\State $x \gets x_{temp}$
		\State $iteration \gets iteration + 1$
		\EndWhile
		\State $color \gets palette[iteration]$
		\State $plot(Px, Py, color)$
		\EndFor
		%		\EndProcedure
	\end{algorithmic}
\end{algorithm}
\vspace{-0.7cm}
{\footnotesize Where $z = x + iy$, $c = x_0 + iy_0$, $x = Re(z^2+c)$ and $y=Im(z^2+c)$.}

\underline{Embarrassingly parallel problem:} each pixel independent of any other.
\end{frame}

\section{Implementations}

\begin{frame}{Implementations overview}

Three main classes of implementations are developed:
\begin{itemize}
	\vspace{-0.2cm}
	\item Serial versions.
	\item GPU versions using the \texttt{CUDA} parallel computing platform.
	\item Hybrid versions using both \texttt{CUDA} and \texttt{MPI} (including \texttt{MPI-IO}).\\[20pt]
\end{itemize}

The application is coded in \texttt{C}.

Code fully debugged and profiled using \texttt{gdb} and \texttt{gprof}.\\
\texttt{Valgrind} used to make sure no memory leaks are possible.

\end{frame}

\begin{frame}{Serial Implementations (1)}

\begin{itemize}
	\item \textbf{naive}.
	\item \textbf{opti1:} Exploit symmetry with respect to the $x$ axis.
	\item \textbf{opti2:} Skip calculations for the points lying within the cardioid or in the period-2 bulb ($\approx34\%$ of the total area).
	\item \textbf{opti3:} Finer-grained optimizations: reduce to $3$ multiplications per loop (minimum) $\&$ use fast array indexing in plotting.
\end{itemize}

\begin{table}
	\vspace{-0.0cm}
	\begin{minipage}[b]{0.4\linewidth}
		\centering
		\frame{\includegraphics[width=0.62\textwidth]{bulbs.png}}
		\vspace{0.2cm}
		\captionof{figure}{Periods of hyperbolic components.} \label{fig:bulbs}
	\end{minipage}\hfill
	\begin{minipage}[b]{0.56\linewidth}
		\centering
		\scriptsize
		\begin{tabular}{|l|l|}
			\hline
			\textbf{Optimization level} & \textbf{Execution time [s]} \\ [0.2ex]
			\hline\hline
			\texttt{-O0} & 422.91 \\
			\texttt{-O1} & 230.99 \\
			\texttt{-O2} & 208.96 \\
			\texttt{-O3} & 208.49 \\
			\texttt{-O3 -ftree-vectorize} & 205.41 \\ [0.2ex]
			\hline
		\end{tabular}
		\vspace{0.2cm}
		\caption{Execution times of \texttt{opti3} ($368.64M$ pixels, max\_iteration=$10,000$) as a function of the optimization level.}
		\label{tab:opti-levels}
		\vspace{-0.2cm}
	\end{minipage}
\end{table}

\end{frame}

\begin{frame}{Serial Implementations (2)}

\begin{figure}
%	\vspace{-0.7cm}
%	\centering
	\begin{subfigure}{.6\textwidth}
		\centering
		\hspace{-2cm}
		\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{serial-optis-px.pdf}
		\caption{}
		\label{fig:serial-optis-px}
	\end{subfigure}%
	\begin{subfigure}{.6\textwidth}
		\centering
		\hspace{-2.5cm}
		\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{serial-optis-maxiter.pdf}
		\caption{}
		\label{fig:serial-optis-maxiter}
	\end{subfigure}
	\vspace{-0.4cm}
	\caption{Time to solution for the different serial implementations with respect to (a) the number of pixels (max\_iteration=10,000) and (b) max\_iteration (368,640,000 pixels).}
	\label{fig:serial-optis}
	%	\vspace{-0.2cm}
\end{figure}

\end{frame}

% -------------------------------------------------------
% -------------------------------------------------------

\section{Going Parallel}

\begin{frame}{CUDA Implementations (1)}

\begin{itemize}
	\item \textbf{opti3:} Parallelize escape time evaluation only.
		\begin{itemize}
			\item[$\circ$] Colors computed serially
			\item[$\circ$] $3$ matrices sent on the PCIe bus
		\end{itemize}
	\item \textbf{opti4:} All workload carried out by the GPU.
		\begin{itemize}
			\item[$\circ$] Only exchange RGB values of the bottom part on the PCIe bus
			\item[$\circ$] Use \textit{Constant memory} to store constant values on the GPU
			\item[$\circ$] Code split into serial (\texttt{.c}) $\&$ parallel (\texttt{.cu}) parts; needs C wrapper
		\end{itemize}
	\item \textbf{opti5:} Single-precision implementation of \texttt{opti4}.
		\begin{itemize}
			\item[$\circ$] Maximize instruction throughput
			\item[$\circ$] Cannot distinguish between double- and single-precision images
		\end{itemize}
\end{itemize}
Application profiled with \texttt{nvprof}: compute-bound.

\end{frame}

\begin{frame}{CUDA Implementations (2)}

\begin{figure}
	%	\vspace{-0.7cm}
	%	\centering
	\begin{subfigure}{.6\textwidth}
		\centering
		\hspace{-2cm}
		\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{cuda-optis-px.pdf}
		\caption{}
		\label{fig:cuda-optis-px}
	\end{subfigure}%
	\begin{subfigure}{.6\textwidth}
		\centering
		\hspace{-2.5cm}
		\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{cuda-optis-maxiter.pdf}
		\caption{}
		\label{fig:cuda-optis-maxiter}
	\end{subfigure}
	\vspace{-0.4cm}
	\caption{Time to solution for the CUDA implementations with respect to (a) the number of pixels (max\_iteration=10,000) and (b) max\_iteration (368,640,000 pixels) with block size $512\times1$.}
	\label{fig:cuda-optis}
	%	\vspace{-0.2cm}
\end{figure}

\end{frame}

\begin{frame}{CUDA \textit{block size} tuning for \texttt{opti5}}

Block size:
\begin{itemize}
	\vspace{-0.2cm}
	\item hyperparameter leading to performance improvements, increasing \textit{occupancy} $\left(\frac{active~warps}{maximum~active~warps}\right)$
	\item It depends on both the problem and the specifics of the GPU
\end{itemize}

\begin{table}[H]
	\vspace{-0.1cm}
	\footnotesize
	\hspace{-1.8cm}
	\begin{subtable}{.38\linewidth}
		\centering
		\begin{tabular}{|l|l|l|}
			\hline
			\textbf{Block size} & \multicolumn{2}{|c|}{\textbf{Occupancy [$\%$]}} \\
			\cline{2-3}
			& \texttt{2560x1440} & \texttt{25600x14400} \\ [0.2ex]
			\hline\hline
			\texttt{32x1} & 18.05 & 18.81 \\
			\texttt{64x1} & 25.41 & 32.65 \\
			\texttt{128x1} & 31.82 & 51.52 \\
			% \texttt{192x1} & 34.85 & 56.01 \\
			\texttt{256x1} & \textbf{36.15} & \textbf{58.80} \\
			% \texttt{384x1} & 35.62 & 57.30 \\
			\texttt{512x1} & 28.76 & 52.37 \\
			%			\texttt{768x1} & 13.79 & 37.59 \\
			\texttt{1024x1} & 8.39 & 25.50 \\
			\texttt{8x8} & 19.04 & 20.12 \\
			\texttt{16x16} & 26.91 & 25.93 \\
			\texttt{32x32} & 5.91 & 7.74 \\ [0.2ex]
			\hline
		\end{tabular}
	\end{subtable}%
	\hspace{1.8cm}
	\begin{subtable}{.38\linewidth}
		\centering
		\begin{tabular}{|l|l|l|}
			\hline
			\textbf{Block size} & \multicolumn{2}{|c|}{\textbf{Execution time [s]}} \\
			\cline{2-3}
			& \texttt{2560x1440} & \texttt{25600x14400} \\ [0.2ex]
			\hline\hline
			\texttt{32x1} & 2.53 & 79.61 \\
			\texttt{64x1} & 2.29 & 50.32 \\
			\texttt{128x1} & 2.10 & 37.52 \\
			% \texttt{192x1} & 2.05 & 36.56 \\
			\texttt{256x1} & \textbf{2.04} & \textbf{35.91} \\
			% \texttt{384x1} & 2.11 & 36.60 \\
			\texttt{512x1} & 2.17 & 37.69 \\
			%			\texttt{768x1} & 2.38 & 44.73 \\
			\texttt{1024x1} & 5.65 & 90.60 \\
			\texttt{8x8} & 4.09 & 237.72 \\
			\texttt{16x16} & 2.45 & 97.12 \\
			\texttt{32x32} & 7.48 & 270.24 \\ [0.2ex]
			\hline
		\end{tabular}
	\end{subtable}
	\caption{Occupancy and execution time for two image sizes as the block size varies for max\_iteration=$10,000$. Evaluated using \texttt{nvprof}.}
\end{table}

\end{frame}

\begin{frame}{Hybrid Implementations (1)}

	Distribute the computations over different CPUs and GPUs with \texttt{MPI}.
	\begin{itemize}
		\item Image split to the $2$ processors in a node, each uses $1$ GPU.
		\begin{itemize}
			\item[$\circ$] Non-blocking, point-to-point communications where rank $0$-processor receives the image parts out-of-order~\footnote{No \texttt{MPI\_Barrier()} used.\label{no_barrier}}
			\item[$\circ$] Parallel I/O
		\end{itemize}
		\item Image split to the $2$ processors in a node, each uses $2$ GPUs.\\
		Highest performance: all the CUDA functions are asynchronous~\footnote{No \texttt{\_\_syncthreads()} used.}
		\begin{itemize}
			\vspace{-0.5cm}
			\item[$\circ$] Non-blocking, point-to-point communications where rank $0$-processor receives the image parts out-of-order~\textsuperscript{\ref{no_barrier}}
			\item[$\circ$] Parallel I/O
		\end{itemize}
		\begin{figure}
%			\vspace{-0.4cm}
%			\hspace{2.5cm}
			\centering
			\includegraphics[width=.7\linewidth]{hybrid-split.pdf}
			\vspace{-0.2cm}
			\caption{Image split to CPUs (orange) and GPUs (orange or green).}
			\label{fig:hybrid-split}
		\end{figure}

	\end{itemize}

\end{frame}

\begin{frame}{Hybrid Implementations (2)}

	\begin{figure}
		%	\vspace{-0.7cm}
		%	\centering
		\begin{subfigure}{.6\textwidth}
			\centering
			\hspace{-2cm}
			\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{hybrid-optis-px.pdf}
			\caption{}
			\label{fig:hybrid-optis-px}
		\end{subfigure}%
		\begin{subfigure}{.6\textwidth}
			\centering
			\hspace{-2.5cm}
			\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{hybrid-optis-maxiter.pdf}
			\caption{}
			\label{fig:hybrid-optis-maxiter}
		\end{subfigure}
		\vspace{-0.4cm}
		\caption{Time to solution for the hybrid implementations with respect to (a) the number of pixels (max\_iteration=10,000) and (b) max\_iteration (368,640,000 pixels) with block size $256\times1$.}
		\label{fig:hybrid-optis}
		%	\vspace{-0.2cm}
	\end{figure}

\end{frame}

% -------------------------------------------------------
% -------------------------------------------------------

\section{Results}

\begin{frame}{Strong Scaling}

	\begin{figure}
		%	\vspace{-0.7cm}
		%	\centering
		\begin{subfigure}{.6\textwidth}
			\centering
			\hspace{-2cm}
			\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{strong-mpi.pdf}
%			\vspace{-0.2cm}
			\caption{}
			\label{fig:strong-mpi}
		\end{subfigure}%
		\begin{subfigure}{.6\textwidth}
			\centering
			\hspace{-2.5cm}
			\includegraphics[width=.98\linewidth, clip, trim={1.5cm 1cm 2.5cm 2cm}]{strong-tts.pdf}
%			\vspace{-0.2cm}
			\caption{}
			\label{fig:strong-tts}
		\end{subfigure}
		\vspace{-0.4cm}
		\caption{Strong scaling as (a) the speedup for an increasing number of GPUs (via \texttt{MPI}) and (b) the reduced time to solution of the same problem ($368.64M$-pixel image, max\_iteration=$10\times10^6$) for the different versions.}
		\label{fig:strong}
%		\vspace{-0.4cm}
	\end{figure}

\end{frame}

\begin{frame}{Weak Scaling}

	\begin{figure}
		%	\vspace{-0.7cm}
		\centering
		\includegraphics[width = 0.8\textwidth, clip, trim={1.5cm 1cm 2cm 2cm}]{weak.pdf}
		\caption{Weak scaling as a function of the problem size that can be solved in the same amount of time ($76~s$) by the different versions.}
		\label{fig:weak}
		%		\vspace{-0.4cm}
	\end{figure}

\end{frame}

% -------------------------------------------------------
% -------------------------------------------------------

\section{Conclusion}

\begin{frame}{Conclusion \& Future Work}
\textbf{Conclusion}
\begin{itemize}
	\vspace{-0.2cm}
	\item Implement and optimize \texttt{serial}, \texttt{CUDA} and \texttt{CUDA+MPI} applications
	\item Gain experience with \texttt{CUDA} and \texttt{MPI} in a supercomputer
	\item Acquire familiarity with profiling tools
	\item Investigate different technologies
	\begin{itemize}
		\item[$\circ$] Non-blocking communications and parallel I/O in \texttt{MPI}
		\item[$\circ$] Asynchronous functions in \texttt{CUDA}
	\end{itemize}
\end{itemize}

\textbf{Future Work}
\begin{itemize}
	\vspace{-0.2cm}
	\item Experiment with 2D grids
	\item Investigate the impact of external libraries
	\item Explore different algorithms
\end{itemize}
% errors -- bugs
% \vfill
\pause
%\begin{tcolorbox}
\fontfamily{qzc}\selectfont % TeX Gyre Schola (similar to Zapf Chancery)
\hfill
\huge
%\tcbox{
\alert{Thank you}
%\end{tcolorbox}

\end{frame}

\end{document}


%%% perfectcut.sty  documentation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Author: Guillaume Munch-Maccagnoni
%%% https://github.com/gadmm/perfectcut
%%%
%%% This work may be distributed and/or modified under the conditions of
%%% the LaTeX Project Public License, either version 1.3 of this license
%%% or (at your option) any later version. Refer to the README file.
%%%
\documentclass[12pt,a4paper,british]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{1}
\usepackage{babel}
\usepackage{array}
\usepackage{booktabs}
\usepackage{calc}
\usepackage{amsmath}
\usepackage[unicode=true]{hyperref}
\usepackage{perfectcut}
\usepackage{stix}
\renewcommand*\ttdefault{txtt}
\usepackage[oldstyle,lining,scale=0.97]{sourcesanspro}
\usepackage[protrusion=true,expansion=true,tracking=false,kerning=true,spacing=true]{microtype}

\begin{document}
\global\long\def\cut#1#2{\perfectcut{#1}{#2}}

\global\long\def\mt{\bar{\mu}}

\title{\texttt{perfectcut.sty} documentation}

\author{\noindent {\large{}Guillaume Munch-Maccagnoni}\thanks{\protect\href{https://github.com/gadmm/perfectcut}{https://github.com/gadmm/perfectcut}}}

\date{3rd September 2017}

\maketitle

\tableofcontents{}

\section{Use}

\paragraph{Original use}

This package supplies the following commands:

\begin{center}
\begin{tabular}{ll}
\toprule
Command & Produces\tabularnewline
\midrule
\texttt{\textbackslash perfectcut\{\#1\}\{\#2\}} & $\perfectcut{\#1}{\#2}$\tabularnewline
\texttt{\textbackslash perfectbra\{\#1\}} & $\perfectbra{\#1}$\tabularnewline
\texttt{\textbackslash perfectket\{\#1\}} & $\perfectket{\#1}$\tabularnewline
\bottomrule
\end{tabular}\quad{}%
\begin{tabular}{ll}
\toprule
Command & Produces\tabularnewline
\midrule
\texttt{\textbackslash perfectcase\{\#1\}} & $\perfectcase{\#1}{\#2}$\tabularnewline
\texttt{\textbackslash perfectbrackets\{\#1\}} & $\perfectbrackets{\#1}$\tabularnewline
\texttt{\textbackslash perfectparens\{\#1\}} & $\perfectparens{\#1}$\tabularnewline
\bottomrule
\end{tabular}
\par\end{center}

The effect of these commands is to let the delimiters grow according
to the number of nested \texttt{\textbackslash perfect}\texttt{\emph{command}}s
(regardless of the size of contents). The package is originally intended
for solving a notational issue regarding the representation of abstract-machine-like
calculi in proof theory and computer science.

\paragraph{General use}

The package also defines \texttt{\textbackslash perfectunary} and
\texttt{\textbackslash perfectbinary} for defining custom delimiters
that behave similarly to the above ones. These commands should be
considered when facing the need of nested delimiters that consistently
grow regardless of the contents. (See ``Advanced Use''.)

\section{Example}

\subsection{Using \texttt{perfectcut.sty}}

\global\long\def\cut#1#2{\cutprimitive{#1}{#2}}

\noindent \texttt{\footnotesize{}\textbackslash usepackage\{perfectcut\}}~\\
\texttt{\footnotesize{}\textbackslash let\textbackslash cut\textbackslash perfectcut}

\begin{center}
\fbox{\begin{minipage}[t]{0.8\columnwidth}%
The following states the idempotency of an adjunction:
\[
\cut t{\mt x.\cut{\mu\alpha.\cut ue}{e'}}=\cut{\mu\alpha.\cut t{\mt x.\cut ue}}{e'}
\]

The following states the commutativity of a strong monad:
\[
\cut t{\mt x.\cut u{\mt y.\cut ve}}=\cut u{\mt y.\cut t{\mt x.\cut ve}}
\]
Using \texttt{\textbackslash underline} to mark redexes:
\begin{align*}
 & \delta(V,x.y,x.y)\\
 & =\mu{\star}.\cut V{\perfectcase{\mt x.\underline{\cut y{\star}}}{\mt x.\underline{\cut y{\star}}}}\\
 & =\mu{\star}.\cut V{\underline{\perfectcase{\mt x.\cut{\iota_{1}(x)}{\mt z.\cut y{\star}}}{\mt x.\cut{\iota_{2}(x)}{\mt z.\cut y{\star}}}}}\\
 & =\mu{\star}.\cut V{\underline{\mt z.}\cut y{\star}}\\
 & =\mu{\star}.\cut y{\star}=y
\end{align*}
 %
\end{minipage}}
\par\end{center}

\subsection{Using \texttt{\textbackslash left}, \texttt{\textbackslash middle}
and \texttt{\textbackslash right} instead}

\global\long\def\fakecut#1#2{\left\langle #1\middle|\mkern-2mu  \middle|#2\right\rangle }

\noindent \texttt{\footnotesize{}\textbackslash renewcommand\{\textbackslash cut\}{[}2{]}\{\textbackslash left\textbackslash langle
\#1\textbackslash middle|\textbackslash mkern-2mu\textbackslash middle|\#2\textbackslash right\textbackslash rangle\}}

\begin{center}
\fbox{\parbox[t]{0.8\columnwidth}{%
The following states the idempotency of an adjunction:
\[
\fakecut t{\mt x.\fakecut{\mu\alpha.\fakecut ue}{e'}}=\fakecut{\mu\alpha.\fakecut t{\mt x.\fakecut ue}}{e'}
\]

The following states the commutativity of a strong monad:
\[
\fakecut t{\mt x.\fakecut u{\mt y.\fakecut ve}}=\fakecut u{\mt y.\fakecut t{\mt x.\fakecut ve}}
\]

Using \texttt{\textbackslash underline} to mark redexes:
\begin{align*}
 & \delta(V,x.y,x.y)\\
 & =\mu{\star}.\fakecut V{\left[\mt x.\underline{\fakecut y{\star}}\middle|\mt x.\underline{\fakecut y{\star}}\right]}\\
 & =\mu{\star}.\fakecut V{\underline{\left[\mt x.\fakecut{\iota_{1}(x)}{\mt z.\fakecut y{\star}}\middle|\mt x.\fakecut{\iota_{2}(x)}{\mt z.\fakecut y{\star}}\right]}}\\
 & =\mu{\star}.\fakecut V{\underline{\mt z.}\fakecut y{\star}}\\
 & =\mu{\star}.\fakecut y{\star}=y
\end{align*}
%
}}
\par\end{center}

As we can see, the legibility of the above rendering is hampered by
multiple issues: the delimiters grow inconsistently, vertical bars
have the wrong size, accents or underlines uselessly make the delimiters
grow, and the spacing could be improved. The package is designed to
fix these issues.

\section{Advanced use}

The package lets you define your own growing delimiters. Let us first
stress that the size of these delimiters is entirely determined by
the number of nestings and is insensitive to the size of the contents.
If you need the size of the contents to be taken into account then
it is probably sufficient to use \texttt{\textbackslash left} and
\texttt{\textbackslash right} while tweaking \texttt{\textbackslash delimitershortfall}
and \texttt{\textbackslash delimiterfactor}.

\subsection{Example}

The following displays a set $\{\#1\mid\#2\}$ with delimiters appropriately
sized if there are other \texttt{\textbackslash perfectcommands}
inside \texttt{\#1} and \texttt{\#2}.\medskip{}

\texttt{\footnotesize{}\textbackslash def\textbackslash Set\#1\#2\{\textbackslash perfectbinary\{IncreaseHeight\}\textbackslash\{|\textbackslash\}\{\#1\textbackslash mathrel\{\}\}\{\textbackslash mathrel\{\}\#2\}\}}{\footnotesize\par}

\texttt{\footnotesize{}\textbackslash{[}\textbackslash Set\{\textbackslash perfectparens\{a\}\}\{\textbackslash perfectparens\{b\}\}\textbackslash{]}}{\footnotesize\par}

\def\Set#1#2{\perfectbinary{IncreaseHeight}\{|\}{#1\mathrel{}}{\mathrel{}#2}}

\[
\fbox{\ensuremath{\Set{\perfectparens{a}}{\perfectparens{b}}}}
\]

\subsection{Custom delimiters}
\begin{description}
\item [{\texttt{\textbackslash perfectunary\#1\#2\#3\#4}}] Displays \texttt{\#2}
\texttt{\#4} \texttt{\#3} where \texttt{\#2} and \texttt{\#3} are
delimiters. The delimiters grow according to \texttt{\#1} which must
be one of \texttt{IncreaseHeight}, \texttt{CurrentHeight}, or \texttt{CurrentHeightPlusOne}.
\item [{\texttt{\textbackslash perfectbinary\#1\#2\#3\#4\#5\#6}}] Displays
\texttt{\#2} \texttt{\#5} \texttt{\#3} \texttt{\#6} \texttt{\#4} where
\texttt{\#2}, \texttt{\#3} and \texttt{\#4} are delimiters. The delimiters
grow according to \texttt{\#1} which must be one of \texttt{IncreaseHeight},
\texttt{CurrentHeight}, or \texttt{CurrentHeightPlusOne}.
\end{description}

\subsection{Stock delimiters}

The stock commands behave as follow:

\begin{center}
\begin{tabular}{>{\raggedright}p{11em}lll}
\toprule
Command & Produces & Growth & Inserts skips\tabularnewline
\midrule
\texttt{\textbackslash perfectcut\{\#1\}\{\#2\}} & $\perfectcut{\#1}{\#2}$ & \texttt{IncreaseHeight} & Yes\tabularnewline
\texttt{\textbackslash perfectbra\{\#1\}} & $\perfectbra{\#1}$ & \texttt{IncreaseHeight} & Yes\tabularnewline
\texttt{\textbackslash perfectket\{\#1\}} & $\perfectket{\#1}$ & \texttt{IncreaseHeight} & Yes\tabularnewline
\texttt{\textbackslash perfectcase\{\#1\}} & $\perfectcase{\#1}{\#2}$ & \texttt{CurrentHeightPlusOne} & Yes\tabularnewline
\texttt{\textbackslash perfectbrackets\{\#1\}} & $\perfectbrackets{\#1}$ & \texttt{CurrentHeightPlusOne} & Only inside\tabularnewline
\texttt{\textbackslash perfectparens\{\#1\}} & $\perfectparens{\#1}$ & \texttt{CurrentHeight} & Only inside\tabularnewline
\texttt{\textbackslash perfectunary\{\#1\}}~\\
\texttt{~\{\#2\}\{\#3\}\{\#4\}} & $\#2\,\#4\,\#3$ & \#1 & No\tabularnewline
\texttt{\textbackslash perfectbinary\{\#1\}}~\\
\texttt{~\{\#2\}\{\#3\}\{\#4\}\{\#5\}\{\#6\}} & $\#2\,\#5\,\#3\,\#6\,\#4$ & \#1 & No\tabularnewline
\bottomrule
\end{tabular}
\par\end{center}

\section{Options}

\subsection{Option \texttt{mathstyle}}

With this option, the command \texttt{\textbackslash currentmathstyle}
from the package \texttt{mathstyle} is used instead of the command
\texttt{\textbackslash ThisStyle} from the \texttt{scalerel} package.
The latter (default) uses \texttt{\textbackslash mathchoice}, and
in order to avoid an exponential time complexity in the number of
nestings, it is only called for the outermost command. Concretely,
with \texttt{mathstyle}, math style changes are taken into account
both inside and outside of \texttt{\textbackslash perfectcommands},
whereas without it, changes in math style are not obeyed inside a
command. Moreover, using the \texttt{mathstyle} option speeds up compilation.
The downside of using \texttt{mathstyle} is that it redefines many
standard math commands, and is therefore a source of incompatibilities,
notably with \texttt{xypic}.

\subsection{Option \texttt{realVert}}

With the option \texttt{realVert}, the double bars are obtained with
the \texttt{\textbackslash Vert} command. But without it, two \texttt{\textbackslash vert}
symbols are used and their spacing is controlled with  \texttt{\textbackslash cutinterbarskip}.
Also, if \texttt{realVert} is not activated, then a penalty (\texttt{binoppenalty})
is added, such that $\cut{\mu\alpha.\cut ab}{\mt x.\cut cd}$ splits
across lines.

\subsection{Option \texttt{fixxits}}

For some reason that the author was unable to identify, the vertical
alignment is wrong with the Opentype XITS math font with XeTeX. The
option \texttt{fixxits} fixes this behaviour.

\subsection{Customisation}

The following mu-skips can be redefined in your preamble:

\begin{center}
\begin{tabular}{ll}
\toprule
Command & Defines the spacing...\tabularnewline
\midrule
\texttt{\textbackslash cutbarskip=5.0mu plus 8mu minus 2.0mu} & around bars\tabularnewline
\texttt{\textbackslash cutangleskip=0.0mu plus 8mu minus 1.0mu} & around delimiters (inside)\tabularnewline
\texttt{\textbackslash cutangleouterskip=0.0mu plus 8mu minus 0mu} & around delimiters (outside)\tabularnewline
\texttt{\textbackslash cutinterbarskip=0.8mu plus 0mu minus 0mu} & between bars (excl. \texttt{realVert})\tabularnewline
\bottomrule
\end{tabular}
\par\end{center}

\noindent (1 mu equals $1/18$ of an em in the current math font.)

\section{Reimplementation of fixed-size delimiters}

In addition, I provide the following corrections and generalisations
of  \texttt{\textbackslash big},\texttt{\textbackslash bigg}, etc.
Why not using the latter? Because both the plain \TeX{} and the \texttt{amsmath}
versions can be incorrect when changing the math font, the font size,
the math style or \texttt{\textbackslash delimitershortfall}. Moreover,
Opentype math fonts sometimes offer more than five sizes. For this
package we need a robust solution.

\begin{center}
\begin{tabular}{lll}
\toprule
Command & Example & \tabularnewline
\midrule
\multicolumn{3}{l}{\emph{\#1-th size of delimiter \#2}}\tabularnewline
\texttt{\textbackslash nthleft\{\#1\}\{\#2\} } & \texttt{\textbackslash nthleft\{2\}(} & $\nthleft{2}($\tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash nthmiddle\{\#1\}\{\#2\}} & \texttt{\textbackslash nthmiddle\{2\}\textbackslash Vert} & $\nthmiddle{2}\Vert$\tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash nthright\{\#1\}\{\#2\}} & \texttt{\textbackslash nthright\{2\})} & $\nthright{2})$\tabularnewline\addlinespace[0.1em]
\multicolumn{1}{l}{\emph{delimiter \#2 of height at least \#1}} &  & \tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash lenleft\{\#1\}\{\#2\}}  & \texttt{\textbackslash lenleft\{3.2mm\}{[}} & $\lenleft{3mm}[$\tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash lenmiddle\{\#1\}\{\#2\}} & \texttt{\textbackslash lenmiddle\{3.2mm\}|} & $\lenmiddle{3mm}|$\tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash lenright\{\#1\}\{\#2\}} & \texttt{\textbackslash lenright\{3.2mm\}{]}} & $\lenright{3mm}]$\tabularnewline\addlinespace[0.1em]
\multicolumn{3}{l}{\emph{delimiter \#2 of height exactly \#1 obtained by scaling the
above one}}\tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash reallenleft\{\#1\}\{\#2\}}  & \texttt{\textbackslash reallenleft\{3.2mm\}{[}} & $\reallenleft{3mm}[$\tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash reallenmiddle\{\#1\}\{\#2\}} & \texttt{\textbackslash reallenmiddle\{3.2mm\}|} & $\reallenmiddle{3mm}|$\tabularnewline\addlinespace[0.1em]
\texttt{\textbackslash reallenright\{\#1\}\{\#2\}} & \texttt{\textbackslash reallenright\{3.2mm\}{]}} & $\reallenright{3mm}]$\tabularnewline
\bottomrule
\end{tabular}
\par\end{center}

\subsection{Example with \texttt{\textbackslash nthleft}}

\texttt{\footnotesize{}\textbackslash nrthleft0(\textbackslash nthleft1(\textbackslash nthleft2(\textbackslash nthleft3(\textbackslash nthleft4(\textbackslash nthleft5(\textbackslash nthleft6(}{\footnotesize\par}

\[
\nthleft0(\nthleft1(\nthleft2(\nthleft3(\nthleft4(\nthleft5(\nthleft6(
\]

\subsection{Example with \texttt{\textbackslash big},\texttt{\textbackslash Big},\texttt{\textbackslash bigg},\texttt{\textbackslash Bigg}}

\texttt{\footnotesize{}(\textbackslash big(\textbackslash Big(\textbackslash bigg(\textbackslash Bigg(}{\footnotesize\par}

\[
(\big(\Big(\bigg(\Bigg(
\]
The above uses the \texttt{\textbackslash big} commands from the
\texttt{amsmath} package. The \texttt{amsmath} package corrects issues
with the original \TeX{} commands, but I could still notice inconsistencies,
such as \texttt{\textbackslash big} starting at size 2, under some
font combinations. \texttt{\textbackslash nthleft}, \texttt{\textbackslash nthright}
and \texttt{\textbackslash nthmiddle} are implemented in a more robust
way.

\section{License}

This work may be distributed and/or modified under the conditions
of the \LaTeX{} Project Public License, either version 1.3 of this
license or (at your option) any later version. Refer to the \texttt{README}
file.
\end{document}


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage[plain]{algorithm}
\usepackage{hyperref}
\usepackage{algpseudocode}

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Assignment\ \#1}
\newcommand{\hmwkDueDate}{Due on 2nd September, 2018}
\newcommand{\hmwkClass}{Fluid Mechanics}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

%\pagebreak

\begin{homeworkProblem}
    The \textit{Knudsen Number} is given by,
    $$\text{Kn} = \frac{\lambda}{L} = \frac{k_B T}{\sqrt{2} \pi d^2 p L}$$
    where $L$ is the characteristic length scale, and $T$ and $p$ are the temperature and pressure respectively.

    We can take some approximations for the the variations of $T$ and $p$, but we note that data for the variation of $T$ and $p$ is also available publicly \url{http://www.hyvac.com/tech_support/atmosphere%20vs%20pressure%202.htm}.
    We import that data and use it to do our calculations. We also assume some standard values for all the other parameters.

    \begin{figure}[!h]
    	\centering
    	\includegraphics[scale=0.45]{knudsen.png}
    \end{figure}

    \end{homeworkProblem}

\begin{homeworkProblem}
	$$\dv{C}{\eta} = \kappa \exp({\frac{-\eta^2}{4D}})$$ where $\eta = x/\sqrt{t}$.
	Performing the indefinite integral and substituting for $\eta$, one gets,
	$$ C(\eta) = \sqrt{D\pi} \kappa \ \text{erf}\left(\frac{\eta}{2\sqrt{D}}\right) + \alpha = \sqrt{D\pi} \kappa \ \text{erf}\left(\frac{x}{2\sqrt{D}\sqrt{t}}\right) + \alpha$$
	where $\alpha$ is some integration constant. We now go ahead and impose boundary conditions
	\begin{itemize}
		\item The concentration at the flower $(x=0)$ is assumed to be a constant $C_0$ at all times. As erf$(0) = 0$, $\alpha=C_0$
		\item At $t=0$, any $x$ would have zero concentration. As erf$(x \rightarrow \infty) = 1$, We get the condition that $\sqrt{D\pi} \kappa + C_0 = 0$ ie. $\kappa = -C_0/\sqrt{D \pi}$
	\end{itemize}

	Therefore, the final solution is,
	$$C(x,t) = C_0\ \left[1 - \text{erf}\left(\frac{x}{2\sqrt{D}\sqrt{t}}\right)\right]$$

	The function is plotted below for different $t$ using standard value of diffusivity $D \approx 10^{-5} $ $m^2/s$,
	\begin{figure}[!h]
		\centering
		\includegraphics[scale=0.45]{q2.png}
	\end{figure}
\end{homeworkProblem}

\begin{homeworkProblem}
	\textbf{Part (a)}\\
	The continuity equation $(\div{\va{v}}=0)$ in cylindrical coordinates is given by,
	$$\frac{1}{\rho} \pdv{v_\rho}{\rho} + \frac{1}{\rho}\pdv{v_\theta}{\theta} + \pdv{v_z}{z} = 0$$

	For flows symmetric about the $\phi$ direction, this can be written as,
	$$\frac{1}{\rho} \pdv{v_\rho}{\rho} + \pdv{v_z}{z} = 0$$

	The stream function $\psi$ should be such that,
	$$d \psi = \pdv{\psi}{\rho} d\rho + \pdv{\psi}{z} d z = M d\rho + N d z \implies \pdv{M}{z} = \pdv{N}{\rho}$$

	Comparing the forms of the last two equations, one can infer,
	$$M = \pdv{\psi}{\rho} = \rho v_z \text{ and } N = \pdv{\psi}{z} = \rho v_\rho $$

	Therefore, the stream function $\psi$ is given by,
	$$\psi = \int \rho v_z d\rho + \int \rho v_\rho d z$$

	The streamlines for a cone are plotted in the figure below.
	\begin{figure}[!h]
		\centering
		\includegraphics[scale=0.1]{stream.jpg}
		\caption{Flow past moving cone, assuming slip}
	\end{figure}
	\\

	\textbf{Part (b)}\\
	The velocity fields at the respective locations of the stream functions as shown in the figure will be $v_1 = \curl{\va{\psi_1}}$ and $v_2 = \curl{\va{\psi_2}}$, where $\va{\psi_1} = (0,0,\psi_1)$ and $\va{\psi_2} = (0,0,\psi_2)$. The streamlines for this flow will meet somewhere in between (because there cannot be two directions of velocity at a single point). For example, such a flow can be generated by two moving infinite plates inclined at an acute angle, and having the no-slip boundary condition.
\end{homeworkProblem}

\begin{homeworkProblem}
	$$\grad{u} = e_{ij} + \Omega_{ij}$$
	We can do the above decomposition of $\grad{u}$ into a symmetric and antisymmetric tensor. \textbf{$\Omega_{ij}$ represents pure rotation}. The symmetric part can be written and the divergence of some $\phi$.

	Let the principle axes in the problem be $x$, $y$ and $z$ (different from the coordinate axes). For some constants $a,b,c$, $\phi$ can be written as (in three dimensions),
	\begin{flalign*}
	\phi &= \frac{1}{2}(ax^2 + by^2 + cz^2)\\
	&= \frac{1}{2}\left[\frac{a+b+c}{3}(x^2+y^2+z^2) +\frac{2a - b - c}{3} x^2 + \frac{2b - a - c}{3} y^2 + \frac{2c - b - a}{3} z^2 \right]\\
	&= \frac{1}{2}\left[\alpha(x^2+y^2+z^2) + \alpha_1 x^2 + \alpha_2 y^2 + \alpha_3 z^2 \right]
	\end{flalign*}

	We note that $\alpha_1+\alpha_2+\alpha_3=0$. Then,
	\begin{flalign*}
	\phi &= \frac{1}{2}\left[\alpha(x^2+y^2+z^2) + \alpha_1 x^2 + \alpha_2 y^2  -(\alpha_1 + \alpha_2) z^2 \right]\\
	&= \frac{1}{2}\left[\alpha(x^2+y^2+z^2) + \alpha_1 (x^2-z^2) + \alpha_2( y^2-z^2)\right]
	\end{flalign*}
	We see that the first term is symmetric in the coordinates, and hence we remark that it is the pure expansion/contraction term. Similarly, the other two terms are antisymmetric under exchange of coordinates, hence they are pure strain terms. One can make a rotation of coordinates such that $$x^2 - y^2 \rightarrow xy \text{ and } y^2 - z^2 \rightarrow yz$$

	One can now make the interpretation of the last two terms as shear strain terms in the rotated coordinates. \textbf{So, we have successfully decomposed the $e_{ij}$ into shear strain $+$ pure expansion/contraction.}
\end{homeworkProblem}
\end{document}