\chapter{The ir-\/ilu-\/preconditioned-\/solver program }
\hypertarget{ir_ilu_preconditioned_solver}{}\label{ir_ilu_preconditioned_solver}\index{The ir-\/ilu-\/preconditioned-\/solver program@{The ir-\/ilu-\/preconditioned-\/solver program}}
The IR-\/\+ILU preconditioned solver example.

This example depends on ilu-\/preconditioned-\/solver, iterative-\/refinement.

 \label{three_pt_stencil_solver_Intro}%
\Hypertarget{three_pt_stencil_solver_Intro}%
 \label{three_pt_stencil_solver_Introduction}%
\Hypertarget{three_pt_stencil_solver_Introduction}%
\doxysection*{Introduction}

\label{three_pt_stencil_solver_Abouttheexample}%
\Hypertarget{three_pt_stencil_solver_Abouttheexample}%
\doxysubsubsection*{About the example }

This example shows how to combine iterative refinement with the adaptive precision block-\/\+Jacobi preconditioner in order to approximately solve the triangular systems occurring in ILU preconditioning. Using an adaptive precision block-\/\+Jacobi preconditioner matrix as inner solver for the iterative refinement method is equivalent to doing adaptive precision block-\/\+Jacobi relaxation in the triangular solves. This example roughly approximates the triangular solves with five adaptive precision block-\/\+Jacobi sweeps with a maximum block size of 16.

This example is motivated by "{}\+Multiprecision block-\/\+Jacobi for Iterative \+Triangular Solves"{} (Göbel, Anzt, Cojean, Flegar, Quintana-\/\+Ortí, Euro-\/\+Par 2020). The theory and a detailed analysis can be found there. \label{three_pt_stencil_solver_CommProg}%
\Hypertarget{three_pt_stencil_solver_CommProg}%
 \doxysection*{The commented program}


\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Usage:\ "{}}\ <<\ argv[0]\ <<\ \textcolor{stringliteral}{"{}\ [executor]"{}}\ <<\ std::endl;}
\DoxyCodeLine{\ \ \ \ std::exit(-\/1);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ executor\_string\ =\ argc\ >=\ 2\ ?\ argv[1]\ :\ \textcolor{stringliteral}{"{}reference"{}};}
\DoxyCodeLine{\textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ sweeps\ =\ argc\ ==\ 3\ ?\ std::atoi(argv[2])\ :\ 5u;}
\DoxyCodeLine{std::map<std::string,\ std::function<std::shared\_ptr<gko::Executor>()>>}
\DoxyCodeLine{\ \ \ \ exec\_map\{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}omp"{}},\ []\ \{\ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}();\ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}cuda"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ []\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1CudaExecutor_a075a1957241de65c0cad59f9534430a2}{gko::CudaExecutor::create}}(0,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}hip"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ []\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1HipExecutor_a8afc5210bf8dd8aedfceab4b73f0047b}{gko::HipExecutor::create}}(0,\ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}dpcpp"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ []\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1DpcppExecutor_af69a356ee07f641010df5d2e9e518bb0}{gko::DpcppExecutor::create}}(0,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}reference"{}},\ []\ \{\ \textcolor{keywordflow}{return}\ gko::ReferenceExecutor::create();\ \}\}\};}

\end{DoxyCode}


executor where Ginkgo will perform the computation


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ exec\ =\ exec\_map.at(executor\_string)();\ \ \textcolor{comment}{//\ throws\ if\ not\ valid}}

\end{DoxyCode}


Read data


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ A\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(\doxymbox{\hyperlink{namespacegko_abc58509ecdcb48399e12f9a081ed7545}{gko::read<mtx>}}(std::ifstream(\textcolor{stringliteral}{"{}data/A.mtx"{}}),\ exec));}

\end{DoxyCode}


Create RHS and initial guess as 1


