\chapter{The par-\/ilu-\/convergence program }
\hypertarget{par_ilu_convergence}{}\label{par_ilu_convergence}\index{The par-\/ilu-\/convergence program@{The par-\/ilu-\/convergence program}}
The Par\+ILU convergence example.

This example depends on simple-\/solver.

 \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 can be used to inspect the convergence behavior of parallel incomplete factorizations. \label{three_pt_stencil_solver_CommProg}%
\Hypertarget{three_pt_stencil_solver_CommProg}%
 \doxysection*{The commented program}


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ try\_generate(Function\ fun)\ -\/>\ \textcolor{keyword}{decltype}(fun())}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{decltype}(fun())\ result;}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{try}\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ result\ =\ fun();}
\DoxyCodeLine{\ \ \ \ \}\ \textcolor{keywordflow}{catch}\ (\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Error}{gko::Error}}\&\ err)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Error:\ "{}}\ <<\ err.\doxymbox{\hyperlink{classgko_1_1Error_aec78ba67d5d7bf123d20afbe086977d0}{what}}()\ <<\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::exit(-\/1);}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType,\ \textcolor{keyword}{typename}\ IndexType>}
\DoxyCodeLine{\textcolor{keywordtype}{double}\ compute\_ilu\_residual\_norm(}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}}*\ residual,}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}}*\ mtx)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{structgko_1_1matrix__data}{gko::matrix\_data<ValueType,\ IndexType>}}\ residual\_data;}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{structgko_1_1matrix__data}{gko::matrix\_data<ValueType,\ IndexType>}}\ mtx\_data;}
\DoxyCodeLine{\ \ \ \ residual-\/>write(residual\_data);}
\DoxyCodeLine{\ \ \ \ mtx-\/>write(mtx\_data);}
\DoxyCodeLine{\ \ \ \ residual\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_ab2094160087e0d7fcbb85120f2138b52}{sort\_row\_major}}();}
\DoxyCodeLine{\ \ \ \ mtx\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_ab2094160087e0d7fcbb85120f2138b52}{sort\_row\_major}}();}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ it\ =\ mtx\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_a4f6be92270fa96bccdc502c83d248dc0}{nonzeros}}.begin();}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{double}\ residual\_norm\{\};}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ entry\ :\ residual\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_a4f6be92270fa96bccdc502c83d248dc0}{nonzeros}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ref\_row\ =\ it-\/>row;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ref\_col\ =\ it-\/>column;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (entry.row\ ==\ ref\_row\ \&\&\ entry.column\ ==\ ref\_col)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ residual\_norm\ +=\ \doxymbox{\hyperlink{namespacegko_abbb55709b10d707b2cbef803832aa834}{gko::squared\_norm}}(entry.value);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ ++it;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{return}\ std::sqrt(residual\_norm);}
\DoxyCodeLine{\}}
\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\ }IndexType\ =\ int;}

\end{DoxyCode}


print usage message


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordflow}{if}\ (argc\ <\ 2\ ||\ executors.find(argv[1])\ ==\ executors.end())\ \{}
\DoxyCodeLine{\ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Usage:\ executable"{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\ <reference|omp|cuda|hip|dpcpp>\ [<matrix-\/file>]\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}[<parilu|parilut|paric|parict]\ [<max-\/iterations>]\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}[<num-\/repetitions>]\ [<fill-\/in-\/limit>]\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\}}

\end{DoxyCode}


generate executor based on first argument


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ exec\ =\ try\_generate([\&]\ \{\ \textcolor{keywordflow}{return}\ executors.at(argv[1])();\ \});}

\end{DoxyCode}


set matrix and preconditioner name with default values


\begin{DoxyCode}{0}
\DoxyCodeLine{std::string\ matrix\ =\ argc\ <\ 3\ ?\ \textcolor{stringliteral}{"{}data/A.mtx"{}}\ :\ argv[2];}
\DoxyCodeLine{std::string\ precond\ =\ argc\ <\ 4\ ?\ \textcolor{stringliteral}{"{}parilu"{}}\ :\ argv[3];}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ max\_iterations\ =\ argc\ <\ 5\ ?\ 10\ :\ std::stoi(argv[4]);}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ num\_repetitions\ =\ argc\ <\ 6\ ?\ 10\ :\ std::stoi(argv[5]);}
\DoxyCodeLine{\textcolor{keywordtype}{double}\ limit\ =\ argc\ <\ 7\ ?\ 2\ :\ std::stod(argv[6]);}

