text:
\chapter{\iflanguage{ngerman}{Zukunft}{Future}}
\label{sec:future}
Knowing the current state of miniature robotic systems for medicine, a look into the future is interesting. Many science fiction movies and novels are showing their vision for the medicine of the future. The producers of Star Wars thought of a human like robot equipped with many different miniature tools. The robot is able to replace a hand with a robot hand or removing brain tumors (Fig. \ref{fig:medidroid}). Other novels had the vision of nanobots which are cycling through our bloodstreams. If they find damaged cells or other inner injuries and diseases they would heal or report those (Fig. \ref{fig:nanobot}).
\begin{figure}[H]
    \centering
    \begin{subfigure}[b]{0.2\textwidth}
        \includegraphics[width=\textwidth]{Figures/starrwars_medidroid.png}
        \caption{Medidroid from Star Wars \cite{medidroid}}
        \label{fig:medidroid}
    \end{subfigure}
    \qquad
    \qquad
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{Figures/nanobot.jpg}
        \caption{Nanobot moving through veins, image from the pharmaceutical press \cite{nanobot}}
        \label{fig:nanobot}
    \end{subfigure}
    \caption{Different kind of science fictional visions of the future of medicine robots}
    \label{fig:visions}
\end{figure}
Fully automated robotic systems are the future due the many advantages against other control systems. Current research are working on automating parts of the robotic system like detection of the tool tip or automated collision avoidance (Sec. \ref{sec:automaticoperation}). When most of the part systems are automated the researches will start to combine the different approaches to build a first fully automated miniature robotic system. A vision like the one of Star Wars is unlikely to come true, because researches are trying to remove restrictions of the human body, like that humans have only 2 hands to use tools. Current robot systems are missing the mobility of the human. That is a part of the Star Wars vision which could become reality. If the robot system would be mobile it could relocate itself to get a better position for reaching a certain area.\\
The earlier a disease is detected the better it can be treated. The best way to detect diseases like a tumor is when the exact corrupted cells are found. For this task a nanobot travelling our blood system like shown in figure \ref{fig:nanobot} is best suited. It would not look like in the picture because the vein system has a diameter of 15\textmu m to 10mm and grippers like in the picture are not possible on this scale. Currently, robot systems are used for automatic colonoscopy. The systems are less painful and also requires less experience from the doctor\cite{automatedColonoscopy}. Additionally, nanobots can be used for delivering drugs into the cells. This is a current research topic \cite{automatedDrugDelivery}. \\
The nanobots will not be made of conventional materials but of bio materials. For example it is made of harmless DNA of virus cells. Those nanobots can be used to detect and remove tumor cells \cite{nanobotsOfVirusDNA}. \\

ext: tex

max_stars_repo_name: JohannesHaering/ProseminarAusarbeitung

max_issues_repo_name: JohannesHaering/ProseminarAusarbeitung

max_forks_repo_name: JohannesHaering/ProseminarAusarbeitung


text:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CS624: Analysis of Algorithms
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/beacon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section*{Question 1}

Prove that if graph $G$ is connected, the breadth-first tree constructed by the $BFS(G, s)$ algorithm is a tree and contains all the nodes in the graph.

\subsection*{Solution}

Proof is given by induction on number of vertices $n(G)$ in a connected graph $G$.
\begin{itemize}\itemsep=0pt
  \item[] \textit{Base case:} In case $n(G) = 1$, the graph will contain only the root node.
BFS algorithm will begin by discovering node $s$ and immediately terminates by visiting it as $s$ has no children.
Therefore, the tree constructed by $BFS(G,s)$ will be a single node tree, containing vertex $s$ which shows both statements hold true.
  \item[] \textit{Inductive hypothesis:} Inductive hypothesis can now be formed as $BFS(G,s)$ will construct a tree containing all nodes, if $n(G)\leq k$ where $k \geq 1$.
  \item[] \textit{Induction step:} Objective is to prove $BFS(G',s)$ algorithm will produce a tree containing all nodes in case $n(G')=k+1$.

  Using the inductive hypothesis, graph $G'(V',E')$ is constructed by introducing a new vertex $v_{new}$ to the graph $G(V,E)$ where $n(G) = k$; i.e.
$V' = V \cup \{v_{new}\}$.
  Since $G'$ should be connected, $E'$ will include a non-empty set of new edges $E''$ that connect $v_{new}$ to other nodes; i.e. $E' = E \cup E''$.
For simplicity, suppose $V''$ will be the set of vertices $v_i$ such that $(v_i,v_{new})\in E''$.

  Suppose $v_i \in V''$ will be the first vertex visited at some step during $BFS(G,s)$ algorithm.
