% Institute of Computer Science thesis template
% authors: Sven Laur, Liina Kamm, Tõnu Tamme
% last change Eero Vainikko <eero.vainikko@ut.ee> 12.01.2021


\documentclass[12pt]{article}

% A package for setting layout and margins for your thesis 
\usepackage[a4paper]{geometry}

%%=== A4 page setup ===
% \setlength{\paperwidth}{21.0cm} 
% \setlength{\paperheight}{29.7cm}
% \setlength{\textwidth}{16cm}
% \setlength{\textheight}{25cm}


\usepackage[utf8]{inputenc} %standard encoding since 2018 (can be commented out?)
\usepackage[T1]{fontenc} %Absolutely critical for *hyphenation* of words with non-ASCII letters.

% Typeset text in Times Roman instead of Computer Modern (EC)
\usepackage{times}

% Suggested packages:
\usepackage{microtype}  %towards typographic perfection...
\usepackage{inconsolata} %nicer font for code listings. (Use \ttfamily for lstinline bastype)

\usepackage[estonian, english]{babel} %the thesis is in English 

% Change Babel document elements 
\addto\captionsestonian{%
  \renewcommand{\refname}{Viidatud kirjandus}%
  \renewcommand{\appendixname}{Lisad}%
}

% General packages for math in general, theorems and symbols 
% Read ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf for further information
\usepackage{amsmath} 
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{algpseudocode}

% Print a dot instead of colon in table or figure captions
\usepackage[labelsep=period]{caption}

% Packages for building tables and tabulars 
\usepackage{array}
\usepackage{tabu}   % Wide lines in tables
\usepackage{xspace} % Non-eatable spaces in macros

% Including graphical images and setting the figure directory
\usepackage{graphicx}

\usepackage{minted}
% Packages for getting clickable links in PDF file
\usepackage[hidelinks]{hyperref} %hide red (blue,green) boxes around links
\usepackage[all]{hypcap}


% Packages for defining colorful text together with some colours
\usepackage{color}
\usepackage{xcolor} 
\definecolor{dkgreen}{rgb}{0,0.6,0.1}
% \definecolor{gray}{rgb}{0.5,0.5,0.5}
% \definecolor{mauve}{rgb}{0.58,0,0.82}

% Used to generate the table
\usepackage{booktabs}
\usepackage{tabularx}

% Standard package for drawing algorithms
% Since the thesis in article format we must define \chapter for
% the package algorithm2e (otherwise obscure errors occur) 
\let\chapter\section
% \usepackage[ruled, vlined, linesnumbered]{algorithm2e}
\usepackage{caption}
\usepackage{algorithm}


% Nice todo notes
\usepackage{todonotes}

% comments and verbatim text (code)
\usepackage{verbatim}


% Proper way to create coloured code listings
\usepackage{listings}
\lstset{ 
  %language=python,                % the language of the code
  language=C++,
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
  %numbers=left,                   % where to put the line-numbers
  % numberstyle=\footnotesize,      % the size of the fonts that are used for the line-numbers
  numberstyle=\tiny\color{gray}, 
  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line 
                                   % will be numbered
  numbersep=5pt,                   % how far the line-numbers are from the code
  backgroundcolor=\color{white},   % choose the background color. You must add \usepackage{color}
  showspaces=false,                % show spaces adding particular underscores
  showstringspaces=false,          % underline spaces within strings
  showtabs=false,                  % show tabs within strings adding particular underscores
  frame = lines,
  frame=single,                   % adds a frame around the code
  rulecolor=\color{black},		   % if not set, the frame-color may be changed on line-breaks within 
                                   % not-black text (e.g. commens (green here))
  tabsize=2,                       % sets default tabsize to 2 spaces
  captionpos=b,                    % sets the caption-position to bottom
  breaklines=true,                 % sets automatic line breaking
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  %title=\lstname,                 % show the filename of files included with \lstinputlisting;
                                   % also try caption instead of title
  keywordstyle=\color{blue},       % keywCurriculumord style
  % commentstyle=\color{dkgreen},    % comment style
  stringstyle=\color{mauve},       % string literal style
  escapeinside={\%*}{*)},          % if you want to add a comment within your code
  morekeywords={*,game, fun}       % if you want to add more keywords to the set
}