\begin{DoxyCode}{0}
\DoxyCodeLine{\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\ num\_rows\ =\ A-\/>get\_size()[0];}
\DoxyCodeLine{\textcolor{keyword}{auto}\ host\_x\ =\ vec::create(exec-\/>get\_master(),\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}(num\_rows,\ 1));}
\DoxyCodeLine{\textcolor{keywordflow}{for}\ (\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\ i\ =\ 0;\ i\ <\ num\_rows;\ i++)\ \{}
\DoxyCodeLine{\ \ \ \ host\_x-\/>at(i,\ 0)\ =\ 1.;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keyword}{auto}\ x\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ host\_x);}
\DoxyCodeLine{\textcolor{keyword}{auto}\ b\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ host\_x);}
\DoxyCodeLine{\textcolor{keyword}{auto}\ clone\_x\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ x);}

\end{DoxyCode}


Generate incomplete factors using Par\+ILU


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ par\_ilu\_fact\ =}
\DoxyCodeLine{\ \ \ \ gko::factorization::ParIlu<ValueType,\ IndexType>::build().on(exec);}

\end{DoxyCode}


Generate concrete factorization for input matrix


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ par\_ilu\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(par\_ilu\_fact-\/>generate(A));}

\end{DoxyCode}


Generate an iterative refinement factory to be used as a triangular solver in the preconditioner application. The generated method is equivalent to doing five block-\/\+Jacobi sweeps with a maximum block size of 16.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ bj\_factory\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(}
\DoxyCodeLine{\ \ \ \ bj::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_max\_block\_size(16u)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_storage\_optimization(\doxymbox{\hyperlink{classgko_1_1precision__reduction_ac4109c61fadb24db7a1888c51ac483e9}{gko::precision\_reduction::autodetect}}())}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .on(exec));}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{auto}\ trisolve\_factory\ =}
\DoxyCodeLine{\ \ \ \ ir::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_solver(bj\_factory)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_criteria(gko::stop::Iteration::build().with\_max\_iters(sweeps))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .on(exec);}

\end{DoxyCode}


Generate an ILU preconditioner factory by setting lower and upper triangular solver -\/ in this case the previously defined iterative refinement method.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ ilu\_pre\_factory\ =\ gko::preconditioner::Ilu<ir,\ ir>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_l\_solver(\doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(trisolve\_factory))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_u\_solver(\doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(trisolve\_factory))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}

\end{DoxyCode}


Use incomplete factors to generate ILU preconditioner


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ ilu\_preconditioner\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(ilu\_pre\_factory-\/>generate(par\_ilu));}

\end{DoxyCode}


Create stopping criteria for Gmres


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{const}\ RealValueType\ reduction\_factor\{1e-\/12\};}
\DoxyCodeLine{\textcolor{keyword}{auto}\ iter\_stop\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(}
\DoxyCodeLine{\ \ \ \ gko::stop::Iteration::build().with\_max\_iters(1000u).on(exec));}
\DoxyCodeLine{\textcolor{keyword}{auto}\ tol\_stop\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(gko::stop::ResidualNorm<ValueType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_reduction\_factor(reduction\_factor)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec));}

\end{DoxyCode}


Use preconditioner inside GMRES solver factory Generating a solver factory tied to a specific preconditioner makes sense if there are several very similar systems to solve, and the same solver+preconditioner combination is expected to be effective.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ ilu\_gmres\_factory\ =}
\DoxyCodeLine{\ \ \ \ gmres::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_criteria(iter\_stop,\ tol\_stop)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_generated\_preconditioner(ilu\_preconditioner)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .on(exec);}

\end{DoxyCode}


Generate preconditioned solver for a specific target system


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ ilu\_gmres\ =\ ilu\_gmres\_factory-\/>generate(A);}

\end{DoxyCode}


Add logger


