diff --git a/lecture2/Packages.tex b/lecture2/Packages.tex new file mode 100644 index 0000000..5b7e76d --- /dev/null +++ b/lecture2/Packages.tex @@ -0,0 +1,24 @@ +% Load Packages +\usepackage[utf8]{inputenc} +\usepackage{xcolor} +\usepackage{tikz} +\usetikzlibrary{positioning,calc} +\usepackage{graphicx} +\usepackage{hyperref} +\usepackage{amsmath} +\usepackage{listings} +\usepackage{fontawesome} +\usepackage[T2A]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage[russian]{babel} + +% Define Commands +\newcommand*{\ClipSep}{0.06cm} %To adjust footer logo +\newcommand{\E}{\mathrm{e}\,} %\def\I{e} % used to defined e for exp(x), see later what it should be +\newcommand{\ud}{\mathrm{d}} +\lstset{numbers=left, numberstyle=\tiny, stepnumber=1,firstnumber=1,breaklines=true, + numbersep=5pt,language=Python, + stringstyle=\ttfamily, + basicstyle=\footnotesize, + showstringspaces=false +} diff --git a/lecture2/atomic.png b/lecture2/atomic.png new file mode 100644 index 0000000..d67b806 Binary files /dev/null and b/lecture2/atomic.png differ diff --git a/lecture2/beamercolorthemeoxonian.sty b/lecture2/beamercolorthemeoxonian.sty new file mode 100644 index 0000000..e910a59 --- /dev/null +++ b/lecture2/beamercolorthemeoxonian.sty @@ -0,0 +1,29 @@ +% Dictates which colours are used +\ProvidesPackage{beamercolorthemeoxonian} + +\mode +% Define Colours +\definecolor{oxfordblue}{RGB}{0,32,68} +\definecolor{glassgrey}{rgb}{220,220,220} + +% Set Colours +\setbeamercolor{title}{parent=oxfordblue} +\setbeamercolor{title}{fg=oxfordblue} +\setbeamercolor{subtitle}{parent=oxfordblue} +\setbeamercolor{author}{parent=glassgrey} +\setbeamercolor{date}{parent=oxfordblue} +\setbeamercolor{institute}{parent=oxfordblue} + +\setbeamercolor{section title}{parent=oxfordblue} +\setbeamercolor{subsection title}{parent=oxfordblue} +\setbeamercolor{frametitle}{parent=oxfordblue} +\setbeamercolor{background canvas}{parent=oxfordblue} +\setbeamercolor{structure}{fg=oxfordblue} + +\setbeamercolor{normal text}{fg=black!97} + +\setbeamercolor{footnote}{fg=black!97} +\setbeamercolor{page number in head/foot}{fg=oxfordblue} + +\mode + diff --git a/lecture2/beamerfontthemeoxonian.sty b/lecture2/beamerfontthemeoxonian.sty new file mode 100644 index 0000000..457d14a --- /dev/null +++ b/lecture2/beamerfontthemeoxonian.sty @@ -0,0 +1,5 @@ +% Dictates which fonts/font attributes are used +\ProvidesPackage{beamerfontthemeoxonian} + +\usefonttheme{serif} +\setbeamerfont{institute}{size=\small} diff --git a/lecture2/beamerinnerthemeoxonian.sty b/lecture2/beamerinnerthemeoxonian.sty new file mode 100644 index 0000000..d697a87 --- /dev/null +++ b/lecture2/beamerinnerthemeoxonian.sty @@ -0,0 +1,86 @@ +% Specify how elements are typeset inside the frame +\ProvidesPackage{beamerinnerthemeoxonian} + +% --- Title Page --- +\makeatletter +\setbeamertemplate{title page} +{ + \vbox{} + \vfill + \begin{centering} + \vskip0.25em% + \begin{beamercolorbox}[sep=8pt,center]{title} + \usebeamerfont{title}\inserttitle\par% + \ifx\insertsubtitle\@empty% + \else% + \vskip0.25em% + {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% + \fi% + \end{beamercolorbox}% + \vskip2.25em% + {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par} + \vskip1em\par + \begin{beamercolorbox}[sep=8pt,center]{author} + \usebeamerfont{author}\insertauthor + \end{beamercolorbox} + \vspace{-10pt} + \begin{beamercolorbox}[sep=8pt,center]{institute} + \usebeamerfont{institute}\insertinstitute + \end{beamercolorbox} + \begin{beamercolorbox}[sep=8pt,center]{date} + \usebeamerfont{date}\insertdate + \end{beamercolorbox}\vskip0.5em + \end{centering} + \vfill +} +\makeatother + +% --- Footer --- +%Remove Navigation Bars +\setbeamertemplate{footline}[frame number]{} +% And Symbols +\setbeamertemplate{navigation symbols}{} +% Design +\setbeamertemplate{footline}{ +\begin{tikzpicture}[remember picture,overlay] + \coordinate (West) at (0,0.5); + \coordinate (East) at (\textwidth,0.5); + + \draw[oxfordblue, very thick] (West) -- (East); + +% \node [inner sep=0pt,clip,rounded corners=0.1cm] (oxlogo) at (0.85\textwidth,0.5); + +% {\includegraphics[width=.16\textwidth]{../Theme/Logos/OxfordLogoV3.png}}; + +\end{tikzpicture}} + +% --- Header --- +\setbeamertemplate{frametitle}{ + + \begin{beamercolorbox}[wd=\paperwidth,ht=2.75ex,dp=1.375ex]{frametitle} + \hspace*{2ex}\insertframetitle \hfill {\small\insertframenumber} \hspace*{1ex} + \end{beamercolorbox} + + \par + + \begin{tikzpicture}[remember picture,overlay] + + \coordinate (LeftEnd) at (-1, 0.5); + \coordinate (LeftEndUnder) at (-1, 0.1); + \coordinate (RightEnd) at (3,0.5); + \draw[oxfordblue, thick, fill=oxfordblue] (LeftEnd)--(RightEnd)--(LeftEndUnder) -- (LeftEnd); + + \coordinate (RightEnd) at (\paperwidth, 0.1); + \coordinate (PreRightEnd) at (10, 0.1); + \draw[oxfordblue,thick] (RightEnd) -- (PreRightEnd); + + \end{tikzpicture} + + +} + +% --- Table of Content --- +% Might modify later (next version) + +% --- Sidebar of Content --- +% Might add later (next version) diff --git a/lecture2/beamerouterthemeoxonian.sty b/lecture2/beamerouterthemeoxonian.sty new file mode 100644 index 0000000..ab52702 --- /dev/null +++ b/lecture2/beamerouterthemeoxonian.sty @@ -0,0 +1,16 @@ +% Specify the outside/border (ex. logo, navigation, sidebar) +\ProvidesPackage{beamerouterthemeoxonian} + +% If you want Section Page to be automatically generated +% \AtBeginSection[]{ +% \begin{frame}[plain] +% \vfill +% \centering +% \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title} +% \usebeamerfont{title}\insertsectionhead\par% +% \color{oxfordblue}\noindent\rule{10cm}{1pt} \\ +% \LARGE{\faFileCodeO} +% \end{beamercolorbox} +% \vfill +% \end{frame} +% } diff --git a/lecture2/beamerthemeoxonian.sty b/lecture2/beamerthemeoxonian.sty new file mode 100644 index 0000000..f01cf60 --- /dev/null +++ b/lecture2/beamerthemeoxonian.sty @@ -0,0 +1,16 @@ +% Copyright 2019 Clara Eleonore Pavillet + +% Author: Clara Eleonore Pavillet +% Description: This is an unofficial Oxford University Beamer Template I made from scratch. Feel free to use it, modify it, share it. +% Version: 1.0 + +\ProvidesPackage{beamerthemeoxonian} +\mode + +\usefonttheme{oxonian} +\usecolortheme{oxonian} +\useinnertheme{oxonian} +\useoutertheme{oxonian} + +\mode + diff --git a/lecture2/compilaton-process.png b/lecture2/compilaton-process.png new file mode 100644 index 0000000..da49073 Binary files /dev/null and b/lecture2/compilaton-process.png differ diff --git a/lecture2/firstprivate.png b/lecture2/firstprivate.png new file mode 100644 index 0000000..74b0fe6 Binary files /dev/null and b/lecture2/firstprivate.png differ diff --git a/lecture2/fork-join.png b/lecture2/fork-join.png new file mode 100644 index 0000000..598a9d8 Binary files /dev/null and b/lecture2/fork-join.png differ diff --git a/lecture2/iaps.png b/lecture2/iaps.png new file mode 100644 index 0000000..f223cc9 Binary files /dev/null and b/lecture2/iaps.png differ diff --git a/lecture2/master-thread.png b/lecture2/master-thread.png new file mode 100644 index 0000000..85ed532 Binary files /dev/null and b/lecture2/master-thread.png differ diff --git a/lecture2/multi-thread.png b/lecture2/multi-thread.png new file mode 100644 index 0000000..b6b70bf Binary files /dev/null and b/lecture2/multi-thread.png differ diff --git a/lecture2/openmp-standards.png b/lecture2/openmp-standards.png new file mode 100644 index 0000000..95b13c8 Binary files /dev/null and b/lecture2/openmp-standards.png differ diff --git a/lecture2/openmp-variants.png b/lecture2/openmp-variants.png new file mode 100644 index 0000000..3914688 Binary files /dev/null and b/lecture2/openmp-variants.png differ diff --git a/lecture2/openmp.pdf b/lecture2/openmp.pdf new file mode 100644 index 0000000..5dd3776 Binary files /dev/null and b/lecture2/openmp.pdf differ diff --git a/lecture2/openmp.tex b/lecture2/openmp.tex new file mode 100644 index 0000000..6b98559 --- /dev/null +++ b/lecture2/openmp.tex @@ -0,0 +1,289 @@ +% Copyright 2019 Clara Eleonore Pavillet + +% Author: Clara Eleonore Pavillet +% Description: This is an unofficial Oxford University Beamer Template I made from scratch. Feel free to use it, modify it, share it. +% Version: 1.0 + +\documentclass{beamer} +\usepackage{pdfpages} +\input{Packages.tex} +\usetheme{oxonian} +\usepackage{wrapfig} +\usepackage{listings} + +\title{Въведение в OpenMP.} +\subtitle{\textit{Курс „Паралелно програмиране“}} +\titlegraphic{{\includegraphics[width=5.3cm]{iaps.png}}} + +\author{\newline \newline Стоян Мишев} + +\vspace{1cm} + +\date{} %\today + +\begin{document} +\lstset{language=Python} +{\setbeamertemplate{footline}{} +\frame{\titlepage}} + + +\section*{План}\begin{frame}{План}\tableofcontents\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}{Определение на OpenMP} + + \url{https://www.openmp.org/} + + \textbf{Стандарт} за писане на програми за създаване и управление на нишки. \pause + + Има варианти за С, С++, Фортран и др. \pause + + \textbf{Нишка} е част от програма, която има достъп до \textit{собствена} част от паметта, както и до общи ресурси за компютъра - памет, външни устройства, мрежа и т.н. \pause + + Лекцията е на основата на клипа \url{https://www.youtube.com/watch?v=IsBgW7-yldA} + +\end{frame} + + +\begin{frame}{Версии на OpenMP} + \includegraphics[width=\textwidth]{openmp-standards.png} +\end{frame} + +\begin{frame}{Версии на OpenMP} + \includegraphics[width=\textwidth]{openmp-variants.png} +\end{frame} + +\begin{frame}{Създаване и \textit{обединяване} на нишки} + \includegraphics[width=\textwidth]{fork-join.png} +\end{frame} + +\begin{frame}[fragile]{Създаване на нишки} + + \includegraphics[width=0.8\textwidth]{master-thread} + \begin{lstlisting} + #pragma omp parallel{ + printf("hi from %d\n", omp_get_num_thread()); + + #pragma omp master{ + printf("This shows once \n"); + } + + } + \end{lstlisting} +\end{frame} + +\begin{frame}{Хардуерни възможности и софтуерна абстракция} + \includegraphics[width=\textwidth]{soft-hard} +\end{frame} + +\begin{frame}[plain]{Хардуерни възможности и софтуерна абстракция} + \includegraphics[width=\textwidth]{soft-hard1} +\end{frame} + +\begin{frame}{Една и много нишки} + \centering + \includegraphics[width=0.2\textwidth]{single-thread} \pause + + \includegraphics[width=0.6\textwidth]{multi-thread.png} + +\end{frame} + + +\begin{frame}{Shared} + \includegraphics[width=\textwidth]{shared} +\end{frame} + + +\begin{frame}[fragile]{Shared} +\lstset{language=C++} + \begin{lstlisting} +#include +#include + + +int main() { + int i = 0; + + #pragma omp parallel shared(i) num_threads(10000) + { + i++; + } + + printf("i = %d\n",i); + return 0; +} + \end{lstlisting} +\end{frame} + +\begin{frame}{Atomic} + \includegraphics[width=\textwidth]{atomic} +\end{frame} + +\begin{frame}[fragile]{Atomic} +\lstset{language=C++} + \begin{lstlisting} +#include +#include + + +int main() { + int i = 0; + + #pragma omp parallel shared(i) num_threads(10000) + { + #pragma omp atomic + i++; + } + + printf("i = %d\n",i); + return 0; +} + \end{lstlisting} +\end{frame} + +\begin{frame}{Private} + \includegraphics[width=\textwidth]{private} +\end{frame} + +\begin{frame}[fragile]{Private} +\lstset{language=C++} +\begin{lstlisting} +#include +#include +#include + + +int main() { + int i = 999; + + printf("i is %d before parallel region\n",i); + + #pragma omp parallel private(i) num_threads(10) + { + printf("Thread %d sees %d on memory %lx\n", omp_get_thread_num(), i, (unsigned long)&i); + } + + return 0; +} + \end{lstlisting} +\end{frame} + +\begin{frame}{Firstprivate} + \includegraphics[width=\textwidth]{firstprivate} +\end{frame} + +\begin{frame}[fragile]{Firstprivate} +\lstset{language=C++} +\begin{lstlisting} +#include +#include +#include + + +int main() { + int i[3] = {999,888,666}; + + printf("i is [%d,%d,%d] before parallel region\n",i[0],i[1],i[2]); + + #pragma omp parallel firstprivate(i) num_threads(10) + { + printf("Thread %d sees [%d,%d,%d] on memory %lx\n", omp_get_thread_num(), i[0],i[1],i[2], (unsigned long)i); + } + + return 0; +} + \end{lstlisting} +\end{frame} + + +\begin{frame}[fragile]{Reduction} + \includegraphics[width=\textwidth]{reduction} +\end{frame} + +\begin{frame}[fragile]{Reduction} +\lstset{language=C++} +\begin{lstlisting} +#include +#include + + +int main() { + int i = 99; + + printf("Value if i prior to parallel region is %d\n",i); + + // Private values are not transferred back + #pragma omp parallel private(i) + { + i=1000; + } + printf("Value if i after parallel region with private(i) is %d\n",i); + + i = 0; + // Reductions for addition. + #pragma omp parallel reduction(+:i) num_threads(10) + { + i=1; + } + printf("Value if i after parallel region with reduction(+:i) is %d\n",i); + + // Reductions for max. + #pragma omp parallel reduction(max:i) num_threads(20) + { + i=omp_get_thread_num(); + } + printf("Value if i after parallel region with reduction(max:i) is %d\n",i); + + return 0; +} + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile]{Домашна работа} + 1. Прегледайте видеото на \url{https://www.youtube.com/watch?v=IsBgW7-yldA}. + + 2. Компилирайте ``сорс''-овете от + \url{https://github.com/josemonsalve2/openmp_tutorial/blob/main/Labs/Lab1/C} + на \verb+neutronstar.iaps.institute+ или другаде. +\end{frame} + + +\begin{frame}{Реализация на OpenMP в различните компилатори} + \url{https://www.openmp.org/resources/openmp-compilers-tools/} +\end{frame} + + +\begin{frame}{Синтаксис. Понятия.} + \includegraphics[width=\textwidth]{terms-pragma} +\end{frame} + +\begin{frame}{Компилиране} + \includegraphics[width=\textwidth]{compilaton-process.png} +\end{frame} + +\begin{frame}[fragile]{Function outlining} + \lstset{language=C++} +\begin{lstlisting} + #pragma omp parallel{ + printf("hello world\n"); + } +\end{lstlisting} + +\begin{lstlisting} + void outlined_function(void* params) + { + printf("hello world\n"); + } + + __runtime_omp_parallel(outlined_function, params); +\end{lstlisting} + +\end{frame} + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: t +%%% End: diff --git a/lecture2/openmp.tex~ b/lecture2/openmp.tex~ new file mode 100644 index 0000000..7c2c439 --- /dev/null +++ b/lecture2/openmp.tex~ @@ -0,0 +1,45 @@ +% Copyright 2019 Clara Eleonore Pavillet + +% Author: Clara Eleonore Pavillet +% Description: This is an unofficial Oxford University Beamer Template I made from scratch. Feel free to use it, modify it, share it. +% Version: 1.0 + +\documentclass{beamer} +\usepackage{pdfpages} +\input{Packages.tex} +\usetheme{oxonian} +\usepackage{wrapfig} +\usepackage{listings} + +\title{Въведение в паралелните изчисления} +\subtitle{\textit{Курс „Паралелни изчисления“}} +\titlegraphic{{\includegraphics[width=5.3cm]{iaps.png}}} + +\author{\newline \newline Стоян Мишев} + +\vspace{1cm} + +%\institute{\url{https://facebook.com/nbudatascience}} + +\date{} %\today + +\begin{document} +\lstset{language=Python} +{\setbeamertemplate{footline}{} +\frame{\titlepage}} + + +\section*{План}\begin{frame}{План}\tableofcontents\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}{} + +\end{frame} + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: t +%%% End: diff --git a/lecture2/private.png b/lecture2/private.png new file mode 100644 index 0000000..4ad7918 Binary files /dev/null and b/lecture2/private.png differ diff --git a/lecture2/reduction.png b/lecture2/reduction.png new file mode 100644 index 0000000..4b37d94 Binary files /dev/null and b/lecture2/reduction.png differ diff --git a/lecture2/shared.png b/lecture2/shared.png new file mode 100644 index 0000000..ca01696 Binary files /dev/null and b/lecture2/shared.png differ diff --git a/lecture2/single-thread.png b/lecture2/single-thread.png new file mode 100644 index 0000000..c9b33bb Binary files /dev/null and b/lecture2/single-thread.png differ diff --git a/lecture2/soft-hard.png b/lecture2/soft-hard.png new file mode 100644 index 0000000..2a26bbd Binary files /dev/null and b/lecture2/soft-hard.png differ diff --git a/lecture2/soft-hard1.png b/lecture2/soft-hard1.png new file mode 100644 index 0000000..3813238 Binary files /dev/null and b/lecture2/soft-hard1.png differ diff --git a/lecture2/terms-pragma.png b/lecture2/terms-pragma.png new file mode 100644 index 0000000..060ae1b Binary files /dev/null and b/lecture2/terms-pragma.png differ