\end{DoxyCode}


load matrix file into Csr format


\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ mtx\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(try\_generate([\&]\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::ifstream\ mtx\_stream\{matrix\};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!mtx\_stream)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ GKO\_STREAM\_ERROR(\textcolor{stringliteral}{"{}Unable\ to\ open\ matrix\ file"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Reading\ "{}}\ <<\ matrix\ <<\ std::endl;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{namespacegko_abc58509ecdcb48399e12f9a081ed7545}{gko::read<gko::matrix::Csr<ValueType,\ IndexType>}}>(mtx\_stream,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exec);}
\DoxyCodeLine{\ \ \ \ \}));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ factory\_generator\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ [\&](\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\ iteration)\ -\/>\ std::shared\_ptr<gko::LinOpFactory>\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}parilu"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIlu<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}paric"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIc<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}parilut"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIlut<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_fill\_in\_limit(limit)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}parict"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIct<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_fill\_in\_limit(limit)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ GKO\_NOT\_IMPLEMENTED;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ \doxymbox{\hyperlink{namespacegko_a0059e27f8f4bc348ff65c1e60caf47c8}{one}}\ =\ \doxymbox{\hyperlink{group__LinOp_ga70851b4c3c9b01bb667b3a8e438fb6d2}{gko::initialize<gko::matrix::Dense<ValueType>}}>(\{1.0\},\ exec);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ minus\_one\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \doxymbox{\hyperlink{group__LinOp_ga70851b4c3c9b01bb667b3a8e438fb6d2}{gko::initialize<gko::matrix::Dense<ValueType>}}>(\{-\/1.0\},\ exec);}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ it\ =\ 1;\ it\ <=\ max\_iterations;\ ++it)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ \doxymbox{\hyperlink{namespacegko_1_1log_a15f71654c6c4f4defc95f9359343fa27a9549dd6065d019211460c59a86dd6536}{factory}}\ =\ factory\_generator(it);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cout\ <<\ it\ <<\ \textcolor{charliteral}{';'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::vector<long>\ times;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::vector<double>\ residuals;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ rep\ =\ 0;\ rep\ <\ num\_repetitions;\ ++rep)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ tic\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacegko_ae3e355a655feea026a7c46814d37a9c9}{gko::as<gko::Composition<ValueType>}}>(\doxymbox{\hyperlink{namespacegko_1_1log_a15f71654c6c4f4defc95f9359343fa27a9549dd6065d019211460c59a86dd6536}{factory}}-\/>generate(mtx));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ exec-\/>synchronize();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ toc\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ residual\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ mtx);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ result-\/>get\_operators()[0]-\/>apply(one,\ result-\/>get\_operators()[1],}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ minus\_one,\ residual);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ times.push\_back(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::chrono::duration\_cast<std::chrono::nanoseconds>(toc\ -\/\ tic)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .count());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ residuals.push\_back(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ compute\_ilu\_residual\_norm(residual.get(),\ mtx.get()));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ el\ :\ times)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ std::cout\ <<\ el\ <<\ \textcolor{charliteral}{';'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ el\ :\ residuals)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ std::cout\ <<\ el\ <<\ \textcolor{charliteral}{';'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cout\ <<\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{\ \ \ \ \}}
\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{Usage:\ executable\ <reference|omp|cuda|hip|dpcpp>\ [<matrix-\/file>]\ [<parilu|parilut|paric|parict]\ [<\doxymbox{\hyperlink{namespacegko_af1812df45c6ec07780d579a12b64c753}{max}}-\/iterations>]\ [<num-\/repetitions>]\ [fill-\/in-\/limit]}

\end{DoxyCode}


When specifying an executor:\+