\begin{DoxyCode}{0}
\DoxyCodeLine{std::shared\_ptr<const\ gko::log::Convergence<ValueType>>\ logger\ =}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{classgko_1_1log_1_1Convergence_ab0ec7b5f1f08c7237e2181e71cf7d5ed}{gko::log::Convergence<ValueType>::create}}();}
\DoxyCodeLine{ilu\_gmres-\/>add\_logger(logger);}

\end{DoxyCode}


Warmup run


\begin{DoxyCode}{0}
\DoxyCodeLine{ilu\_gmres-\/>apply(b,\ x);}

\end{DoxyCode}


Solve system 100 times and take the average time.


\begin{DoxyCode}{0}
\DoxyCodeLine{std::chrono::nanoseconds\ time(0);}
\DoxyCodeLine{\textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ 100;\ i++)\ \{}
\DoxyCodeLine{\ \ \ \ x-\/>copy\_from(clone\_x);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ tic\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ ilu\_gmres-\/>apply(b,\ x);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ toc\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ time\ +=\ std::chrono::duration\_cast<std::chrono::nanoseconds>(toc\ -\/\ tic);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{std::cout\ <<\ \textcolor{stringliteral}{"{}Using\ "{}}\ <<\ sweeps\ <<\ \textcolor{stringliteral}{"{}\ block-\/Jacobi\ sweeps.\(\backslash\)n"{}};}

\end{DoxyCode}


Print solution


\begin{DoxyCode}{0}
\DoxyCodeLine{std::cout\ <<\ \textcolor{stringliteral}{"{}Solution\ (x):\(\backslash\)n"{}};}
\DoxyCodeLine{\doxymbox{\hyperlink{namespacegko_af82d8f7795fefcf5f38a38895e316c02}{write}}(std::cout,\ x);}

\end{DoxyCode}


Get residual


\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ res\ =\ \doxymbox{\hyperlink{namespacegko_ae3e355a655feea026a7c46814d37a9c9}{gko::as<vec>}}(logger-\/>get\_residual\_norm());}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}GMRES\ iteration\ count:\ \ \ \ \ "{}}\ <<\ logger-\/>get\_num\_iterations()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}GMRES\ execution\ time\ [ms]:\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{double}\textcolor{keyword}{>}(time.count())\ /\ 100000000.0\ <<\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}Residual\ norm\ sqrt(r\string^T\ r):\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{namespacegko_af82d8f7795fefcf5f38a38895e316c02}{write}}(std::cout,\ res);}
\DoxyCodeLine{\}}

\end{DoxyCode}
 \label{three_pt_stencil_solver_Results}%
\Hypertarget{three_pt_stencil_solver_Results}%
\doxysection*{Results}

This is the expected output:\+


\begin{DoxyCode}{0}
\DoxyCodeLine{Using\ 5\ block-\/Jacobi\ sweeps.}
\DoxyCodeLine{Solution\ (x):}
\DoxyCodeLine{\%\%MatrixMarket\ matrix\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{array}}\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}}\ general}
\DoxyCodeLine{19\ 1}
\DoxyCodeLine{0.252218}
\DoxyCodeLine{0.108645}
\DoxyCodeLine{0.0662811}
\DoxyCodeLine{0.0630433}
\DoxyCodeLine{0.0384088}
\DoxyCodeLine{0.0396536}
\DoxyCodeLine{0.0402648}
\DoxyCodeLine{0.0338935}
\DoxyCodeLine{0.0193098}
\DoxyCodeLine{0.0234653}
\DoxyCodeLine{0.0211499}
\DoxyCodeLine{0.0196413}
\DoxyCodeLine{0.0199151}
\DoxyCodeLine{0.0181674}
\DoxyCodeLine{0.0162722}
\DoxyCodeLine{0.0150714}
\DoxyCodeLine{0.0107016}
\DoxyCodeLine{0.0121141}
\DoxyCodeLine{0.0123025}
\DoxyCodeLine{GMRES\ iteration\ count:\ \ \ \ \ 8}
\DoxyCodeLine{GMRES\ execution\ time\ [ms]:\ 0.377673}
\DoxyCodeLine{Residual\ norm\ sqrt(r\string^T\ r):}
\DoxyCodeLine{\%\%MatrixMarket\ matrix\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{array}}\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}}\ general}
\DoxyCodeLine{1\ 1}
\DoxyCodeLine{1.65303e-\/12}