\newcommand\myworries[1]{\textcolor{red}{#1}}

% Obscure packages to write logic formulae and program semantics
% Unless you do a thesis on program semantics or static code analysis you do not need that
% http://logicmatters.net/resources/ndexamples/proofsty3.html <= writing type rules => use semantic::inference
% ftp://tug.ctan.org/tex-archive/macros/latex/contrib/semantic/semantic.pdf
\usepackage{proof}
\usepackage{semantic} 
\setlength{\inferLineSkip}{4pt}
\def\predicatebegin #1\predicateend{$\Gamma \vdash #1$}

% If you really want to draw figures in LaTeX use packages tikz or pstricks
% However, getting a corresponding illustrations is really painful  


% Define your favorite macros that you use inside the thesis 
% Name followed by non-removable space
\newcommand{\proveit}{ProveIt\xspace}

% Macros that make sure that the math mode is set
\newcommand{\typeF}[1] {\ensuremath{\mathsf{type_{#1}}}\xspace}
\newcommand{\opDiv}{\ensuremath{\backslash \mathsf{div}}\xspace} 

\newcommand{\cg}{Conjugate Gradient}
\newcommand{\ddm}{Domain Decomposition Method}
\newcommand{\bcg}{Block Conjugate Gradient}
\newcommand{\gmres}{Generalized Minimal Residual Method}
\newcommand{\fgmres}{Flexible Generalized Minimal Residual Method}
\newcommand{\oc}{OpenCL}
\newcommand{\as}{Additive Schwarz}
\newcommand{\raas}{Restricted Additive Average Schwarz}

% Nice Todo box
\setlength{\marginparwidth}{2cm}
\newcommand{\TODO}{\todo[inline]}

% A way to define theorems and lemmata
\newtheorem{theorem}{Theorem}



%%% BEGIN DOCUMENT
\begin{document}

%===BEGIN TITLE PAGE
\thispagestyle{empty}
\begin{center}

\large
\iflanguage{english}{%
UNIVERSITY OF TARTU\\
Faculty of Science and Technology\\
Institute of Computer Science\\
Computer Science Curriculum\\
%Software Engineering Curriculum\\
}{%\iflanguage
TARTU ÜLIKOOL\\
Loodus- ja täppisteaduste valdkond\\
Arvutiteaduse instituut\\
Informaatika õppekava\\
}%\iflanguage

\vspace{25mm}

\Large Ziya Mammadov

\vspace{4mm}

\huge GPU-accelerated Domain Decomposition Methods for Helmholtz equation

\vspace{20mm}

\Large
\iflanguage{english}{%
%Bachelor's Thesis (9 ECTS)
Master's Thesis (30 ECTS)
}{%\iflanguage
Magistritöö (30 EAP)
}%\iflanguage

\end{center}

\vspace{2mm}

\begin{flushright}
 {
 \setlength{\extrarowheight}{5pt}
 \begin{tabular}{r l} 
  \sffamily \iflanguage{english}{Supervisor(s)}{Juhendaja(d)}: & \sffamily  Prof. Eero Vainikko
             
 \end{tabular}
 }
\end{flushright}

\vfill
\centerline{\large Tartu \the\year}

%===END TITLE PAGE

% If the thesis is printed on both sides of the page then 
% the second page must be must be empty. Comment this out
% if you print only to one side of the page comment this out
%\newpage
%\thispagestyle{empty}    
%\phantom{Text to fill the page}
% END OF EXTRA PAGE WITHOUT NUMBER


%===COMPULSORY INFO PAGE
\newpage

%=== Info in English
\newcommand\EngInfo{{%
\selectlanguage{english}
\noindent\textbf{\large GPU-accelerated Domain Decomposition Methods for Helmholtz equation}

\vspace*{3ex}

\noindent\textbf{Abstract:}

\noindent

The Helmholtz equation, used in various fields like acoustics, optics, and seismology, is a partial differential equation that describes how waves propagate in various physical systems. The Helmholtz matrix arises from the discretization of the Helmholtz problem when solving the Helmholtz equation numerically using finite difference or finite element methods. In practice, the numerical solution of the Helmholtz equation can be challenging due to the size of the discredited problem as well as the spectral properties of the matrix. The thesis explores iterative methods to solve the Helmholtz equation, speeding up the computations by using the power of GPUs. A special domain decomposition preconditioning technique, the Restricted Additive Average Schwarz method, is applied in a setup that allows using multiple subdomains to solve simultaneously in one go on a GPU. For this purpose a special implementation of the Conjugate Gradients iterative solver in PyOpenCL using complex arithmetics was developed, allowing to solve for multiple right-hand side vectors simultaneously. Performance evaluation for the overall solution of the discretized Helmholtz equation is performed experimentally to compare the efficiency of different subdomain solution techniques.

\vspace*{1ex}

\noindent\textbf{Keywords:}\\
GPU programming, Conjugate Gradient method, Iterative methods, Domain Decomposition, OpenCL, PyOpenCL
%Layout, formatting, template

\vspace*{1ex}

\noindent\textbf{CERCS:}\\
P130 - Functions, differential equations, P170 - Computer science, numerical analysis, systems, control

\vspace*{1ex}
}}%\newcommand\EngInfo


%=== Info in Estonian
\newcommand\EstInfo{{%
\selectlanguage{estonian}
\newpage
\noindent\textbf{\large GPU-kiirendatud alampiirkondadeks jagamise meetodid Helmholtzi võrrandi jaoks}
\vspace*{3ex}

\noindent\textbf{Lühikokkuvõte:} 

\noindent

Helmholtzi võrrand, mida kasutatakse erinevates valdkondades, näiteks akustika, optika ja seismoloogia, on osatuletistega diferentsiaalvõrrand, mis kirjeldab lainete tekkimist erinevates füüsikalistes süsteemides. Helmholtzi maatriks saadakse antud ülesande diskretiseerimisel numbriliseks lahendamiseks, kasutades lõplike diferentside või lõplike elementide meetodeid. Praktikas võib Helmholtzi võrrandi numbriline lahendamine olla keerukas nii probleemi suuruse kui ka maatriksi spektraalsete omaduste tõttu. Käesolev lõputöö uurib iteratiivseid meetodeid Helmholtzi võrrandi lahendamiseks kiirendades arvutusi kasutades GPU võimsust. Iteratiivses protsessis rakendatakse eelkonditsioneerijana spetsiaalset alampiirkondadeks jagamise meetodit, Restricted Additive Schwarz'i meetodit, mis võimaldab GPU-d kasutada samaaegselt mitme alampiirkonna lahendajana. Sel eesmärgil sai realiseeritud spetsiaalne Kaasgradientide kompleksarvuline blokk-lahendaja PyOpenCL-s mitme samaaegse parempoole vektori jaoks. Sooritatakse eksperimente diskretiseeritud Helmholtzi võrrandi lahenduse jõudluse hindamiseks, võrreldakse erinevate tehnikate tõhusust sõltuvalt alampiirkondade lahendamiseks kasutatavast meetodist.
\vspace*{1ex}

\noindent\textbf{Võtmesõnad:}\\
GPU-programmeerimine, Kaasgradientide meetod, Iteratiivsed meetodid, Alampiirkondadeks jagamise meetod, OpenCL, PyOpenCL
\\

%Layout, formatting, template

\vspace*{1ex}

\noindent\textbf{CERCS:}\\P130 - Funktsioonid, diferentsiaalvõrrandid, P170 - Arvutiteadus, arvutusmeetodid, süsteemid, juhtimine (automaatjuhtimisteooria)

\vspace*{1ex}
}}%\newcommand\EstInfo


%=== Determine the order of languages on the Info page
\iflanguage{english}{\EngInfo}{\EngInfo}
\iflanguage{estonian}{\EngInfo}{\EstInfo}

\newpage
\noindent\textbf{List of abbreviations and terms:} \\

\begin{tabular}{l l}

\textbf{PDE} &  Partial Differential Equation \\
\textbf{CG} & Conjugate Gradient \\
\textbf{GMRES} & Generalized Minimal Residual
Method\\
\textbf{GMRES(m)} & Restarted GMRES\\
\textbf{FGMRES} & Flexible Generalized Minimal Residual
Method\\
\textbf{ILU} & Incomplete Cholesky Factorisation\\
\textbf{DDM} & Domain Decomposition Method\\
\textbf{RAS} & Restricted Additive Schwarz \\
\textbf{RAAS} & Restricted Additive Average Schwarz \\
\textbf{GAS} & Generalized Additive Schwarz \\
\textbf{GPU} & Graphics Processing Units \\
\textbf{CPU} & Central Processing Units \\
\textbf{FPGA} & Field Programmable Gate Arrays \\
\textbf{BDD} & Balancing Domain Decomposition \\
\textbf{GPGPU} & General-purpose computing on graphics processing units \\
\end{tabular}

\listoftables

\listoffigures

\listofalgorithms

\lstlistoflistings
\newpage
\tableofcontents

\newpage
\section{Introduction}
\input{sections/introduction}

\newpage
\section{Background}
\input{sections/background}


\newpage
\section{Data and methods}
\input{sections/methods.tex}

\newpage
\section{Results}
\input{sections/results}

\newpage
\section{Discussion}
\input{sections/discussions}

\newpage
\section{Conclusion}
\input{sections/conclusion}


\newpage
\section{Acknowledgements}
\label{acknowledgements}
I am grateful for the support and guidance I received during my studies at the University of Tartu. I would like to express my deepest appreciation to my supervisor, Professor Eero Vainikko, whose invaluable comments and unwavering support were essential to my work on this thesis. His expertise and insight have greatly enriched my learning experience and research.

I am also immensely thankful to the University of Tartu for providing access to the High-Performance Computing Center. This resource was crucial in allowing me to leverage the power of GPUs to conduct my experiments.

To all who supported me throughout my academic journey—thank you for your encouragement, for believing in my potential, and for helping me achieve this milestone.
\newpage

% BibTeX bibliography
\bibliographystyle{alpha} %plain=[1], alpha=[BGZ09]
\bibliography{sections/references}

\addcontentsline{toc}{section}{\refname}


\newpage
%\appendix
%\section*{\appendixname}
\iflanguage{english}%
  {\section*{Appendix}
  \addcontentsline{toc}{section}{Appendix}
  }%
  {\section*{Lisad}
  \addcontentsline{toc}{section}{Lisad}}
  
  
\section*{I. Access to Code}
The code used to obtain the results can be found in this GitHub repository given below:
\url{https://github.com/ziyamammadov/conjugate-gradient-pyopencl}
\addcontentsline{toc}{subsection}{I. Access to Code}

\newpage

%=== Licence in English
\newcommand{\licencehint}[2]{\\\hspace*{#1}\textsl(#2)\par}
\newcommand\EngLicence{{%
\selectlanguage{english}
\section*{II. Licence}

\addcontentsline{toc}{subsection}{II. Licence}

\subsection*{Non-exclusive license to reproduce thesis and make thesis public}

I, \textbf{Ziya Mammadov}, %author's name
  \licencehint{10mm}{author's name}

\begin{enumerate}
\item
herewith grant the University of Tartu a free permit (non-exclusive licence) to
\par
reproduce, for the purpose of preservation, including for adding to the DSpace digital archives until the expiry of the term of copyright,
\par
\textbf{GPU-accelerated Domain Decomposition Methods for Helmholtz equation}, %
  \licencehint{10mm}{title of thesis}
\par
supervised by Eero Vainikko. %supervisor's name
  \licencehint{10mm}{supervisor's name}
\item
I grant the University of Tartu a permit to make the work specified in p. 1 available to the public via the web environment of the University of Tartu, including via the DSpace digital archives, under the Creative Commons licence CC BY NC ND 3.0, which allows, by giving appropriate credit to the author, to reproduce, distribute the work and communicate it to the public, and prohibits the creation of derivative works and any commercial use of the work until the expiry of the term of copyright.
\item
I am aware of the fact that the author retains the rights specified in p. 1 and 2.
\item
I certify that granting the non-exclusive licence does not infringe other persons' intellectual property rights or rights arising from the personal data protection legislation. 
\end{enumerate}

\noindent
Ziya Mammadov\\ %author's name
\textbf{\textsl{15/05/2024}}
}}%\newcommand\EngLicence


%=== Licence in Estonian
\newcommand\EstLicence{{%
\selectlanguage{estonian}
\section*{II. Litsents}

\addcontentsline{toc}{subsection}{II. Litsents}

\subsection*{Lihtlitsents lõputöö reprodutseerimiseks ja üldsusele kättesaadavaks tegemiseks}

Mina, \textbf{Alice Cooper}, %author's name
  \licencehint{10mm}{autori nimi}

\begin{enumerate}
\item
annan Tartu Ülikoolile tasuta loa (lihtlitsentsi) minu loodud teose
\par
\textbf{Tüübituletus neljandat järku loogikavalemitele}, %title of thesis
    \licencehint{10mm}{lõputöö pealkiri}
\par
mille juhendaja(d) on Axel Rose ja May Flower, %supervisor's name(s)
  \licencehint{10mm}{juhendaja nimi}
\par
reprodutseerimiseks eesmärgiga seda säilitada, sealhulgas lisada digitaalarhiivi DSpace kuni autoriõiguse kehtivuse lõppemiseni.
\par
\item
Annan Tartu Ülikoolile loa teha punktis 1 nimetatud teos üldsusele kättesaadavaks Tartu Ülikooli veebikeskkonna, sealhulgas digitaalarhiivi DSpace kaudu Creative Commonsi litsentsiga CC BY NC ND 3.0, mis lubab autorile viidates teost reprodutseerida, levitada ja üldsusele suunata ning keelab luua tuletatud teost ja kasutada teost ärieesmärgil, kuni autoriõiguse kehtivuse lõppemiseni.
\item
Olen teadlik, et punktides 1 ja 2 nimetatud õigused jäävad alles ka autorile.
\item
Kinnitan, et lihtlitsentsi andmisega ei riku ma teiste isikute intellektuaalomandi ega isikuandmete kaitse õigusaktidest tulenevaid õigusi. 
\end{enumerate}

\noindent
Alice Cooper\\ %author's name
\textbf{\textsl{pp.kk.aaaa}}
}}%\newcommand\EstLicence


%===Choose the licence in active language
\iflanguage{english}{\EngLicence}{\EstLicence}


\end{document}