\begin{DoxyCode}{0}
\DoxyCodeLine{Reading\ data/A.mtx}
\DoxyCodeLine{1;71800;10300;8800;8200;8000;7700;7500;7500;7500;7400;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;1.0331e-\/14;}
\DoxyCodeLine{2;15500;9100;13500;9000;8600;8800;8700;8600;8600;8500;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{3;16500;10200;10100;10100;9900;10000;9800;9800;9900;9900;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{4;17500;11500;11200;15600;11300;11200;11400;11200;11200;11100;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{5;18800;12800;12700;12600;12500;12400;12400;12400;12400;14100;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{6;19200;13400;23100;15400;13200;13000;13000;13000;13100;13000;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{7;20500;14500;14400;14200;14200;14300;14200;14100;14300;14200;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{8;21600;15700;86200;16300;15700;15600;15500;15400;15500;15600;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{9;22700;17000;16700;16600;16700;16800;20400;17400;17500;17400;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}
\DoxyCodeLine{10;25500;19000;18800;18700;18700;18800;18600;18700;18600;18700;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;4.15407e-\/16;}

\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\ <fstream>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <functional>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <map>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <memory>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <ginkgo/ginkgo.hpp>}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{const}\ std::map<std::string,\ std::function<std::shared\_ptr<gko::Executor>()>>}
\DoxyCodeLine{\ \ \ \ executors\{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{\textcolor{stringliteral}{"{}reference"{}},\ []\ \{\ \textcolor{keywordflow}{return}\ gko::ReferenceExecutor::create();\ \}\},}
\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,\ \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{\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classgko_1_1DpcppExecutor_af69a356ee07f641010df5d2e9e518bb0}{gko::DpcppExecutor::create}}(0,\ \doxymbox{\hyperlink{classgko_1_1OmpExecutor_af977cb680e0427ca4eb71eb7b1266211}{gko::OmpExecutor::create}}());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \}\}\};}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Function>}
\DoxyCodeLine{\textcolor{keyword}{auto}\ try\_generate(Function\ fun)\ -\/>\ \textcolor{keyword}{decltype}(fun())}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{decltype}(fun())\ result;}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{try}\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ result\ =\ fun();}
\DoxyCodeLine{\ \ \ \ \}\ \textcolor{keywordflow}{catch}\ (\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Error}{gko::Error}}\&\ err)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Error:\ "{}}\ <<\ err.\doxymbox{\hyperlink{classgko_1_1Error_aec78ba67d5d7bf123d20afbe086977d0}{what}}()\ <<\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::exit(-\/1);}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType,\ \textcolor{keyword}{typename}\ IndexType>}
\DoxyCodeLine{\textcolor{keywordtype}{double}\ compute\_ilu\_residual\_norm(}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}}*\ residual,}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}}*\ mtx)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{structgko_1_1matrix__data}{gko::matrix\_data<ValueType,\ IndexType>}}\ residual\_data;}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{structgko_1_1matrix__data}{gko::matrix\_data<ValueType,\ IndexType>}}\ mtx\_data;}
\DoxyCodeLine{\ \ \ \ residual-\/>write(residual\_data);}
\DoxyCodeLine{\ \ \ \ mtx-\/>write(mtx\_data);}
\DoxyCodeLine{\ \ \ \ residual\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_ab2094160087e0d7fcbb85120f2138b52}{sort\_row\_major}}();}
\DoxyCodeLine{\ \ \ \ mtx\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_ab2094160087e0d7fcbb85120f2138b52}{sort\_row\_major}}();}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ it\ =\ mtx\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_a4f6be92270fa96bccdc502c83d248dc0}{nonzeros}}.begin();}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{double}\ residual\_norm\{\};}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ entry\ :\ residual\_data.\doxymbox{\hyperlink{structgko_1_1matrix__data_a4f6be92270fa96bccdc502c83d248dc0}{nonzeros}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ref\_row\ =\ it-\/>row;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ref\_col\ =\ it-\/>column;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (entry.row\ ==\ ref\_row\ \&\&\ entry.column\ ==\ ref\_col)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ residual\_norm\ +=\ \doxymbox{\hyperlink{namespacegko_abbb55709b10d707b2cbef803832aa834}{gko::squared\_norm}}(entry.value);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ ++it;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{return}\ std::sqrt(residual\_norm);}
\DoxyCodeLine{\}}
\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\ }IndexType\ =\ int;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{if}\ (argc\ <\ 2\ ||\ executors.find(argv[1])\ ==\ executors.end())\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Usage:\ executable"{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\ <reference|omp|cuda|hip|dpcpp>\ [<matrix-\/file>]\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}[<parilu|parilut|paric|parict]\ [<max-\/iterations>]\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}[<num-\/repetitions>]\ [<fill-\/in-\/limit>]\(\backslash\)n"{}};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ -\/1;}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ exec\ =\ try\_generate([\&]\ \{\ \textcolor{keywordflow}{return}\ executors.at(argv[1])();\ \});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::string\ matrix\ =\ argc\ <\ 3\ ?\ \textcolor{stringliteral}{"{}data/A.mtx"{}}\ :\ argv[2];}
\DoxyCodeLine{\ \ \ \ std::string\ precond\ =\ argc\ <\ 4\ ?\ \textcolor{stringliteral}{"{}parilu"{}}\ :\ argv[3];}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{int}\ max\_iterations\ =\ argc\ <\ 5\ ?\ 10\ :\ std::stoi(argv[4]);}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{int}\ num\_repetitions\ =\ argc\ <\ 6\ ?\ 10\ :\ std::stoi(argv[5]);}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordtype}{double}\ limit\ =\ argc\ <\ 7\ ?\ 2\ :\ std::stod(argv[6]);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ mtx\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{gko::share}}(try\_generate([\&]\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::ifstream\ mtx\_stream\{matrix\};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!mtx\_stream)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ GKO\_STREAM\_ERROR(\textcolor{stringliteral}{"{}Unable\ to\ open\ matrix\ file"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Reading\ "{}}\ <<\ matrix\ <<\ std::endl;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{namespacegko_abc58509ecdcb48399e12f9a081ed7545}{gko::read<gko::matrix::Csr<ValueType,\ IndexType>}}>(mtx\_stream,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exec);}
\DoxyCodeLine{\ \ \ \ \}));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ factory\_generator\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ [\&](\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\ iteration)\ -\/>\ std::shared\_ptr<gko::LinOpFactory>\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}parilu"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIlu<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}paric"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIc<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}parilut"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIlut<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_fill\_in\_limit(limit)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (precond\ ==\ \textcolor{stringliteral}{"{}parict"{}})\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::factorization::ParIct<ValueType,\ IndexType>::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_fill\_in\_limit(limit)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .with\_iterations(iteration)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .on(exec);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ GKO\_NOT\_IMPLEMENTED;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ \doxymbox{\hyperlink{namespacegko_a0059e27f8f4bc348ff65c1e60caf47c8}{one}}\ =\ \doxymbox{\hyperlink{group__LinOp_ga70851b4c3c9b01bb667b3a8e438fb6d2}{gko::initialize<gko::matrix::Dense<ValueType>}}>(\{1.0\},\ exec);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ minus\_one\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \doxymbox{\hyperlink{group__LinOp_ga70851b4c3c9b01bb667b3a8e438fb6d2}{gko::initialize<gko::matrix::Dense<ValueType>}}>(\{-\/1.0\},\ exec);}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ it\ =\ 1;\ it\ <=\ max\_iterations;\ ++it)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ \doxymbox{\hyperlink{namespacegko_1_1log_a15f71654c6c4f4defc95f9359343fa27a9549dd6065d019211460c59a86dd6536}{factory}}\ =\ factory\_generator(it);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cout\ <<\ it\ <<\ \textcolor{charliteral}{';'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::vector<long>\ times;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::vector<double>\ residuals;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ rep\ =\ 0;\ rep\ <\ num\_repetitions;\ ++rep)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ tic\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacegko_ae3e355a655feea026a7c46814d37a9c9}{gko::as<gko::Composition<ValueType>}}>(\doxymbox{\hyperlink{namespacegko_1_1log_a15f71654c6c4f4defc95f9359343fa27a9549dd6065d019211460c59a86dd6536}{factory}}-\/>generate(mtx));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ exec-\/>synchronize();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ toc\ =\ std::chrono::high\_resolution\_clock::now();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ residual\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ mtx);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ result-\/>get\_operators()[0]-\/>apply(one,\ result-\/>get\_operators()[1],}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ minus\_one,\ residual);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ times.push\_back(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::chrono::duration\_cast<std::chrono::nanoseconds>(toc\ -\/\ tic)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ .count());}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ residuals.push\_back(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ compute\_ilu\_residual\_norm(residual.get(),\ mtx.get()));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ el\ :\ times)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ std::cout\ <<\ el\ <<\ \textcolor{charliteral}{';'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ el\ :\ residuals)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ std::cout\ <<\ el\ <<\ \textcolor{charliteral}{';'};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cout\ <<\ \textcolor{charliteral}{'\(\backslash\)n'};}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 