\end{DoxyCode}


\label{three_pt_stencil_solver_Commentsaboutprogramminganddebugging}%
\Hypertarget{three_pt_stencil_solver_Commentsaboutprogramminganddebugging}%
\doxysubsubsection*{Comments about programming and debugging }

\label{three_pt_stencil_solver_PlainProg}%
\Hypertarget{three_pt_stencil_solver_PlainProg}%
 \doxysection*{The plain program}


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <cstdlib>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <fstream>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <map>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <ginkgo/ginkgo.hpp>}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}*\ argv[])}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }ValueType\ =\ double;}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }RealValueType\ =\ \doxymbox{\hyperlink{namespacegko_a107302a750bfa82a2107c77293f791c9}{gko::remove\_complex<ValueType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }IndexType\ =\ int;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }vec\ =\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense}{gko::matrix::Dense<ValueType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }real\_vec\ =\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense}{gko::matrix::Dense<RealValueType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }mtx\ =\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }gmres\ =\ \doxymbox{\hyperlink{classgko_1_1solver_1_1Gmres}{gko::solver::Gmres<ValueType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }ir\ =\ \doxymbox{\hyperlink{namespacegko_1_1solver_a1dac6a1b61c52db896845967e899aef0}{gko::solver::Ir<ValueType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }bj\ =\ \doxymbox{\hyperlink{classgko_1_1preconditioner_1_1Jacobi}{gko::preconditioner::Jacobi<ValueType,\ IndexType>}};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \doxymbox{\hyperlink{classgko_1_1version__info_ab13efac1405dd90951d2d9485acc4f30}{gko::version\_info::get}}()\ <<\ std::endl;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{if}\ (argc\ ==\ 2\ \&\&\ (std::string(argv[1])\ ==\ \textcolor{stringliteral}{"{}-\/-\/help"{}}))\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Usage:\ "{}}\ <<\ argv[0]\ <<\ \textcolor{stringliteral}{"{}\ [executor]"{}}\ <<\ std::endl;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::exit(-\/1);}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ executor\_string\ =\ argc\ >=\ 2\ ?\ argv[1]\ :\ \textcolor{stringliteral}{"{}reference"{}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ sweeps\ =\ argc\ ==\ 3\ ?\ std::atoi(argv[2])\ :\ 5u;}
\DoxyCodeLine{\ \ \ \ std::map<std::string,\ std::function<std::shared\_ptr<gko::Executor>()>>}
\DoxyCodeLine{\ \ \ \ \ \ \ \ exec\_map\{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}omp"{}},\ []\ \{\ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}();\ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}cuda"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ []\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1CudaExecutor_a075a1957241de65c0cad59f9534430a2}{gko::CudaExecutor::create}}(0,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}hip"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ []\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1HipExecutor_a8afc5210bf8dd8aedfceab4b73f0047b}{gko::HipExecutor::create}}(0,\ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}dpcpp"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ []\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1DpcppExecutor_af69a356ee07f641010df5d2e9e518bb0}{gko::DpcppExecutor::create}}(0,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \}\},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}reference"{}},\ []\ \{\ \textcolor{keywordflow}{return}\ gko::ReferenceExecutor::create();\ \}\}\};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ exec\ =\ exec\_map.at(executor\_string)();\ \ \textcolor{comment}{//\ throws\ if\ not\ valid}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ A\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(\doxymbox{\hyperlink{namespacegko_abc58509ecdcb48399e12f9a081ed7545}{gko::read<mtx>}}(std::ifstream(\textcolor{stringliteral}{"{}data/A.mtx"{}}),\ exec));}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\ num\_rows\ =\ A-\/>get\_size()[0];}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ host\_x\ =\ vec::create(exec-\/>get\_master(),\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}(num\_rows,\ 1));}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{for}\ (\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\ i\ =\ 0;\ i\ <\ num\_rows;\ i++)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ host\_x-\/>at(i,\ 0)\ =\ 1.;}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ x\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ host\_x);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ b\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ host\_x);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ clone\_x\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ x);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ par\_ilu\_fact\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gko::factorization::ParIlu<ValueType,\ IndexType>::build().on(exec);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ par\_ilu\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(par\_ilu\_fact-\/>generate(A));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ bj\_factory\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ bj::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .with\_max\_block\_size(16u)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .with\_storage\_optimization(\doxymbox{\hyperlink{classgko_1_1precision__reduction_ac4109c61fadb24db7a1888c51ac483e9}{gko::precision\_reduction::autodetect}}())}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .on(exec));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ trisolve\_factory\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ ir::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .with\_solver(bj\_factory)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .with\_criteria(gko::stop::Iteration::build().with\_max\_iters(sweeps))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ ilu\_pre\_factory\ =\ gko::preconditioner::Ilu<ir,\ ir>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_l\_solver(\doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(trisolve\_factory))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_u\_solver(\doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(trisolve\_factory))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ ilu\_preconditioner\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(ilu\_pre\_factory-\/>generate(par\_ilu));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ RealValueType\ reduction\_factor\{1e-\/12\};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ iter\_stop\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gko::stop::Iteration::build().with\_max\_iters(1000u).on(exec));}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ tol\_stop\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(gko::stop::ResidualNorm<ValueType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_reduction\_factor(reduction\_factor)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ ilu\_gmres\_factory\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ gmres::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .with\_criteria(iter\_stop,\ tol\_stop)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .with\_generated\_preconditioner(ilu\_preconditioner)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ ilu\_gmres\ =\ ilu\_gmres\_factory-\/>generate(A);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::shared\_ptr<const\ gko::log::Convergence<ValueType>>\ logger\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1log_1_1Convergence_ab0ec7b5f1f08c7237e2181e71cf7d5ed}{gko::log::Convergence<ValueType>::create}}();}
\DoxyCodeLine{\ \ \ \ ilu\_gmres-\/>add\_logger(logger);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ ilu\_gmres-\/>apply(b,\ x);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::chrono::nanoseconds\ time(0);}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ 100;\ i++)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ x-\/>copy\_from(clone\_x);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ tic\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ ilu\_gmres-\/>apply(b,\ x);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ toc\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ time\ +=\ std::chrono::duration\_cast<std::chrono::nanoseconds>(toc\ -\/\ tic);}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}Using\ "{}}\ <<\ sweeps\ <<\ \textcolor{stringliteral}{"{}\ block-\/Jacobi\ sweeps.\(\backslash\)n"{}};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}Solution\ (x):\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{namespacegko_af82d8f7795fefcf5f38a38895e316c02}{write}}(std::cout,\ x);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ res\ =\ \doxymbox{\hyperlink{namespacegko_ae3e355a655feea026a7c46814d37a9c9}{gko::as<vec>}}(logger-\/>get\_residual\_norm());}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}GMRES\ iteration\ count:\ \ \ \ \ "{}}\ <<\ logger-\/>get\_num\_iterations()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}GMRES\ execution\ time\ [ms]:\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{double}\textcolor{keyword}{>}(time.count())\ /\ 100000000.0\ <<\ \textcolor{stringliteral}{"{}\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}Residual\ norm\ sqrt(r\string^T\ r):\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{namespacegko_af82d8f7795fefcf5f38a38895e316c02}{write}}(std::cout,\ res);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 