This means, $v_i$ will also be the first node visited at $BFS(G',s)$ algorithm.
Since $v_{new}$ is connected to $v_i$, definition of algorithm will enforce discovery of $v_i$, putting $v_i$ in the visiting queue and marking edge $(v_i,v_{new})$ as a tree edge.
Since $v_i$ can be placed in queue only once, further visits to vertices $v_j \in V''$ will not discover $v_{new}$.
This means that edge $(v_i,v_{new})$ would be the only edge added to the tree constructed by $BFS(G,s)$.
As no loop can be created by adding one edge to a tree from a new vertex, $G'$ is proved to be a tree.
Further, since $v_{new}$ is in queue, it will be visited at some point during $BFS(G',s)$ and will be including in the nodes of the tree constructed by $BFS(G',s)$.
\end{itemize}

max_stars_repo_name: ghorbanzade/beacon

max_issues_repo_name: ghorbanzade/beacon

max_forks_repo_name: ghorbanzade/beacon


text:
\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

%% Sets page size and margins
\usepackage[a4paper,top=3cm,bottom=3cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

%% Useful packages
\usepackage{graphicx}
\usepackage{url}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{physics}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{bm}

\numberwithin{equation}{subsection}
\newcommand{\mb}[1]{\mathbf{#1}}
\title{Surface Plasmonic Polaritons}
\author{Kosala Sananthana Herath}
\numberwithin{equation}{section}

\begin{document}

\maketitle

\section{Derivation of the Dispersion Equation}
\textit{Surface plasmon polaritons} (SPPs) are electromagnetic waves that travel along a metal–dielectric, practically in the infrared or visible-frequency. The term surface plasmon polariton explains that the wave involves both charge motion in the metal (\textit{surface plasmon}) and electromagnetic waves in the air or dielectric (\textit{polariton}).

Starting the SPPs in a metal–dielectric interface know as excitation. SPPs can be excited by both electrons and photons. Excitation by electrons is created by firing electrons into the bulk of a metal. As the electrons scatter, energy is transferred into the bulk plasma. The component of the scattering vector parallel to the surface results in the formation of a SPP. For a photon to excite an SPP, both must have the same frequency and momentum. However, for a given frequency, a free-space photon has less momentum than an SPP because the two have different dispersion relations. Nevertheless, coupling of photons into SPPs can be achieved using a coupling medium such as a prism or grating to match the photon and SPP wave vectors.
\begin{figure}[ht!]
  \centering
  \includegraphics{figures/fig1}
  \caption{The SPPs exist on the interface of two different materials. Our considering surface is positioned in on the $yz$-plane.}
  \label{fig1}
\end{figure}

Here we are goin to find electromagnetic wave solutions ($\vb{E}(x,y,z,t),\vb{H}(x,y,z,t)$) that can be exist on the metal–dielectric interface. We represent the electric field of the SPP using $\vb{E}$ and the magnetic field with $\vb{H}$. In this case, we hoping to find solutions with following properties:
\begin{itemize}
  \item Wave solutions propagte through the surface (we assume they propagate to $z$-direction) \\
  \begin{equation} \nonumber
    \vb{E} \approx e^{-i\omega t + ik_z z} \quad
    \text{and} \quad
    \vb{H} \approx e^{-i\omega t + ik_z z}.
  \end{equation}
  \item Wave solutions decay through the both mediums (in the perpendicular direction to the surface) \\
  \begin{equation} \nonumber
    \vb{E} \rightarrow 0 \quad
    \text{and} \quad
    \vb{H} \rightarrow 0 \quad
    \text{as} \quad
    x \rightarrow \pm \infty.
  \end{equation}
\end{itemize}

In this analysis we consider a two material interface as mentioned in Fig.~(\ref{fig1}). These materials have the permitivity values  $\varepsilon_1,\varepsilon_2$ respectively for the upper one and the lower one. Without loss of generality, we can assume that $|\vb{E}|$ and $|\vb{H}|$ are independent on $y$. Now we can find the solutions for $\vb{E}$ and $\vb{H}$ by defining them as following form
\begin{equation}
  \vb{E} (x,y,z,t) = \bm{\mathcal{E}}(x) e^{-i\omega t + ik_z z}
  \quad \text{and} \quad
  \vb{H} (x,y,z,t) = \bm{\mathcal{H}}(x) e^{-i\omega t + ik_z z}.
\end{equation}
\begin{figure}[ht!]
  \centering
  \includegraphics{figures/fig2}
  \caption{The SPPs exist on the interface of two different materials are consider to be have only the TM-polarization mode.}
  \label{fig2}
\end{figure}
Furthermore, we restrict our study on to the TM-polarization mode as given in the Fig.~(\ref{fig2}). That means, we can represent the magnitudes of electric field and magnetic field as components of cartesian coordinate system
\begin{equation}
  \bm{\mathcal{E}} = (\mathcal{E}_x,\mathcal{E}_y,\mathcal{E}_z)^T
  \quad \text{,} \quad
  \bm{\mathcal{H}} = (\mathcal{H}_x,\mathcal{H}_y,\mathcal{H}_z)^T,
\end{equation}
with
\begin{equation}
  \mathcal{E}_y = 0 \quad,\quad \mathcal{H}_x = 0
  \quad,\quad \mathcal{H}_x = 0,
\end{equation}
and this leads to
\begin{equation}
  \bm{\mathcal{E}}(x) = \Big(\mathcal{E}_x(x),0,\mathcal{E}_z(x)\Big)^T
  \quad \text{,} \quad
  \bm{\mathcal{H}}(x) = \Big(0,\mathcal{H}_y(x),0\Big)^T.
\end{equation}
Next, to calculate known paramters, we can use Maxwell's equations
\begin{equation}
  \curl{\vb{H}} = \pdv{\vb{D}}{t} \quad \text{with} \quad
  \vb{D} = \varepsilon \varepsilon_0 \vb{E}
\end{equation}
\begin{equation}
  \curl{\vb{E}} = \pdv{\vb{B}}{t}\quad \text{with} \quad
  \vb{B} = \mu \mu_0 \vb{H},
\end{equation}
where $\varepsilon_0$ permitivity of vaccum. This will leas us to follwing set of equations
\begin{equation}
  -ik_z \mathcal{H}_y = -i \varepsilon \varepsilon_0 \mathcal{E}_x,
\end{equation}
\begin{equation}
  \pdv{\mathcal{H}_y}{x} = -i \varepsilon \varepsilon_0 \omega \mathcal{E}_z,
\end{equation}
\begin{equation}
  ik_z \mathcal{E}_x - \pdv{\mathcal{E}_z}{x} =
  i \mu \mu_0 \omega \mathcal{H}_y,
\end{equation}
and using these equation we can derive that
\begin{equation}
  \mathcal{E}_x = \frac{k_z }{\varepsilon \varepsilon_0} \mathcal{H}_y,
\end{equation}
\begin{equation}
  \mathcal{E}_z = \frac{i}{\varepsilon \varepsilon_0 \omega}
  \pdv{\mathcal{H}_y}{x},
\end{equation}
\begin{equation}
  \pdv[2]{\mathcal{H}_y}{x} -
  - \kappa^2 \mathcal{H}_y = 0 \quad
  \text{where} \quad
  \kappa = \pm\Big[k_z^2 - \mu\varepsilon \frac{\omega^2}{c^2}\Big].
\end{equation}
These quations known as the \textit{Helmholz equations} and $c$ is the velocity of the light. We can identify the solution for above second order homogeneous differential equations as
\begin{equation}
  {\mathcal{H}_{y}}(x) = \mathcal{H} e^{-\kappa x}
\end{equation}
Here we only considered the positive solution for the $\kappa$ as we need only the decaying solution in outside of the interface and $\mathcal{H}$ is a unknown constant. Applying this solution into the two different mediums, we can find solutions for the electric and magneticfield in each medium as follows
\begin{itemize}
  \item Upper medium (Material1):\\
  \begin{equation}
    {\mathcal{H}_{1,y}}(x) = \mathcal{H}_1 e^{-\kappa_1 x} \quad,\quad
    {\mathcal{E}_{1,x}}(x) = \frac{k_z}{\varepsilon \varepsilon_0 \omega}\mathcal{H}_1 e^{-\kappa_1 x} \quad,\quad
    {\mathcal{E}_{1,z}}(x) = \frac{-i\kappa_1}{\varepsilon \varepsilon_0 \omega}\mathcal{H}_1 e^{-\kappa_1 x}.
    \end{equation}
    \item Lower medium (Material2):\\
    \begin{equation}
      {\mathcal{H}_{2,y}}(x) = \mathcal{H}_2 e^{\kappa_2 x} \quad,\quad
      {\mathcal{E}_{2,x}}(x) = \frac{k_z}{\varepsilon \varepsilon_0 \omega}\mathcal{H}_2 e^{\kappa_2 x} \quad,\quad
      {\mathcal{E}_{2,z}}(x) = \frac{i \kappa_2}{\varepsilon \varepsilon_0 \omega}\mathcal{H}_2 e^{\kappa_2 x}.
  \end{equation}
\end{itemize}
Here, $\mathcal{H}_1, \mathcal{H}_2$ are unknown constants which can be find by initial conditions and
\begin{equation}
  \kappa_1 = \sqrt{k_z^2 - \mu_1\varepsilon_1 \frac{\omega^2}{c^2}} \quad
  \text{,} \quad
  \kappa_2 = \sqrt{k_z^2 - \mu_2\varepsilon_2 \frac{\omega^2}{c^2}}.
\end{equation}

We can proceed further by considering the boundary condition of our system. Taking into account the boundary values we can identify the following identities
\begin{equation}
  {\mathcal{H}_{1,y}}(x =0) =  {\mathcal{H}_{2,y}}(x=0) ~\Longrightarrow~
  {\mathcal{H}_{1}} = {\mathcal{H}_{2}} = {\mathcal{H}},
\end{equation}
\begin{equation}
  {\mathcal{E}_{1,z}}(x =0) =  {\mathcal{E}_{2,z}}(x=0) ~\Longrightarrow~
  \frac{\kappa_1}{\varepsilon_1} = - \frac{\kappa_2}{\varepsilon_2}.
\end{equation}
Next, we assume these material are not magnatized materials ($\mu_1 =1,\mu_2 =1$), and this leads to
\begin{equation}
  \frac{\sqrt{k_z^2 - \varepsilon_1 {\omega^2}/{c^2}}}{\varepsilon_1} = - \frac{\sqrt{k_z^2 - \varepsilon_2 {\omega^2}/{c^2}}}{\varepsilon_2}
\end{equation}
Since the decaying parameters $\kappa_1,\kappa_2$ are defined as inverse of the penetration depth, we know these values should be get positive values. Therefore we can derive that one of the matrial's permitivity should be an negative value
\begin{equation}
  \varepsilon_1 \varepsilon_2 < 0.
\end{equation}
This implies that we can only find solutions for SSPs when one of the matrial should be a metal while onther one is a dielectric material. Therefore we can expext SPPs only on the metal-dielectric interfaces. Additionally, by solving above eqution we can identify the wave vector of the SPP's electric and magnetic field as
\begin{equation}
  k_z = \frac{\omega}{c} \sqrt{\frac{\varepsilon_1\varepsilon_2}{\varepsilon_1 + \varepsilon_2}}.
\end{equation}
This is known as the \textit{dispersion equation} of the consided the SPP.

\end{document}

max_stars_repo_name: KosalaHerath/surface-plasmon-polaritons

max_issues_repo_name: KosalaHerath/surface-plasmon-polaritons

max_forks_repo_name: KosalaHerath/surface-plasmon-polaritons


text:
\chapter{Statistical Analysis} \label{chapter:statistical-analysis}
Having prepared the bond data and matched it with the stocks, some statistical analysis can now be performed. In particular, we are interested in summary statistics of corporate bond returns \cite{q-factors}, as well as in the analysis of the lead-lag relationship of corporate bond and stock returns. For this, the returns themselves first need to be calculated from daily prices. Additionally, as the matching has so far only been done for static data, it needs to be extended to historical return data as well. All in all, the following procedure for the statistical analysis arises:
\begin{enumerate}
	\item calculate monthly bond returns
	\item match bond and equity returns
	\item calculate summary statistics
	\item analyze lead-lag relationship
\end{enumerate}

\section{Monthly Bond Returns}
In order to calculate the monthly bond returns, the following formula will be used: \\ \\
$R_{n} = \dfrac{P_{n}}{P_{n-1}}$, \\ \\ where $R_{n}$ stands for bond return in month $n$, and $P_{n}$ for the bond price on last day of month $n$.
To implement the formula in Stata, in the time series bond data only the last price of each bond for each month needs to be kept. The rest of the data can be dropped, as it is not relevant for the current analysis. The pricing parameter which will be used to calculate the returns is \textit{MPD}. It represents the Datastream Selected Default Price, and is the most reliable price parameter in the extracted database. Other price parameters, such as e.g. \textit{CP} (Clean Price), have significantly more missing values and are thus less suited for the purpose. Having kept the last monthly prices, a variable group consisting of the variables \textit{dscd} and \textit{month} has to be generated (\textit{egen} \textit{group} command). This group can then be set as a Stata time-series (\textit{tsset}). Based on this time-series, the monthly return variable can be generated with the introduced formula.

\section{Matching Bond and Equity Returns}
To match the bond and equity returns with each other, we can make use of the matching that we accomplished in chapter \ref{chapter:matching}. For this, we load the corporate bond returns, which we just calculated, into Stata. These bond returns can then be merged with the existing matching over the $bond\_dscd$ parameter, as shown in Fig. \ref{fig:matching-returns}.
\begin{figure}[h]
	\centering
	\includegraphics[trim={0 4.5cm 0 5cm},clip,width=1.0\linewidth]{figures/matching-returns.pdf}
	\caption{Matching of Bond and Equity Returns}
	\label{fig:matching-returns}
\end{figure}
After that, the resulting dataset has to be merged with the provided stock time series data, which also includes the required monthly stock returns. This merge should take place over the two parameters $stock\_dscd$ and $month$. This is because we want the bond and stock returns to be comparable for one and the same month later on. When executing the merges in Stata, keep in mind to make sure that the Datastream code parameter is named the same in the bond dataset and the matching (i.e. $bond\_dscd$), and similarly for the stocks and the matching (i.e. $stock\_dscd$). Otherwise, the matching will fail. The bonds-matching merge is performed on a M-to-1 relation, because multiple bonds can be mapped to the same equity over the issuing company. The merge with the equities is performed on a M-to-1 relation as well for the same reason. The resulting database builds the foundation for further statistical analysis.

\section{Summary Statistics} \label{section:summary-statistics}
Stata offers some very useful tools to determine the underlying distribution of the data, as well as to perform correlation and regression calculations. In order to obtain summary statistics separately for different bond groups, I split the bond returns dataset by geography and by credit rating.

\begin{figure}[h]
	\centering
	\includegraphics[trim={1cm 15.5cm 1cm 0},clip,width=1.0\linewidth]{figures/summary-stats-by-geo.pdf}
	\caption{Monthly Return Statistics by Bond Geography}
	\label{fig:summary-stats-by-geo}
\end{figure}

Fig. \ref{fig:summary-stats-by-geo} features monthly return statistics for:
\begin{itemize}
	\item The entire world
	\item North America region (NA), represented by USA and Canada
	\item Western Europe region (EUW), represented by Germany, France, UK, Italy, Ireland, Luxembourg, Netherlands, Spain, Portugal, Belgium, Austria, Switzerland, and Scandinavian countries
	\item Eastern Europe region (EUE), represented by Poland, Czech Republic, Bulgaria, Greece, Serbia, Croatia, Hungary, Montenegro, Ukraine, Turkey, and Georgia
	\item South America region, represented by Brazil, Argentina, Chile, Colombia, Uruguay, Paraguay, Panama, Peru, and Mexico (though NA)
	\item China
\end{itemize}
Note that the list is neither regionally exhaustive, nor is it 100\% geographically accurate. Its sole purpose is to gain a general idea of the distribution of corporate bond returns for countries with a similar financial structure.

Fig. \ref{fig:summary-stats-by-rating} features monthly return statistics for different credit ratings of corporate bonds. Please note that the number of bond-month observations for the single credit ratings does not sum up to to the number in the \textit{All} column. This is due to the procedure which was used to split the bonds up by their rating. To give an example, bonds listed in rating category \textit{BBB} are those bonds which have either a \textit{BBB} rating as given by the S\&P agency, or a \textit{Baa} rating as given by the Moody's agency. In some cases, it occurs that e.g. the Moody's rating is given as \textit{A}, and the S\&P rating as \textit{BBB}. In this case, the bond would be listed in both the \textit{A} and the \textit{BBB} categories, which results in intersections between the single categories. The procedure has been chosen this way to receive a larger amount of data for analysis, as e.g. entries for the Moody's rating alone were somewhat scarce. If needed, further analysis can be done based on ratings of a single agency only.

\begin{figure}[h]
	\centering
	\includegraphics[trim={0 16cm 0 0},clip,width=1.0\linewidth]{figures/summary-stats-by-rating.pdf}
	\caption{Monthly Return Statistics by Bond Rating}
	\label{fig:summary-stats-by-rating}
\end{figure}

The distribution mean and standard deviation of the bond returns are largely in-line with my expectations. Bonds in regions with a majority of developed countries generally have a higher mean return and a lower standard deviation than bonds in regions with more developing countries. Similarly, investment grade bonds have higher mean return and lower volatility than non-investment grade bonds.

The correlation with equity returns looks higher for developed regions, but at the same time lower for investment grade bonds.
Additionally, the correlation of monthly bond returns with lagged stock returns strictly monotonically increases with falling credit rating. As such, the lowest bond-lead correlation can be seen for corporate bonds rated \textit{AAA}, while the highest correlation is listed for \textit{CCC} rated bonds. This already explains quite well why existing research on the topic of the lead-lag relation of corporate bonds and stocks mostly focuses on high yield bonds, as these have the highest lead correlation with stocks. The correlation results of stock returns with lagged bond returns are less conclusive, but tend to be higher for investment grade bonds. From a geographical point of view, there seems to be no significant insight for the lead and lag correlations with equity returns.

\section{Lead-Lag Relationship} \label{section:lead-lag-relationship}
In order to estimate the existence of a potential lead or lag relationship between corporate bonds and stocks, multiple regression analyses have been run. In particular, the calculations were conducted for the following bond groups:
\begin{itemize}
	\item all corporate bonds
	\item split by geographical region: North America, South America, Western Europe, Eastern Europe, and China
	\item split by bond credit rating: AAA, AA, A, BBB, BB, B, CCC, other
	\item split by aggregated bond credit rating: investment grade and non-investment grade bonds
	\item two rating-based approaches to high-yield bonds
\end{itemize}
All regression analyses have been run as a duo of:
\begin{enumerate}
	\item regression with monthly bond returns as dependent variable and 1-month lagged stock returns as independent variable
	\item regression with monthly stock returns as dependent variable and 1-month lagged bond returns as independent variable
\end{enumerate}

For shortness, not all the regression results will be introduced here in detail. This section will mostly focus on high yield bonds, as these have shown the most likely lead correlation with equities in section \ref{section:summary-statistics}, and also because the leads and lags of high yield bonds have seen the highest attention in the existing literature on this subject so far (e.g. \cite{lead-lag-source}). All the other regression results can be found either in appendix \ref{appendix-regression} to this work, or as part of the project files.

\begin{figure}[h]
	\centering
	\includegraphics[trim={0 0 0 0},clip,width=1.0\linewidth]{figures/regression-results/regression-high-yield-ccc-d-moodies-bonds-as-dependent.PNG}
	\caption{Results: regression with high-yield corporate bonds (as by Moody's) as dependent variable, and stocks as independent variable}
	\label{fig:regression-high-yield-ccc-d-moodies-bonds-as-dependent.PNG}
\end{figure}

Fig. \ref{fig:regression-high-yield-ccc-d-moodies-bonds-as-dependent.PNG} features the regression results for high-yield corporate bond return as dependent variable, and stock return as independent variable. Specifically, high-yield bonds have been taken as those with either a \textit{Ca} or a \textit{C} current rating provided by Moody's. From a statistical perspective, the following interpretation of the results can be given:
\begin{itemize}
	\item The \textit{model sum of squares} (\textit{MSS}) is not very close to the \textit{total sum of squares} (\textit{TSS}), which means that the fit of the model function is not very tight.
	\item The \textit{p-value} (here \textit{Prob $>$ F}) is noticeably lower than 0.05. This means that the results of the regression are statistically significant.
	\item The $r^2$ is the amount of variance of bond returns that is explained by the lagged equity returns. The number is rather low, though it is the highest achieved in all the regression analyses run. Apparently, equities are best in explaining the variance of high-yield bonds, compared to other bond groups.
	\item The \textit{root mean-squared-error} is the standard deviation of the regression model. It is close to 0, which means that the single bond return values do not deviate much from the distribution mean on average. On the other hand, the bond returns themselves are not very high, so even an absolutely small standard deviation can have a significant impact on the spread.
	\item The modeled regression function itself has the shape $bond\_return_{n} = -0.0013 + 0.0584 * stock\_return_{n-1}$, with $n$ being the month, at the end of which the return occurred. The magnitude of the steepness factor and the intercept seems in-line with our expectations.
	\item The \textit{t-values} signify the importance of the variable in the regression model. An absolute \textit{t-value} greater than 1.96 is usually considered as good, which is here the case for the steepness coefficient.
	\item The \textit{two-tail p-value} (here \textit{P $>$ $|t|$})is lower than 0.05 for the growth coefficient, which means that it is statistically significant. The value for the intercept is not very significant at 0.231.
\end{itemize}
Overall, the results show that stock returns lead the returns of high yield bonds on a 1-month basis, though the results are not entirely conclusive. My recommendation is to use a more sophisticated (e.g. portfolio-based) regression procedure, and potentially to also try using a non-linear regression model to receive more reliant results.

\begin{figure}[h]
	\centering
	\includegraphics[trim={0 0 0 0},clip,width=1.0\linewidth]{figures/regression-results/regression-high-yield-ccc-d-moodies-stocks-as-dependent.PNG}
	\caption{Results: regression with high-yield corporate bonds (as by Moody's) as independent variable, and stocks as dependent variable}
	\label{fig:regression-high-yield-ccc-d-moodies-stocks-as-dependent.PNG}
\end{figure}

Fig. \ref{fig:regression-high-yield-ccc-d-moodies-stocks-as-dependent.PNG} shows the regression results for high-yield corporate bond return as independent variable, and stock return as dependent variable. The same definition of 'high-yield' applies as for the first regression. Compared to regression results with bonds as dependent variable, the results with stocks as dependent variable are somewhat less significant, as can be seen e.g. by looking at the p-value an the two-tailed p-values. The model function fit is also somewhat worse when looking at the model sum of squares compared to the total sum of squares, as well as based on the $r^2$ parameter and the standard deviation of the model. Based on the t-values and the two-tail p-values, the results are statistically significant for the growth coefficient, but not so for the intercept. The model function itself is shaped as $stock\_return_{n} = -0.0013 + 0.2345 * bond\_return_{n-1}$, with $n$ being the month like before.

As the results of the second regression model are not as reliable and significant as those of the first one, it can be concluded that stocks are likely faster in incorporating significant market information than high-yield bonds, for one and the same company. However, due to the chosen procedure being very basic, it is advisable to conduct a more thorough regression analysis to draw up more reliable conclusions.


text:
%----------------------------------------------------------------------------------------
%       PACKAGES AND THEMES
%
% docs: https://en.wikibooks.org/wiki/LaTeX/Presentations#Introductory_example
%----------------------------------------------------------------------------------------

\documentclass{beamer}

\mode<presentation> {

% The Beamer class comes with a number of default slide themes
% which change the colors and layouts of slides. Below this is a list
% of all the themes, uncomment each in turn to see what they look like.

%\usetheme{default}
%\usetheme{AnnArbor}
%\usetheme{Antibes}
%\usetheme{Bergen}
%\usetheme{Berkeley}
%\usetheme{Berlin}
%\usetheme{Boadilla}
%\usetheme{CambridgeUS}
%\usetheme{Copenhagen}
%\usetheme{Darmstadt}
%\usetheme{Dresden}
\usetheme{Frankfurt}
%\usetheme{Goettingen}
%\usetheme{Hannover}
%\usetheme{Ilmenau}
%\usetheme{JuanLesPins}
%\usetheme{Luebeck}
%\usetheme{Madrid}
%\usetheme{Malmoe}
%\usetheme{Marburg}
%\usetheme{Montpellier}
%\usetheme{PaloAlto}
%\usetheme{Pittsburgh}
%\usetheme{Rochester}
%\usetheme{Singapore}
%\usetheme{Szeged}
%\usetheme{Warsaw}

% As well as themes, the Beamer class has a number of color themes
% for any slide theme. Uncomment each of these in turn to see how it
% changes the colors of your current slide theme.

%\usecolortheme{albatross}
%\usecolortheme{beaver}
%\usecolortheme{beetle}
%\usecolortheme{crane}
%\usecolortheme{dolphin}
%\usecolortheme{dove}
%\usecolortheme{fly}
%\usecolortheme{lily}
%\usecolortheme{orchid}
%\usecolortheme{rose}
%\usecolortheme{seagull}
%\usecolortheme{seahorse}
%\usecolortheme{whale}
%\usecolortheme{wolverine}

%\setbeamertemplate{footline} % To remove the footer line in all slides uncomment this line
%\setbeamertemplate{footline}[page number] % To replace the footer line in all slides with a simple slide count uncomment this line

%\setbeamertemplate{navigation symbols}{} % To remove the navigation symbols from the bottom of all slides uncomment this line
}

%\usepackage[german]{babel}
\usepackage[latin1]{inputenc}
\usepackage{alltt}
\usepackage{beamerthemesplit}

\usepackage{graphicx} % Allows including images
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables

\usepackage{color}
\usepackage{listings}
\lstset{
  %basicstyle=\ttfamily\bfseries,
  basicstyle=\ttfamily\footnotesize,
  commentstyle=\color{red}\itshape,
  stringstyle=\color{green},
  showstringspaces=false,
  keywordstyle=\color{blue}\bfseries,
  numberstyle=\ttfamily\tiny,
  frame=single,
  numbers=left,
  numbersep=1em,
  xleftmargin=2em,
  language=Python,
  breaklines=true,
  breakatwhitespace=true,
  postbreak=\hbox{$\hookrightarrow$ },
  showstringspaces=false,
  tabsize=2
}

%% Title Page

\title{Birdhouse Architecture}
%\subtitle{subtitle}
\author{
Carsten Ehbrecht\\
\medskip
{\scriptsize \url{ehbrecht@dkrz.de}}
}
\institute{German Climate Computing Center (DKRZ)}
\date{February 2016}
\subject{Climate Science, Web Processing Service}

% page numbers
%\insertframenumber

% don't count title page
%\addtocounter{framenumber}{-1}

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

\begin{document}

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

  \begin{frame}[plain]
    \titlepage
  \end{frame}

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

  %\AtBeginSection[]
  \AtBeginSection[]{\frame{\frametitle{Overview}\tableofcontents[current]}}
  {
    \begin{frame} % shrink
      \frametitle{Outline}
      \tableofcontents[subsectionstyle=hide/hide]
    \end{frame}
  }

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

  \section{Motivation}

  \begin{frame}
    \frametitle{Web Processing Service}
    A web service interface to standardize the way that algorithms are made available on the Internet
    \begin{figure}
      \includegraphics[width=7cm]{images/Wps.png}
    \end{figure}
  \end{frame}

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

  \begin{frame}
    \frametitle{WPS Use Case}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/WpsUseCase.png}
    \end{figure}
  \end{frame}

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

  \begin{frame}
    \frametitle{What does WPS provide?}
    \begin{itemize}
      \item web access to your algorithms (GET request with key-value, POST request with xml)
      \item WPS knows about the inputs and outpus of a process
      \item processes are self-describing (GetCapabilites, DescribeProcess)
      \item sync and async calls (async calls with status document)
      \item its a standard interface ... several implementations are available (PyWPS, GeoServer, 52 North, COWS, ...)
      \item process definition is easy to write
      \item not restricted to a specific programming language
      \item can be used internally to provide enhanced functionality to web portals
    \end{itemize}
  \end{frame}

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

  \begin{frame}[fragile]
    \frametitle{Enable your code as WPS process}
    \begin{block}{Use wps decorator for your function}
      \tiny
      \lstset{language=python}
      \lstinputlisting{wps_myplot.py}
    \end{block}
    \begin{block}{Execute your function with WPS}
      \begin{verbatim}
http://localhost/wps?service=WPS&version=1.0.0 \
   &request=execute \
   &identifier=myplot \
   &DataInputs=nc_file=http://;variable=tas
      \end{verbatim}
    \end{block}
\end{frame}

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

  % \begin{frame}[plain]
  %   \frametitle{Example: Textgenerator + Word Counter}
  %   \begin{columns}[T] % contents are top vertically aligned
  %     \begin{column}[T]{5cm} % each column can also be its own environment
  %       \begin{figure}
  %         \includegraphics[height=6cm]{images/WpsTextGenerator.png}
  %       \end{figure}
  %     \end{column}
  %     \begin{column}[T]{5cm} % alternative top-align that's better for graphics
  %       \begin{figure}
  %         \includegraphics[height=6cm]{images/WpsInOut.png}
  %       \end{figure}
  %     \end{column}
  %   \end{columns}
  % \end{frame}

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

  % \begin{frame}[plain]
  %   \frametitle{Example: WPS Chain}
  %   \begin{figure}
  %     \includegraphics[height=6cm]{images/WpsChain.png}
  %   \end{figure}
  % \end{frame}

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

  \section{Birdhouse Components}

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

\begin{frame}
    \frametitle{Birdhouse Aims}
    \begin{itemize}
      \item Making it easier to setup WPS services (Birdhouse-Builder).
      \item Providing Python library and WPS processes to access climate data.
      \item Providing a workflow to chain data fetching and data processing.
      \item Providing a web and command line client to interact with WPS services.
    \end{itemize}
  \end{frame}

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

  \begin{frame}[plain]
    \frametitle{Birdhouse Components}
    \begin{figure}
      \begin{center}
        \includegraphics[width=11.5cm]{images/birdhouse-components.png}
      \end{center}
    \end{figure}
  \end{frame}

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

  \begin{frame}
    \frametitle{Phoenix web-based WPS client}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/phoenix.png}
    \end{figure}
  \end{frame}

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

  \begin{frame}[fragile]
    \frametitle{Birdy command line WPS client}
    \begin{verbatim}
>> conda install -c birdhouse birdhouse-birdy
>> export WPS_SERVICS=http://localhost:8094/wps
>> birdy -h
    \end{verbatim}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/birdy-terminal.png}
    \end{figure}
\end{frame}

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

  \begin{frame}
    \frametitle{Birdhouse WPS serivces}
    \begin{itemize}
      \item Malleefowl (for internal use): download data with cache, workflows ...
      \item Emu: processes for testing and demo
      \item Hummingbird: processes for general tools used in the climate science community like cdo and cfchecker
      \item Flyingpigeon: processes for climate data, indices and extreme events
    \end{itemize}
  \end{frame}

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

  \begin{frame}
    \frametitle{WSGI Application controlled with Supervisor}
    \begin{figure}
      \includegraphics[width=8cm]{images/WsgiApp.png}
    \end{figure}
  \end{frame}

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

  \begin{frame}
    \frametitle{Workflow Process in Birdhouse}
    \begin{itemize}
      \item the chain of WPS processes is controlled by a Workflow Engine (dispel4py)
      \item The Workflow Process itself is a WPS process
      \item data-search, download and publish are internal processes (provided by Malleefowl)
      \item Compute is a process choosen by the user ... for example cfchecker
      \item The Phoenix wizard is used to collect the parameters for the workflow process
    \end{itemize}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/WpsWorkflow.png}
    \end{figure}
  \end{frame}

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

  \section{Birdhouse Builder}

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

  \begin{frame}
    \frametitle{Why Conda and Buildout?}
    \begin{itemize}
      \item many components: WPS, WMS, web-server, solr, ...
      \item lots of dependencies: cdo, cfchecker, ocgis, numpy, R, ...
      \item many different kinds of config files need to be configured
      \item installation needs to be reproducible at different locations
      \item should work with different Linux distributions (Centos, Fedora, Debian, Ubuntu, ...)
    \end{itemize}
    \begin{figure}
      \includegraphics[width=4cm]{images/chaos.png}
    \end{figure}
  \end{frame}

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

  \subsection{Conda}

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

  \begin{frame}[fragile]
    \frametitle{conda package manager}
    \begin{itemize}
      \item originally for python ... but has a general concept
      \item does not need admin rights
      \item manages dependencies
    \end{itemize}
    \begin{block}{install from birdhouse channel}
      \begin{verbatim}
>> conda install -c birdhouse pywps cdo
      \end{verbatim}
    \end{block}
    \begin{block}{create conda environment=emu}
      \begin{verbatim}
>> conda create -n emu -c birdhouse \
        python=2.7 cdo pywps
      \end{verbatim}
    \end{block}
\end{frame}

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

  \begin{frame}[fragile]
    \frametitle{conda recipe}
    \begin{block}{meta.yaml}
      \lstinputlisting{meta.yaml}
    \end{block}
    \begin{block}{build conda package}
      \begin{verbatim}
>> ls
meta.yaml build.sh
>> conda build .
      \end{verbatim}
    \end{block}
\end{frame}

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

  \begin{frame}[plain]
    \frametitle{Anaconda Cloud}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/anaconda-cloud.png}
    \end{figure}
  \end{frame}

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

  \subsection{Buildout}

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

  \begin{frame}
    \frametitle{Buildout}
    \begin{itemize}
      \item Python based build system
      \item creates application with multiple components including configuration files
      \item works also for non-Python parts
      \item using a buildout configuration
      \item can be extended with recipes
    \end{itemize}
  \end{frame}

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

  \begin{frame}[fragile]
    \frametitle{Buildout configuration}
    \begin{block}{buildout.cfg}
      \lstinputlisting{buildout.cfg}
    \end{block}
\end{frame}

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

  \begin{frame}[fragile]
    \frametitle{Buildout Recipe}
    \begin{block}{birdhousebuilder.recipe.pywps}
      \lstinputlisting{recipe.py}
    \end{block}
\end{frame}

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

  \begin{frame}[fragile]
    \frametitle{Install Birdhouse Component with Buildout}
    \begin{itemize}
      \item for convienience there is a Makefile to call the buildout commands
      \item all Birdhouse components (WPS, Phoenix) are installed in the same way
    \end{itemize}
    \begin{block}{First installation}
      \begin{verbatim}
>> git clone https://github.com/bird-house/emu.git
>> cd emu
>> make clean install
>> make start
      \end{verbatim}
    \end{block}
\begin{block}{Update configuration like hostname, port}
      \begin{verbatim}
>> vim custom.cfg
>> make update
>> make restart
      \end{verbatim}
    \end{block}
\end{frame}

  \section{Deployment with Docker}

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

  \begin{frame}
    \frametitle{What is Docker?}
    \begin{itemize}
      \item a lightweight Virtual-Machine using Linux Containers
      \item isolated environment for your Linux installation
      \item runs on the same hardware as the host
      \item run latest Ubuntu on an older Centos
      \item rapid startup time
      \item only changed parts of docker image need to loaded on update
    \end{itemize}
    \begin{figure}
      \includegraphics[width=4cm]{images/docker-container.png}
    \end{figure}
  \end{frame}

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

  \begin{frame}
    \frametitle{Containers vs VMs (slide taken from docker)}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/docker-vs-vms.jpg}
    \end{figure}
  \end{frame}

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

  \begin{frame}[plain]
    \frametitle{Deploy Birdhouse with Docker}
    \begin{itemize}
      \item each service is running in a Docker container
      \item docker containers can be \emph{linked} to other containers
      \item only some containers (Phonix, WPS Proxy) need to be exposed to external use
    \end{itemize}
    \begin{figure}
      \includegraphics[width=10cm]{images/BirdhouseDocker.png}
    \end{figure}
  \end{frame}

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

  \begin{frame}[fragile,shrink]
    \frametitle{Dockerfile}
    \lstinputlisting{Dockerfile}
\end{frame}

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

  \begin{frame}[fragile,shrink]
    \frametitle{Try a Docker ...}
    \begin{block}{Images are available on DockerHub}
      \url{https://hub.docker.com/u/birdhouse/}
    \end{block}
    \begin{block}{Start a docker image with Emu WPS}
      \begin{verbatim}
>> docker run -it -p 8090:8090 -p 8094:8094 \
         --name=emu_wps birdhouse/emu
      \end{verbatim}
    \end{block}
    \begin{block}{Run WPS GetCapabilities Request}
      \begin{verbatim}
http://localhost:8094/wps? \
   service=WPS&version=1.0.0&request=getcapabilities
      \end{verbatim}
    \end{block}
\end{frame}

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

  \section{Security and Interoperability}

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

  \begin{frame}
    \frametitle{WPS Security Proxy}
    \begin{itemize}
      \item using string token (uuid) as part of URL or in request header to protect WPS execute access
      \item X509 certificates to access (remote) data from ESGF are provided by proxy (using environ)
      \item implemented as WSGI application layer
    \end{itemize}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/WpsProxy.png}
    \end{figure}
  \end{frame}

  \begin{frame}
    \frametitle{Twitcher OWS Security Proxy (prototype)}
    \begin{figure}
      \includegraphics[width=11.5cm]{images/twitcher-overview.png}
    \end{figure}
  \end{frame}

  \begin{frame}
    \frametitle{Best Practises to make WPS interchangeable}
    \begin{itemize}
      \item support of complete WPS protocol (literal type, complex types, ...)
      \item separation of WPS definition and functional code (provided as Python library)
      \item convenience and integration code provided as library (e.a. Malleefowl provides functions used by WPS processes)
      \item using WPS profiles (common WPS process definitions)
      \item use self-describing possibilities of WPS
      \item parameters relevant for the process should be part of the process definition
    \end{itemize}
  \end{frame}

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

  \appendix

  \section{Appendix}

   \begin{frame}[allowframebreaks]
    \frametitle<presentation>{Further Reading}
    \begin{thebibliography}{10}
      \beamertemplatearticlebibitems
    \bibitem{birdhouse}
      Birdhouse
      \newblock \url{http://bird-house.github.io/}
    \bibitem{buildout}
      Buildout
      \newblock \url{http://www.buildout.org/}
    \bibitem{anaconda}
      Anaconda
      \newblock \url{https://www.continuum.io/why-anaconda}
    \bibitem{foos4g-ebrahim}
      Evaluation of WPS Frameworks
      \newblock \url{http://www.slideshare.net/mepa1363/foss4g-ebrahim}
    \bibitem{wps-cct}
      Web Processing Service
      \newblock http://www.slideshare.net/GasperiJerome/20130530-web-processing-service-cct-cloud-toulouse-29423710

    \end{thebibliography}

  \end{frame}

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

  \begin{frame}
    \Huge{\centerline{The End}}
  \end{frame}

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

\end{document}

max_stars_repo_name: Zeitsperre/birdhouse-docs

max_issues_repo_name: Zeitsperre/birdhouse-docs

max_forks_repo_name: Zeitsperre/birdhouse-docs


text:
\documentclass[margin,line]{res}
\usepackage[margin=.4in]{geometry}
\usepackage{fontawesome}
\usepackage{fancyhdr}
\usepackage{marvosym}
\usepackage{wasysym}

\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrule{}

\oddsidemargin -.65in
\evensidemargin -.65in
\textwidth=6.5in
\itemsep=0in
\parsep=0in

\usepackage[symbol,bottom]{footmisc}
\usepackage[x11names]{xcolor}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\usepackage{svg}
\usepackage{float}
\usepackage{marvosym}
\usepackage{caption}
\usepackage{array}
\captionsetup{labelfont=bf}
\usepackage[lofdepth]{subfig}
\usepackage[nodayofweek]{datetime}
\usepackage{setspace}\onehalfspacing
\usepackage{cite} % takes care of citations
\usepackage[final]{hyperref} % adds hyperlinks in pdfs
\usepackage{fancyhdr}

% =============================
% DEFINE YOUR FAV COLOURS HERE
% =============================

\definecolor{myorange}{HTML}{F46524}
\definecolor{myblue}{HTML}{191970}
\definecolor{mygray}{HTML}{696969}
\definecolor{mycyan}{HTML}{074774}

\newcommand{\MYhref}[3][mycyan]{\href{#2}{\color{#1}{#3}}}%

% ==============================
% DEFINITIONS FOR BULLET FORMAT
% ==============================

\newenvironment{list1}{
  \begin{list}{\ding{113}}{%
      \setlength{\itemsep}{0in}
      \setlength{\parsep}{0in} \setlength{\parskip}{0in}
      \setlength{\topsep}{0in} \setlength{\partopsep}{0in}
      \setlength{\leftmargin}{0in}}}{\end{list}}

\newenvironment{list2}{
  %\begin{list}{$\bullet$}{%
  \begin{list}{$\circ$}{%
      \setlength{\itemsep}{0in}
      \setlength{\parsep}{0in} \setlength{\parskip}{0in}
      \setlength{\topsep}{0in} \setlength{\partopsep}{0in}
      \setlength{\leftmargin}{0.25in}}}{\end{list}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% You can have multiple style options the legal options ones are:
%
%   centered	the name and address are centered at the top of the
%		page (default)
%
%   line	the name is the left with a horizontal line then
%		the address to the right
%
%   overlapped	the section titles overlap the body text (default)
%
%   margin	the section titles are to the left of the body text
%
%   11pt	use 11 point fonts instead of 10 point fonts
%
%   12pt	use 12 point fonts instead of 10 point fonts
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Commands
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   \Resume	prints the word resume but typeset nicely
%
%   \newsectionwidth{dimen}
%		defines the amount of space the labels extend
%		into the left margin.
%		DO NOT TRY to change any of the dimensions
%		yourself.  You will probably confuse the style file.
%
%   \name{text} defines your name
%
%   \address{text}
%		defines your address
%		this can be called twice if you have two addresses
%		use \\'s to indicate where either line breaks or
%		comas should go
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\vspace{-4in}

%change hyperlink to linkedin and name here
\name{{{\MYhref{https://www.linkedin.com/in/}{{\textsc{\Resume \space - John Doe}}}}}}

\vspace*{-.025in}
% hyperlink your email address here
\address{\normalsize{{\MYhref{mailto:your.email@domain.com}{\textbf{ \Letter \space \texttt{your\{DOT\}email\{AT\}domain\{DOT\}com}}}}} \space  {\MYhref{https://goo.gl/maps/}{\textbf {\faMapMarker \space \textsf{Secret}}}} %can hyperlink your city or detailed address here
\space {\textcolor{mycyan}{\text{\textbf{\large{\faMobile}\normalsize{\space +1 007 1234 007}}}}} }

\begin{resume}

\vspace*{-.15in}
\section{\sc Interests}
{ {\bf }  stealth maneuvers, computational cryptography, special intelligence}

\vspace*{-.1in}
\section{\sc Education}

{\bf Fancy Master's degree } \hfill {\bf 2017}\\
\vspace{-.2in}
\begin{list2}
\item [] \textsf{Fancy School, memorable city} \hfill {cumulative grade - \bf 4/4}
\end{list2}

\vspace*{-.15in}

{\bf Fancy Bachelor's degree} \hfill {\bf 2007}\\
\vspace{-.2in}
\begin{list2}
\item [] \textsf{Cool School, nice city} \hfill {cumulative grade - \bf 4/4}
\end{list2}
\vspace*{-0.1in}
\section{\sc Professional Experience}

{\bf Experience \#1}, {\sf where-you-did-it} \hfill {when-you-did-it}

\begin{list2}
\item what contribution you made towards \textsf{some project}
\end{list2}

\vspace*{-.15in}
{\bf Experience \#2} \hfill {when-you-did-it}

\begin{list2}
\item what did you learn from this? in a manner that is transferrable to other skills
\end{list2}

\vspace*{-.15in}
{\bf Experience \#3}, {\sf where-you-did-it} \hfill {when-you-did-it}

\begin{list2}
\item what did you learn from this? in a manner that is transferrable to other skills
\end{list2}

\vspace*{-0.1in}
\section{\sc Key Academic Projects}

{\bf Project \#1}, {\sf where-you-did-it} \hfill {when-you-did-it}

\begin{list2}
\item main responsibility, and how you excelled; key achievements and success metrics
\end{list2}

\vspace*{-.15in}
{\bf Project \#2}, {\sf where-you-did-it} \hfill {when-you-did-it}

\begin{list2}
\item main responsibility, and how you excelled; key achievements and success metrics

\end{list2}

\vspace*{-.15in}
{\bf Fellowship \#1}, {\sf where-you-did-it} \hfill {when-you-did-it}

\begin{list2}
\item main responsibility, and how you excelled; key achievements and success metrics
\end{list2}

\vspace*{-.15in}
{\bf Internship \#1}, {\sf where-you-did-it} \hfill {when-you-did-it}

\begin{list2}
\item main responsibility, and how you excelled; key achievements and success metrics
\end{list2}

\vspace*{-0.1in}

\section{\sc Academic Achievements}
\begin{list1}
\item []\textbf{scholarship} {\sf by-whom} \hfill {when-you-did-it}
\item []\textbf{Scholarship for X project } {\sf by-whom} \hfill {when-you-did-it}
\item [] Secured \textit{some-merit} in \textit{some-exam} \hfill {when-you-did-it}
\item [] {\bf Graduate Record Examination:}  Quantitative: {\bf 16x/170}, Verbal: {\bf 16x/170}, Total: {\bf 32x/340} \hfill {when}
\end{list1}

\vspace*{-0.1in}

\section{\sc Programming Skills}
\begin{list1}
    \item [] Programming languages: \texttt{Python}, \texttt{C++}
    \item [] Scripting languages: \texttt{Bash}, \texttt{R}, \texttt{Scilab}, \texttt{Matlab}, \LaTeX
    \item [] Workflows: \texttt{TensorFlow}, \texttt{conda}, \texttt{git}, \texttt{Jupyter}, \texttt{Snakemake}
    \vspace*{.075in}
\end{list1}

\vspace*{-0.1in}

\section{\sc Positions of Responsibility}
\begin{list1}
\item []{\bf Volunteer X}, \textsf{where} \hfill {when-you-did-it}
\item []{\bf School Secretary}, \textsf{where} \hfill {when-you-did-it}
%\item []{\bf Sergeant, National Cadet Corps}, \textsf{4-MP Battalion} \hfill {when-you-did-it}
\end{list1}

\vspace*{-0.1in}

\section{\sc Extracurricular}
\begin{list1}
\item [] \textbf{Clubs:} that you were involved with

\item [] {\bf Interests:} meditation or some cool hobbies

\item [] \textbf{Sports:} to flex some muscle

\item [] \textbf{Hobbies:} to show some other interesting parts of your personality

\end{list1}

\end{resume}
\end{document}

max_stars_repo_name: divprasad/CurriculumVitae

max_issues_repo_name: divprasad/CurriculumVitae

max_forks_repo_name: divprasad/CurriculumVitae


text:
%%%%%%%%%%%%%%%%%%%%%%
% This is an example presentation made with Christopher Gandrud's unofficial LSE Beamer theme
% Updated 27 December 2011
%%%%%%%%%%%%%%%%%%%%%%

\documentclass{beamer}
\usetheme{LSE}
\usepackage{color}
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=black}
\usepackage{graphics}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{minted}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Title Slide %%%%%%%%%%%%%%%%%%%%%%%%%%
\title[Calcolo Parallelo]{Calcolo Parallelo : Lezione 1}
\author[F. Durastante]{
    \href{mailto:f.durastante@na.iac.cnr.it}{Fabio Durastante}
}
\institute{Consiglio Nazionale delle Ricerche - Istituto per Le Applicazioni del Calcolo ``M. Picone''}
\date[Gennaio 2020]{Master in Scienze e Tecnologie Spaziali, 2020}

\beamerdefaultoverlayspecification{}

\begin{document}

\begin{frame}
	\titlepage
\end{frame}

\section[Outline]{}
\frame{\tableofcontents}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Scientific and parallel computing}

\begin{frame}{Scientific and parallel computing}

\begin{columns}
	\begin{column}{0.6\textwidth}
		\begin{center}
		``\textbf{Computational science} (also \textbf{scientific computing} or \textbf{scientific computation} (SC)) is a rapidly growing multidisciplinary field that uses advanced computing capabilities to \emph{understand and solve complex problems}. It is an area of science which spans many disciplines, but at its core it involves the development of \emph{models and simulations to understand natural systems}.''
		\end{center}

		\flushright Wikipedia
	\end{column}
	\begin{column}{0.4\textwidth}
		\centering
		\includegraphics[width=\columnwidth]{nasasuperpc.jpg}

	\end{column}
\end{columns}

\end{frame}

\begin{frame}{What are the applications?}
	\centering
	\begin{columns}
		\begin{column}{0.5\textwidth}
		\begin{itemize}
		\item Computational finance,
		\item Computational biology,
		\item Simulation of complex systems,
		\item Network analysis
		\item Multi-physics simulations,
		\item Weather and climate models,
		\item \ldots
		\end{itemize}
		\end{column}
		\begin{column}{0.5\textwidth}
			\includegraphics[width=\columnwidth]{applications.png}
		\end{column}
	\end{columns}
	\vfill
	\onslide<2>{Why the need for \alert{parallelism}?}
\end{frame}

\begin{frame}{Moore's law}
	\begin{columns}
		\begin{column}{0.4\columnwidth}
		\centering
		\includegraphics[width=0.3\columnwidth]{Gordon_Moore.jpg}

		{\small
			``The complexity for minimum component costs has increased at a rate of roughly a factor of two per year. Certainly over the short term this rate can be expected to continue, if not to increase. Over the longer term, the rate of increase is a bit more uncertain, although there is no reason to believe it will not remain nearly constant for at least 10 years.''
		}

		{\flushright G. Moore, 1975}
		\end{column}
	\begin{column}{0.6\columnwidth}
		\centering
		\includegraphics[width=\columnwidth]{mooreslawoftransistors.png}

		\onslide<2>{
		Computers \emph{should} reach the physical limits of Moore's Law at some point in the 2020s\ldots exponential functions saturates physical capabilities!
		}
	\end{column}
	\end{columns}
\end{frame}

\begin{frame}{Motivations for parallel computing}
\begin{itemize}
\item<1-> We are hitting the wall of single processor transistor count/computing capabilities,
\item<2-> Some applications needs more memory than the one that could be available on a single machine,
\item<3-> Optimization of sequential algorithms can bring us only to a certain extent
\end{itemize}
\onslide<4->{
	\centering
	``$\delta\iota\alpha\acute{\iota}\rho\epsilon\iota\,\kappa\alpha\grave{\iota}\,\beta\alpha\sigma\acute{\iota}\lambda\epsilon\nu\epsilon$``\\
	(di\'{a}irei k\'{a}i bas\'{i}leue)}

\onslide<5->{
\centering
Dividi et Impera
}

\onslide<6>{
\flushleft
Therefore, we need
\begin{itemize}
	\item Algorithms that can work in parallel,
	\item A communications protocol for parallel computation integrated with our programming languages
	\item Parallel machines that can actually run this code
\end{itemize}
}
\end{frame}

\subsection{Flynn's Taxonomy}

\begin{frame}{Parallel computers: Flynn's Taxonomy}
Let us start from the bottom: the \alert{machines}.
\begin{itemize}
	\item<2-> What is a parallel computer? \only<3-4>{well, it can be a certain number of different ``things''
	\begin{itemize}
		\item \alert<4>{Multi-core computing}
		\item Symmetric multiprocessing
		\item Distributed computing
		\item \alert<4>{Cluster computing}
		\item \alert<4>{Massively parallel computing}
		\item Grid computing
		\item \alert<4>{General-purpose computing on graphics processing units (GPGPU)}
		\item Vector processors
	\end{itemize}}
	\item<5-> Let us \emph{abstract} from the machine by describing Flynn's taxonomy
	\begin{columns}
		\begin{column}{0.25\columnwidth}
		\centering
		\small
		\includegraphics[width=\columnwidth]{SISD.png}

		Single instruction stream, single data stream\\SISD
		\end{column}
			\begin{column}{0.25\columnwidth}
						\centering
				\small
	\includegraphics[width=\columnwidth]{SIMD.png}

	\alert<6>{Single instruction stream, multiple data streams\\SIMD}
	\end{column}
		\begin{column}{0.25\columnwidth}
					\centering
			\small
	\includegraphics[width=\columnwidth]{MISD.png}

	Multiple instruction streams, single data stream\\MISD
\end{column}
\begin{column}{0.25\columnwidth}
					\centering
			\small
	\includegraphics[width=\columnwidth]{MIMD.png}

	\alert<6->{Multiple instruction streams, multiple data streams\\MIMD}
\end{column}
	\end{columns}
\end{itemize}
\end{frame}

\begin{frame}{Parallel Computers: our computer model}
For our task of introducing parallel computations we need to fix a \textbf{specific multiprocessor model}, i.e., a specific generalization of the sequential RAM model in which there is more than one processor.
\vfill
\begin{columns}
	\begin{column}{0.5\columnwidth}
	Since we want to stay in a SIMD/MIMD model, we focus on a \emph{local memory machine model}, i.e., a set of $M$ processors each with its own local memory that are attached to a common communication network.
	\end{column}
	\begin{column}{0.5\columnwidth}
	\centering
	\includegraphics[width=\columnwidth]{networkarchitecture.pdf}
	\end{column}
\end{columns}
\vfill
\only<2>{
\begin{itemize}
	\item We can be more precise about the connection between processors, one can consider a network (a collection of switches connected by communication channels) and delve in a detailed way into its pattern of interconnection, i.e., into what is called the network topology.
\end{itemize}
}
\only<3>{
\begin{itemize}
	\item An alternative is to summarize the network properties in terms of two parameters: \alert{latency} and \alert{bandwidth}
	\begin{description}
		\item[Latency] the time it takes for a message to traverse the network;
		\item[Bandwidth] the rate at which a processor can inject data into the network.
	\end{description}
\end{itemize}
}

%\vfill
%\onslide<3>{
%	\centering
%	What are the available machines?
%}
\end{frame}

\subsection{The TOP500 List}

\begin{frame}{The TOP500 List -- \url{https://www.top500.org/}}
\begin{columns}
	\begin{column}{0.4\columnwidth}
	\small
	``\ldots we have decided in 1993 to assemble and maintain a list of the 500 most powerful computer systems. Our list has been compiled twice a year since June 1993 with the help of high-performance computer experts, computational scientists, manufacturers, and the Internet community in general\ldots

	In the present list (which we call the TOP500), we list computers ranked by their performance on the \alert{LINPACK Benchmark}.''
	\vfill
	\url{http://www.netlib.org/benchmark/hpl/}
	\end{column}
	\begin{column}{0.6\textwidth}
	\small
	\onslide<2>{
	The \alert{LINPACK} Benchmark.

	Solution of a dense $n\times n$  system of linear equations $A\mathbf{x} = \mathbf{b}$, so that
	\begin{itemize}
		\item $\frac{\| A \mathbf{x} - \mathbf{b}\|}{\|A\|\|\mathbf{x}\| n \varepsilon} \leq O(1)$, for $\varepsilon$ machine precision,
		\item It uses a specialized right--looking LU factorization with look--ahead
		\item Measuring
		\begin{itemize}
			\item $R_\text{max}$ the performance in GFLOPS for the largest problem run on a machine,
			\item $N_\text{max}$ the size of the largest problem run on a machine,
			\item $N_{1/2}$ the size where half the $R_\text{max}$ execution rate is achieved,
			\item $R_{\text{peak}}$ the theoretical peak performance GFLOPS for the machine.
		\end{itemize}
	\end{itemize}

	}
	\end{column}
\end{columns}
\end{frame}

\section{Parallel Algorithms}

\begin{frame}{Parallel Algorithms}
In a fairly general way we can say that a \textbf{parallel algorithm} is an algorithm which can do \emph{multiple operations} in a given time.

\onslide<2->{\textbf{Example:} the sum of two vectors $\mathbf{x}, \mathbf{y} \in \mathbb{R}^n$

\begin{equation*}
	\begin{array}{cl}
	\mathbf{x} & = [x_1 \; x_2 \; \cdots \; x_i  \;\onslide<3>{\textcolor{blue}{\boldsymbol{|}}\;} x_{i+1} \; \cdots x_n] \\
	+ \\
	\mathbf{y} & = [y_1 \; y_2 \; \cdots \; y_i  \;\onslide<3>{\textcolor{blue}{\boldsymbol{|}}\;} y_{i+1} \; \cdots y_n] \\
	= \\
	\mathbf{x} + \mathbf{y} & = [x_1+y_1 \; x_2+y_2 \; \cdots \; x_i+y_i  \;\onslide<3>{\textcolor{blue}{\boldsymbol{|}}\;} \cdots x_n+y_n] \\
	\end{array}
\end{equation*}
\begin{itemize}
	\item<2-> If we do the operation sequentially we do $O(n)$ operations in $T_n$
	\item<3-> If we split the operation among $2$ processors, one summing up the entries between $1,\ldots,i$, and one summing up the entries between $i+1,\ldots,n$ we take $T_i$ time for the first part and $T_{n-i}$ time for the second, therefore the overall time is $\max(T_{i},T_{n-i})$ for doing always $O(n)$ operations.
\end{itemize}

}
\end{frame}

\begin{frame}{Parallel Algorithms: \emph{speedup}}
\small
Let us try to think again in an abstract way and to quantify the \alert{overall speed gain} for a given gain in a subset of a process.
\begin{itemize}
	\item<1-> We break some process into $N$ distinct portions with the $i$th portion occupying the $P_i$ fraction of the overall completion time,
	\item<2-> then we order such portion in such a way that the $N$th portions subsumes all the parts of the overall processes that have fixed costs.
	\item<3-> The \emph{speedup} of the $i$th portion can then be defined as
	\begin{equation*}
		S_i \triangleq \frac{t_{\text{original}}}{t_{\text{optimized}}}, \quad i=1,\ldots,N-1
	\end{equation*}
	where the numerator and denominator are the original and optimized completion time.
%	\item<4->
\end{itemize}
\begin{block}<4>{Amdahl's Law}
Then the \textcolor{blue}{overall speedup} for $\mathbf{P} = (P_1,\ldots,P_N)$, $\mathbf{S} = (S_1,\ldots,S_{N-1})$ is:
\begin{equation*}
S(\mathbf{P},\mathbf{S}) = \left(P_N + \sum_{i=1}^{N-1} \frac{P_i}{S_i}\right)^{-1}.
\end{equation*}
\end{block}

\end{frame}

\begin{frame}{Parallel Algorithms: \emph{Amdahl's Law}}
Let us make some observations on Amdahl's Law
\begin{itemize}
	\item We are not assuming about whether the original completion time  involves some optimization,
	\item We are not making any assumption on what our optimization process is,
	\item We are not even saying that the process in question involves a computer!
\end{itemize}
Amdahl's Law is a fairly general way of looking at how processes can be speed up by dividing them into sub-tasks with lower execution time.

\onslide<2>{Moreover, it fixes  the \alert{theoretical maximum speedup} in various scenarios.
\begin{itemize}
	\item If we allow all components $S_i$ to grow unbounded then the upper bound on all scenario si $S_{\text{max}} = 1/P_N$.
\end{itemize}
Let us decline it in the context of the potential utility of \emph{parallel hardware}.
}
\end{frame}

\begin{frame}{Parallel Algorithms: \emph{Amdahl's Law} for \emph{parallel hardware}}
 Consider now having a parallel machine that permits us dividing the execution of code across $M$ hardware units, then the problem independent maximum speedup that such hardware can provide is $M$.
 \begin{block}{Parallel Efficiency}
 We define the parallel efficiency $E$ as
 \begin{equation*}
 	E \triangleq \frac{S_{\text{overall}}}{M},
 \end{equation*}
 where $E = 100\%$ correspond to the maximal use of the available hardware. When $S_{\text{max}} < M$, it is then impossible to take full advantage of all available execution units.
 \end{block}
\onslide<2->{\alert{Goal:} we require very large $S_{\text{max}}$ and correspondingly tiny $P_N$.}

\onslide<3->{\begin{center}
	\underline{Every dusty corner of a code must scale}, any portion that doesn't becomes the rate-limiting step!
\end{center}}

\end{frame}

\begin{frame}{Parallel Algorithms: \emph{Amdahl's Law} limitations}
What we are neglecting and what we are tacitly assuming
\begin{itemize}
	\item We are neglecting \emph{overhead costs}, i.e., the cost associated with parallel execution such as
	\begin{itemize}
		\item initializing (spawning) and joining of different computation threads,
		\item communication between processes, data movement and memory allocation.
	\end{itemize}
	\item We considered also the ideal case in which $S_i \rightarrow +\infty$ $\forall i$, observe that with finite speedup on portions $1$ through $N-1$, the $S_{\text{overall}}$ might continue to improve with increasing number of execution units.
	\item We are assuming that the size of the problem remains fixed while the number of execution units increases, this is called the case of \alert{strong scalability}. In some contexts, we need to turn instead to \alert{weak scalability} in which the problem size grows proportionally to the number of execution units.
\end{itemize}
\end{frame}

\section{Message Passing Interface}

\begin{frame}{How do we realize practically this parallelism?}
Let us focus on what we have discussed until now:
\begin{itemize}
	\item We have ``machines'' with multiple processors and whose main memory is partitioned into fragmented components,
	\item We have algorithms that can divide a problem of size $N$ among these processors so that they can run (almost) independently,
	\item With a certain degree of approximation, we know how to compute what is the \emph{best improvement} we can expect from a parallel program with $M$ processors on a problem of size $N$.
\end{itemize}
What we need to discuss now is then: ``How can we actually implement these algorithms on real machines?''
\begin{itemize}
	\item We need a way to define a parallel environment in which every processor is accounted for,
	\item We need to have data formats that are aware of the fact that we have a \emph{distributed} memory,
	\item We need to exchange data between the various memory fragments.
\end{itemize}
\end{frame}

\begin{frame}{Message Passing Interface -- \url{https://www.mpi-forum.org/}}

\begin{quote}
	``MPI (Message Passing Interface) is a \alert{specification for a standard library} for message passing that was defined by the MPI Forum, a broadly based group of parallel computer vendors, library writers, and applications specialists.'' -- W. Gropp, E. Lusk, N. Doss, A. Skjellum,
	\emph{A high-performance, portable implementation of the MPI message passing interface standard}, Parallel Computing, 22 (6), 1996.
\end{quote}

\begin{itemize}
	\item<2-> MPI implementations consist of a specific set of routines directly callable from C, C++, Fortran;
	\item<3-> MPI uses Language Independent Specifications for calls and language bindings;
	\item<4-> The MPI interface provides an essential \emph{virtual} topology, synchronization, and communication functionality inside a set of processes.
	\item<5-> There exist many implementations of the MPI specification, e.g., MPICH, Open MPI, pyMPI
\end{itemize}
\end{frame}

\subsection{Our First MPI Program}

\begin{frame}[fragile]{Hello (parallel) world!}
In all the course we are going to use the MPI inside C programs.
\begin{columns}
\begin{column}{0.4\columnwidth}
\begin{minted}{c}
#include"mpi.h"
#include<stdio.h>

int main(int argc,
	char **argv){
 MPI_Init( &argc, &argv);
 printf("Hello, world!\n");
 MPI_Finalize();
 return 0;
}
\end{minted}
\end{column}
\begin{column}{0.56\columnwidth}
\small
\begin{itemize}
	\item \mintinline{c}{#include "mpi.h"} provides basic MPI definitions and types,
	\item \mintinline{c}{MPI_Init} start MPI, it has to precede any MPI call!
	\item \mintinline{c}{MPI_Finalize} exits MPI
	\item All the non--MPI routines are local!
\end{itemize}
\end{column}
\end{columns}
\vfill
\onslide<2>{We need now to \emph{compile} and \emph{link} the \mintinline{bash}{helloworld.c} program, and we can do it simply by:
\
\mint{bash}{mpicc helloworld.c -o helloworld}
}
\end{frame}

\begin{frame}[fragile]{Hello (parallel) world! -- Compile, Link and Run}
\mint{bash}{mpicc helloworld.c -o helloworld}
\begin{itemize}
	\item \mintinline{bash}{mpicc} is a wrapper for a C compiler provided by the Open MPI implementation of MPI.
	\item the option \mintinline{bash}{-o} sets the name of the compiled (executable) file.
\end{itemize}
\onslide<2->{Let us see what is happening behind the curtains}
\begin{itemize}
	\item<2-> you can first try to discover what compiler are you using by executing \mintinline{bash}{mpicc --version}, \begin{onlyenv}<2>
that will give you something like
\begin{minted}{bash}
icc (ICC) 17.0.4 20170411
Copyright (C) 1985-2017 Intel Corporation.
All rights reserved.
\end{minted}
for an Intel compiler, or maybe
\begin{minted}{bash}
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
\end{minted}
	\end{onlyenv}
\item<3-> or discover what are the library inclusion and linking options by asking for \mintinline{bash}{mpicc --showme:compile} and \mintinline{bash}{mpicc --showme:link}, respectively.
\item<4-> In general, looking at the output of the \mintinline{bash}{man mpicc} command is always a good idea.
\end{itemize}
\only<5>{{\centering\small``If you find yourself saying, "But I don't want to use wrapper compilers!", please humor us and try them. See if they work for you. Be sure to let us know if they do not work for you. '' - {\scriptsize \url{https://www.open-mpi.org/faq/?category=mpi-apps}}}}
\end{frame}

\begin{frame}[fragile]{Hello (parallel) world! -- Compile, Link and Run}
A piece of advice: if your program is anything more realistic than a classroom exercise use \mintinline{bash}{make}\footnote{\url{https://www.gnu.org/software/make/}}, and save yourself from writing painfully long compiling commands, and dealing with complex dependencies more than once.

\begin{quote}
``Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files.''
\end{quote}

A very simple \mintinline{bash}{Makefile} for our first test would be
\begin{minted}{Makefile}
MPICC = mpicc #The wrapper for the compiler
CFLAGS += -g  #Useful for debug symbols
all: helloworld
helloworld: helloworld.c
  $(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
clean:
  rm -f helloworld
\end{minted}
\end{frame}

\begin{frame}[fragile]{Hello (parallel) world! -- Compile, Link and Run}
Let us run our first parallel program by doing:
\mint{bash}{mpirun [ -np X ] [ --hostfile <filename> ]  helloworld}
or by using its synonym
\mint{bash}{mpiexec [ -np X ] [ --hostfile <filename> ]  helloworld}
\begin{itemize}
	\item<1-> \mintinline{bash}{mpirun}/\mintinline{bash}{mpiexec} will  run  \mintinline{bash}{X} copies of \mintinline{bash}{helloworld} in your current run-time environment, scheduling (by default) in a round-robin fashion by CPU slot.
	\item<1-> if running under a supported resource manager, Open MPI's \mintinline{bash}{mpirun} will usually automatically use the corresponding resource manager process starter, as opposed to, for example, rsh or ssh, which require the use of a hostfile, or will default  to  running all \mintinline{bash}{X} copies on the localhost
	\item<2-> as always, look at the manual, by doing \mintinline{bash}{man mpirun}.
\end{itemize}

\end{frame}

\begin{frame}[fragile]{Hello (parallel) world! -- Compile, Link and Run}
If we now run
\mint{bash}{mpirun -np 6 helloworld}
we get the following output:
\begin{columns}
\begin{column}{0.4\columnwidth}
\begin{minted}{bash}
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
\end{minted}
\end{column}
\begin{column}{0.6\columnwidth}
Every process executes the line \mint{c}{printf("Hello, world!\n");} that it is a \alert{local} routine!
\end{column}
\end{columns}
\begin{block}<2>{local vs non-local procedure}
	A procedure is \textbf{local} if completion of the procedure depends only on the local executing process.

	A procedure is \textbf{non-local} if completion of the operation may require the execution of some MPI procedure on another process. Such an operation \emph{may require
	communication} occurring with another user process.
\end{block}
\end{frame}

\subsection{The MPI parallel environment}
\begin{frame}[fragile]{The MPI parallel environment}
Let us modify our \mintinline{bash}{helloworld} to investigate the MPI parallel environment. Specifically, we want to answer, from within the program, to the questions:
\begin{enumerate}
	\item How many processes are there?
	\item Who am I?
\end{enumerate}
\begin{minted}{c}
#include "mpi.h"
#include <stdio.h>
int main( int argc, char **argv ){
 int rank, size;
 MPI_Init( &argc, &argv );
 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
 MPI_Comm_size( MPI_COMM_WORLD, &size );
 printf( "Hello world! I'm process %d of %d\n",rank, size );
 MPI_Finalize();
 return 0;
}
\end{minted}
\end{frame}

\begin{frame}[fragile]{The MPI parallel environment}
\begin{minted}{c}
#include "mpi.h"
#include <stdio.h>
int main( int argc, char **argv ){
 int rank, size;
 MPI_Init( &argc, &argv );
 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
 MPI_Comm_size( MPI_COMM_WORLD, &size );
 printf( "Hello world! I'm process %d of %d\n",rank, size );
 MPI_Finalize();
 return 0;
}
\end{minted}
\begin{itemize}
	\item How many is answered by a call to \mintinline{c}{MPI_Comm_size} as an \mintinline{c}{int} value,
	\item Who am I? Is answered by a call to \mintinline{c}{MPI_Comm_rank} as an \mintinline{c}{int} value that is conventionally called \mintinline{c}{rank} and is a number between \mintinline{c}{0} and \mintinline{c}{size-1}.
\end{itemize}
\end{frame}

\begin{frame}{The MPI parallel environment}
	The last keyword we need to describe is the \mintinline{c}{MPI_COMM_WORLD}, this is the standard Communicator object.

	\begin{block}{Communicator}
	A Communicator object connects a group of processes in one MPI session. There can be more than one communicator in an MPI session, each of them gives each contained process an independent identifier and arranges its contained processes in an ordered topology.
	\end{block}

	This provides
	\begin{itemize}
	\item a safe communication space, that guarantees that the code can communicate as they
	need to, without conflicting with communication extraneous to the present code, e.g., if other parallel libraries are in use,
	\item a unified object for conveniently denoting communication context, the group of communicating processes and to house abstract process naming.
	\end{itemize}
\end{frame}

\begin{frame}[fragile]{The MPI parallel environment}
If we have saved our inquiring MPI program in the file \mintinline{bash}{hamlet.c}, we can then modify our \mintinline{bash}{Makefile} by modifying/adding the lines
\begin{minted}{Makefile}
all: helloworld hamlet
hamlet: hamlet.c
 $(MPICC) $(CFLAGS) $(LDFLAGS) $? $(LDLIBS) -o $@
clean:
 rm -f helloworld hamlet
\end{minted}
Then, we compile everything by doing \mintinline{bash}{make hamlet} (or, simply, \mintinline{bash}{make}).

\begin{onlyenv}<2->
When we run the code with \mintinline{bash}{mpirun -np 6 hamlet} we see
\begin{columns}
\begin{column}{0.5\columnwidth}
\begin{verbatim}
Hello world! I'm process 1 of 6
Hello world! I'm process 5 of 6
Hello world! I'm process 0 of 6
Hello world! I'm process 3 of 6
Hello world! I'm process 2 of 6
Hello world! I'm process 4 of 6
\end{verbatim}
\end{column}
\begin{column}{0.5\columnwidth}
\begin{itemize}
	\item<3-> Every processor answers the call,
	\item<4-> But it answers it as soon as he has done doing the computation! There is \alert{no synchronization}.
\end{itemize}
\end{column}
\end{columns}
\end{onlyenv}
\end{frame}

\subsection{When to travek the MPI road}
\begin{frame}{A word of advice}
When should you \textbf{not} write parallel code with MPI?
\begin{itemize}
	\item<1-> The effort of writing optimized and scalable MPI codes is not negligible, therefore a direct usage of it its usually best suited for developing \emph{libraries for scientific computations}.
	\item<2-> If there is a library containing a good (possibly open source) parallel implementation of the algorithm and the data structure you need: LEARN IT AND USE IT!
\end{itemize}
When should you write parallel code with MPI?
\begin{itemize}
	\item<3-> When you are learning about parallel computing with distributed memory!
	\item<4-> To \emph{really} understand what the instructions manuals of such parallel libraries are telling you,
	\item<5-> Sometimes it happens, you are using a library based on MPI and some function that you truly need is not included.
	\item<6-> To develop new and better libraries for your scientific challenge!
\end{itemize}
\end{frame}

\section{References}

\begin{frame}{References}
There are more books, notes, tutorials, online courses and oral tradition on scientific and parallel computing than we would have time to read and listen in a life. Pretty much everything that contains the words Parallel Programming and Scientific Computing is good\ldots

I suggest here the book
\begin{thebibliography}{10}
	\bibitem{rouson} Rouson, D., Xia, J., \& Xu, X. (2011). Scientific software design: the object-oriented way. Cambridge University Press.
\end{thebibliography}
that discusses general aspect of scientific computing (not perfectly related to parallel computing), and to have on your bedside
\begin{thebibliography}{10}
	\bibitem{mpimanual}  Message Passing Interface Forum. MPI: A Message-Passing Interface Standard, Version 3.1. \url{https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report.pdf}, High Performance Computing Center Stuttgart (HLRS).
\end{thebibliography}
\end{frame}

%\begin{frame}{Una storia che viene da lontano$\ldots$}
%\begin{columns}
%\begin{column}{0.20\textwidth}
%	\centering
%	\includegraphics[width=\columnwidth]{AdaLovelace.jpg}
%
%	\onslide<2->{Ada Lovelace}
%\end{column}
%\begin{column}{0.20\textwidth}
%	\centering
%	\includegraphics[width=\columnwidth]{JohnvonNeumann.jpg}
%
%	\onslide<3->{John von Neumann}
%\end{column}
%\begin{column}{0.20\textwidth}
%	\centering
%	\includegraphics[width=\columnwidth]{AlanTuring.jpg}
%
%	\onslide<4->{Alan Turing}
%\end{column}
%\begin{column}{0.20\textwidth}
%	\centering
%	\includegraphics[width=\columnwidth]{MargaretHamilton.jpg}
%
%	\onslide<5->{Margaret Hamilton}
%\end{column}
%\begin{column}{0.20\textwidth}
%	\centering
%	\includegraphics[width=\columnwidth]{KatherineJohnson.jpg}
%
%	\onslide<6->{Katherine Johnson}
%\end{column}
%\end{columns}
%\onslide<7>{
%s
%}
%\end{frame}

\end{document}

max_stars_repo_name: Cirdans-Home/intrompi

max_issues_repo_name: Cirdans-Home/intrompi

max_forks_repo_name: Cirdans-Home/intrompi