\chapter{The kokkos-\/assembly program }
\hypertarget{kokkos_assembly}{}\label{kokkos_assembly}\index{The kokkos-\/assembly program@{The kokkos-\/assembly program}}
The Kokkos assembly example.

This example depends on simple-\/solver, poisson-\/solver, three-\/pt-\/stencil-\/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}

This example solves a 1D Poisson equation:\+

\[    u : [0, 1] \rightarrow R\\
    u\textnormal{\textquotesingle}\textnormal{\textquotesingle} = f\\
    u(0) = u0\\
    u(1) = u1
\]

using a finite difference method on an equidistant grid with {\ttfamily K} discretization points ({\ttfamily K} can be controlled with a command line parameter).

The resulting CSR matrix is assembled using Kokkos kernels. This example show how to use Ginkgo data with Kokkos kernels.

\label{kokkos_assembly_Notes}%
\Hypertarget{kokkos_assembly_Notes}%
\doxysubsubsection*{Notes }

If this example is built as part of Ginkgo, it is advised to configure Ginkgo with {\ttfamily -\/DGINKGO\+\_\+\+WITH\+\_\+\+CCACHE=OFF} to prevent incompabilities with Kokkos\textquotesingle{} compiler wrapper for {\ttfamily nvcc}. \label{three_pt_stencil_solver_CommProg}%
\Hypertarget{three_pt_stencil_solver_CommProg}%
 \doxysection*{The commented program}


\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ \ *}
\DoxyCodeLine{\ \ \ \ \ *\ @tparam\ ValueType\_c\ \ The\ value\ type\ of\ the\ matrix\ elements,\ might\ have}
\DoxyCodeLine{\ \ \ \ \ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ other\ cv\ qualifiers\ than\ ValueType}
\DoxyCodeLine{\ \ \ \ \ *\ @tparam\ IndexType\_c\ \ The\ index\ type\ of\ the\ matrix\ elements,\ might\ have}
\DoxyCodeLine{\ \ \ \ \ *\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ other\ cv\ qualifiers\ than\ IndexType}
\DoxyCodeLine{\ \ \ \ \ *\ /}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\_c,\ \textcolor{keyword}{typename}\ IndexType\_c>}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{struct\ }type\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }index\_array\ =\ \textcolor{keyword}{typename}\ index\_mapper::template\ type<IndexType\_c>;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }value\_array\ =\ \textcolor{keyword}{typename}\ value\_mapper::template\ type<ValueType\_c>;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ /\ **}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ Constructor\ based\ on\ size\ and\ raw\ pointers}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ @param\ size\ \ The\ number\ of\ stored\ elements}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ @param\ row\_idxs\ \ Pointer\ to\ the\ row\ indices}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ @param\ col\_idxs\ \ Pointer\ to\ the\ column\ indices}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ @param\ values\ \ Pointer\ to\ the\ values}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ @\textcolor{keywordflow}{return}\ \ An\ \textcolor{keywordtype}{object}\ which\ has\ each\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{gko::array}}\ of\ the}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ \ \ \ \ \ \ \ \ \ device\_matrix\_data\ mapped\ to\ a\ Kokkos\ view}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ *\ /}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{static}\ type\ map(size\_type\ size,\ IndexType\_c*\ row\_idxs,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ IndexType\_c*\ col\_idxs,\ ValueType\_c*\ values)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \{index\_mapper::map(row\_idxs,\ size),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ index\_mapper::map(col\_idxs,\ size),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ value\_mapper::map(values,\ size)\};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ index\_array\ row\_idxs;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ index\_array\ col\_idxs;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ value\_array\ values;}
\DoxyCodeLine{\ \ \ \ \};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{static}\ type<ValueType,\ IndexType>\ map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ device\_matrix\_data<ValueType,\ IndexType>\&\ md)}
\DoxyCodeLine{\ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ assert\_compatibility<MemorySpace>(md);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ type<ValueType,\ IndexType>::map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_num\_stored\_elements(),\ md.get\_row\_idxs(),\ md.get\_col\_idxs(),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_values());}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{static}\ type<const\ ValueType,\ const\ IndexType>\ map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ device\_matrix\_data<ValueType,\ IndexType>\&\ md)}
\DoxyCodeLine{\ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ assert\_compatibility<MemorySpace>(md);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ type<const\ ValueType,\ const\ IndexType>::map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_num\_stored\_elements(),\ md.get\_const\_row\_idxs(),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_const\_col\_idxs(),\ md.get\_const\_values());}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\}\ \ \textcolor{comment}{//\ namespace\ gko::ext::kokkos::detail}}

\end{DoxyCode}


Creates a stencil matrix in CSR format for the given number of discretization points.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType,\ \textcolor{keyword}{typename}\ IndexType>}
\DoxyCodeLine{\textcolor{keywordtype}{void}\ generate\_stencil\_matrix(\doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}}*\ matrix)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ exec\ =\ matrix-\/>get\_executor();}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ discretization\_points\ =\ matrix-\/>get\_size()[0];}

\end{DoxyCode}


Over-\/allocate storage for the matrix elements. Each row has 3 entries, except for the first and last one. To handle each row uniformly, we allocate space for 3x the number of rows.


\begin{DoxyCode}{0}
\DoxyCodeLine{\doxymbox{\hyperlink{classgko_1_1device__matrix__data}{gko::device\_matrix\_data<ValueType,\ IndexType>}}\ md(exec,\ matrix-\/>get\_size(),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ discretization\_points\ *\ 3);}

\end{DoxyCode}


Create Kokkos views on Ginkgo data.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ k\_md\ =\ gko::ext::kokkos::map\_data(md);}

\end{DoxyCode}


Create the matrix entries. This also creates zero entries for the first and second row to handle all rows uniformly.


\begin{DoxyCode}{0}
\DoxyCodeLine{Kokkos::parallel\_for(}
\DoxyCodeLine{\ \ \ \ \textcolor{stringliteral}{"{}generate\_stencil\_matrix"{}},\ md.get\_num\_stored\_elements(),}
\DoxyCodeLine{\ \ \ \ KOKKOS\_LAMBDA(\textcolor{keywordtype}{int}\ i)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ ValueType\ coefs[]\ =\ \{-\/1,\ 2,\ -\/1\};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ofs\ =\ \textcolor{keyword}{static\_cast<}IndexType\textcolor{keyword}{>}((i\ \%\ 3)\ -\/\ 1);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ row\ =\ \textcolor{keyword}{static\_cast<}IndexType\textcolor{keyword}{>}(i\ /\ 3);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ col\ =\ row\ +\ ofs;}

\end{DoxyCode}


To prevent branching, a mask is used to set the entry to zero, if the column is out-\/of-\/bounds


\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ mask\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{static\_cast<}IndexType\textcolor{keyword}{>}(0\ <=\ col\ \&\&\ col\ <\ discretization\_points);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ k\_md.row\_idxs[i]\ =\ mask\ *\ row;}
\DoxyCodeLine{\ \ \ \ k\_md.col\_idxs[i]\ =\ mask\ *\ col;}
\DoxyCodeLine{\ \ \ \ k\_md.values[i]\ =\ mask\ *\ coefs[ofs\ +\ 1];}
\DoxyCodeLine{\});}

\end{DoxyCode}


Add up duplicate (zero) entries.


\begin{DoxyCode}{0}
\DoxyCodeLine{md.sum\_duplicates();}

\end{DoxyCode}


Build Csr matrix.


\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ matrix-\/>read(std::move(md));}
\DoxyCodeLine{\}}

\end{DoxyCode}


Generates the RHS vector given {\ttfamily f} and the boundary conditions.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Closure,\ \textcolor{keyword}{typename}\ ValueType>}
\DoxyCodeLine{\textcolor{keywordtype}{void}\ generate\_rhs(Closure\&\&\ f,\ ValueType\ u0,\ ValueType\ u1,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense}{gko::matrix::Dense<ValueType>}}*\ rhs)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ discretization\_points\ =\ \doxymbox{\hyperlink{namespacegko_1_1solver_a82d21321745fbd3dc65c276d5838bb8aa83ff9f9e3dd7561d3dd91204cf546b7e}{rhs}}-\/>get\_size()[0];}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ k\_rhs\ =\ gko::ext::kokkos::map\_data(rhs);}
\DoxyCodeLine{\ \ \ \ Kokkos::parallel\_for(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}generate\_rhs"{}},\ discretization\_points,\ KOKKOS\_LAMBDA(\textcolor{keywordtype}{int}\ i)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ ValueType\ h\ =\ 1.0\ /\ (discretization\_points\ +\ 1);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ ValueType\ xi\ =\ ValueType(i\ +\ 1)\ *\ h;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ k\_rhs(i,\ 0)\ =\ -\/f(xi)\ *\ h\ *\ h;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ 0)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ k\_rhs(i,\ 0)\ +=\ u0;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ discretization\_points\ -\/\ 1)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ k\_rhs(i,\ 0)\ +=\ u1;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \});}
\DoxyCodeLine{\}}

\end{DoxyCode}


Computes the 1-\/norm of the error given the computed {\ttfamily u} and the correct solution function {\ttfamily correct\+\_\+u}.


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Closure,\ \textcolor{keyword}{typename}\ ValueType>}
\DoxyCodeLine{\textcolor{keywordtype}{double}\ calculate\_error(\textcolor{keywordtype}{int}\ discretization\_points,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense}{gko::matrix::Dense<ValueType>}}*\ u,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Closure\&\&\ correct\_u)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ k\_u\ =\ gko::ext::kokkos::map\_data(u);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ error\ =\ 0.0;}
\DoxyCodeLine{\ \ \ \ Kokkos::parallel\_reduce(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}calculate\_error"{}},\ discretization\_points,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ KOKKOS\_LAMBDA(\textcolor{keywordtype}{int}\ i,\ \textcolor{keywordtype}{double}\&\ lsum)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ h\ =\ 1.0\ /\ (discretization\_points\ +\ 1);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ xi\ =\ (i\ +\ 1)\ *\ h;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ lsum\ +=\ Kokkos::abs((k\_u(i,\ 0)\ -\/\ correct\_u(xi))\ /}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Kokkos::abs(correct\_u(xi)));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ error);}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{return}\ error;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}*\ argv[])}
\DoxyCodeLine{\{}

\end{DoxyCode}


Some shortcuts


\begin{DoxyCode}{0}
\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\ }mtx\ =\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}};}
\DoxyCodeLine{\textcolor{keyword}{using\ }cg\ =\ \doxymbox{\hyperlink{classgko_1_1solver_1_1Cg}{gko::solver::Cg<ValueType>}};}
\DoxyCodeLine{\textcolor{keyword}{using\ }bj\ =\ \doxymbox{\hyperlink{classgko_1_1preconditioner_1_1Jacobi}{gko::preconditioner::Jacobi<ValueType>}};}

\end{DoxyCode}


Print help message. For details on the kokkos-\/options see \href{https://kokkos.github.io/kokkos-core-wiki/ProgrammingGuide/Initialization.html\#initialization-by-command-line-arguments}{\texttt{https:\+/\+/\+kokkos.\+github.\+io/\+kokkos-\/core-\/wiki/\+\+Programming\+Guide/\+\+Initialization.\+html\+\#initialization-\/by-\/command-\/line-\/arguments}}


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordflow}{if}\ (argc\ ==\ 2\ \&\&\ (std::string(argv[1])\ ==\ \textcolor{stringliteral}{"{}-\/-\/help"{}}))\ \{}
\DoxyCodeLine{\ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Usage:\ "{}}\ <<\ argv[0]}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\ [discretization\_points]\ [kokkos-\/options]"{}}\ <<\ std::endl;}
\DoxyCodeLine{\ \ \ \ Kokkos::ScopeGuard\ kokkos(argc,\ argv);\ \ \textcolor{comment}{//\ print\ Kokkos\ help}}
\DoxyCodeLine{\ \ \ \ std::exit(1);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{Kokkos::ScopeGuard\ kokkos(argc,\ argv);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ discretization\_points\ =}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{static\_cast<}\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\textcolor{keyword}{>}(argc\ >=\ 2\ ?\ std::atoi(argv[1])\ :\ 100u);}

\end{DoxyCode}


chooses the executor that corresponds to the Kokkos Default\+Execution\+Space


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ exec\ =\ gko::ext::kokkos::create\_default\_executor();}

\end{DoxyCode}


problem:\+


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ correct\_u\ =\ []\ KOKKOS\_FUNCTION(ValueType\ x)\ \{\ \textcolor{keywordflow}{return}\ x\ *\ x\ *\ x;\ \};}
\DoxyCodeLine{\textcolor{keyword}{auto}\ f\ =\ []\ KOKKOS\_FUNCTION(ValueType\ x)\ \{\ \textcolor{keywordflow}{return}\ ValueType\{6\}\ *\ x;\ \};}
\DoxyCodeLine{\textcolor{keyword}{auto}\ u0\ =\ correct\_u(0);}
\DoxyCodeLine{\textcolor{keyword}{auto}\ u1\ =\ correct\_u(1);}

\end{DoxyCode}


initialize vectors


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ \doxymbox{\hyperlink{namespacegko_1_1solver_a82d21321745fbd3dc65c276d5838bb8aa83ff9f9e3dd7561d3dd91204cf546b7e}{rhs}}\ =\ vec::create(exec,\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}(discretization\_points,\ 1));}
\DoxyCodeLine{generate\_rhs(f,\ u0,\ u1,\ \doxymbox{\hyperlink{namespacegko_1_1solver_a82d21321745fbd3dc65c276d5838bb8aa83ff9f9e3dd7561d3dd91204cf546b7e}{rhs}}.get());}
\DoxyCodeLine{\textcolor{keyword}{auto}\ u\ =\ vec::create(exec,\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}(discretization\_points,\ 1));}
\DoxyCodeLine{u-\/>\doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense_af8eb9f6120517fbc19cee8e9ddfceb05}{fill}}(0.0);}

\end{DoxyCode}


initialize the stencil matrix


\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keyword}{auto}\ A\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{share}}(mtx::create(}
\DoxyCodeLine{\ \ \ \ exec,\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}\{discretization\_points,\ discretization\_points\}));}
\DoxyCodeLine{generate\_stencil\_matrix(A.get());}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{const}\ RealValueType\ reduction\_factor\{1e-\/7\};}

\end{DoxyCode}


Generate solver and solve the system


\begin{DoxyCode}{0}
\DoxyCodeLine{\ \ \ \ cg::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_criteria(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ gko::stop::Iteration::build().with\_max\_iters(discretization\_points),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ gko::stop::ResidualNorm<ValueType>::build().with\_reduction\_factor(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ reduction\_factor))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_preconditioner(bj::build())}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .on(exec)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ -\/>generate(A)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ -\/>apply(rhs,\ u);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}\(\backslash\)nSolve\ complete."{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\(\backslash\)nThe\ average\ relative\ error\ is\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ calculate\_error(discretization\_points,\ u.get(),\ correct\_u)\ /}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ discretization\_points}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ std::endl;}
\DoxyCodeLine{\}}

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

Example output:\+ 
\begin{DoxyCode}{0}
\DoxyCodeLine{>\ ./kokkos-\/assembly}
\DoxyCodeLine{}
\DoxyCodeLine{Solve\ complete.}
\DoxyCodeLine{The\ average\ relative\ error\ is\ 1.05488e-\/11}

\end{DoxyCode}


The actual error depends on the used hardware. \label{three_pt_stencil_solver_PlainProg}%
\Hypertarget{three_pt_stencil_solver_PlainProg}%
 \doxysection*{The plain program}


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Kokkos\_Core.hpp>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <ginkgo/ginkgo.hpp>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <ginkgo/extensions/kokkos.hpp>}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{namespace\ }gko::ext::kokkos::detail\ \{}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType,\ \textcolor{keyword}{typename}\ IndexType,\ \textcolor{keyword}{typename}\ MemorySpace>}
\DoxyCodeLine{\textcolor{keyword}{struct\ }mapper<device\_matrix\_data<ValueType,\ IndexType>,\ MemorySpace>\ \{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }index\_mapper\ =\ mapper<array<IndexType>,\ MemorySpace>;}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }value\_mapper\ =\ mapper<array<ValueType>,\ MemorySpace>;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\_c,\ \textcolor{keyword}{typename}\ IndexType\_c>}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{struct\ }type\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }index\_array\ =\ \textcolor{keyword}{typename}\ index\_mapper::template\ type<IndexType\_c>;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }value\_array\ =\ \textcolor{keyword}{typename}\ value\_mapper::template\ type<ValueType\_c>;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{static}\ type\ map(size\_type\ size,\ IndexType\_c*\ row\_idxs,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ IndexType\_c*\ col\_idxs,\ ValueType\_c*\ values)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \{index\_mapper::map(row\_idxs,\ size),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ index\_mapper::map(col\_idxs,\ size),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ value\_mapper::map(values,\ size)\};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ index\_array\ row\_idxs;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ index\_array\ col\_idxs;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ value\_array\ values;}
\DoxyCodeLine{\ \ \ \ \};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{static}\ type<ValueType,\ IndexType>\ map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ device\_matrix\_data<ValueType,\ IndexType>\&\ md)}
\DoxyCodeLine{\ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ assert\_compatibility<MemorySpace>(md);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ type<ValueType,\ IndexType>::map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_num\_stored\_elements(),\ md.get\_row\_idxs(),\ md.get\_col\_idxs(),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_values());}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{static}\ type<const\ ValueType,\ const\ IndexType>\ map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ device\_matrix\_data<ValueType,\ IndexType>\&\ md)}
\DoxyCodeLine{\ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ assert\_compatibility<MemorySpace>(md);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ type<const\ ValueType,\ const\ IndexType>::map(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_num\_stored\_elements(),\ md.get\_const\_row\_idxs(),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ md.get\_const\_col\_idxs(),\ md.get\_const\_values());}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\}\ \ \textcolor{comment}{//\ namespace\ gko::ext::kokkos::detail}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType,\ \textcolor{keyword}{typename}\ IndexType>}
\DoxyCodeLine{\textcolor{keywordtype}{void}\ generate\_stencil\_matrix(\doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}}*\ matrix)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ exec\ =\ matrix-\/>get\_executor();}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ discretization\_points\ =\ matrix-\/>get\_size()[0];}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \doxymbox{\hyperlink{classgko_1_1device__matrix__data}{gko::device\_matrix\_data<ValueType,\ IndexType>}}\ md(exec,\ matrix-\/>get\_size(),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ discretization\_points\ *\ 3);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ k\_md\ =\ gko::ext::kokkos::map\_data(md);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ Kokkos::parallel\_for(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}generate\_stencil\_matrix"{}},\ md.get\_num\_stored\_elements(),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ KOKKOS\_LAMBDA(\textcolor{keywordtype}{int}\ i)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ ValueType\ coefs[]\ =\ \{-\/1,\ 2,\ -\/1\};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ofs\ =\ \textcolor{keyword}{static\_cast<}IndexType\textcolor{keyword}{>}((i\ \%\ 3)\ -\/\ 1);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ row\ =\ \textcolor{keyword}{static\_cast<}IndexType\textcolor{keyword}{>}(i\ /\ 3);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ col\ =\ row\ +\ ofs;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ mask\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{static\_cast<}IndexType\textcolor{keyword}{>}(0\ <=\ col\ \&\&\ col\ <\ discretization\_points);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ k\_md.row\_idxs[i]\ =\ mask\ *\ row;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ k\_md.col\_idxs[i]\ =\ mask\ *\ col;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ k\_md.values[i]\ =\ mask\ *\ coefs[ofs\ +\ 1];}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ md.sum\_duplicates();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ matrix-\/>read(std::move(md));}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Closure,\ \textcolor{keyword}{typename}\ ValueType>}
\DoxyCodeLine{\textcolor{keywordtype}{void}\ generate\_rhs(Closure\&\&\ f,\ ValueType\ u0,\ ValueType\ u1,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense}{gko::matrix::Dense<ValueType>}}*\ rhs)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ discretization\_points\ =\ \doxymbox{\hyperlink{namespacegko_1_1solver_a82d21321745fbd3dc65c276d5838bb8aa83ff9f9e3dd7561d3dd91204cf546b7e}{rhs}}-\/>get\_size()[0];}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ k\_rhs\ =\ gko::ext::kokkos::map\_data(rhs);}
\DoxyCodeLine{\ \ \ \ Kokkos::parallel\_for(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}generate\_rhs"{}},\ discretization\_points,\ KOKKOS\_LAMBDA(\textcolor{keywordtype}{int}\ i)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ ValueType\ h\ =\ 1.0\ /\ (discretization\_points\ +\ 1);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ ValueType\ xi\ =\ ValueType(i\ +\ 1)\ *\ h;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ k\_rhs(i,\ 0)\ =\ -\/f(xi)\ *\ h\ *\ h;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ 0)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ k\_rhs(i,\ 0)\ +=\ u0;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ ==\ discretization\_points\ -\/\ 1)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ k\_rhs(i,\ 0)\ +=\ u1;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \});}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Closure,\ \textcolor{keyword}{typename}\ ValueType>}
\DoxyCodeLine{\textcolor{keywordtype}{double}\ calculate\_error(\textcolor{keywordtype}{int}\ discretization\_points,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense}{gko::matrix::Dense<ValueType>}}*\ u,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Closure\&\&\ correct\_u)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ k\_u\ =\ gko::ext::kokkos::map\_data(u);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ error\ =\ 0.0;}
\DoxyCodeLine{\ \ \ \ Kokkos::parallel\_reduce(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}calculate\_error"{}},\ discretization\_points,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ KOKKOS\_LAMBDA(\textcolor{keywordtype}{int}\ i,\ \textcolor{keywordtype}{double}\&\ lsum)\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ h\ =\ 1.0\ /\ (discretization\_points\ +\ 1);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ xi\ =\ (i\ +\ 1)\ *\ h;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ lsum\ +=\ Kokkos::abs((k\_u(i,\ 0)\ -\/\ correct\_u(xi))\ /}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Kokkos::abs(correct\_u(xi)));}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ error);}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{return}\ error;}
\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\ }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\ }mtx\ =\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Csr}{gko::matrix::Csr<ValueType,\ IndexType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }cg\ =\ \doxymbox{\hyperlink{classgko_1_1solver_1_1Cg}{gko::solver::Cg<ValueType>}};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{using\ }bj\ =\ \doxymbox{\hyperlink{classgko_1_1preconditioner_1_1Jacobi}{gko::preconditioner::Jacobi<ValueType>}};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keywordflow}{if}\ (argc\ ==\ 2\ \&\&\ (std::string(argv[1])\ ==\ \textcolor{stringliteral}{"{}-\/-\/help"{}}))\ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::cerr\ <<\ \textcolor{stringliteral}{"{}Usage:\ "{}}\ <<\ argv[0]}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\ [discretization\_points]\ [kokkos-\/options]"{}}\ <<\ std::endl;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ Kokkos::ScopeGuard\ kokkos(argc,\ argv);\ \ \textcolor{comment}{//\ print\ Kokkos\ help}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ std::exit(1);}
\DoxyCodeLine{\ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ Kokkos::ScopeGuard\ kokkos(argc,\ argv);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ discretization\_points\ =}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keyword}{static\_cast<}\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{gko::size\_type}}\textcolor{keyword}{>}(argc\ >=\ 2\ ?\ std::atoi(argv[1])\ :\ 100u);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ exec\ =\ gko::ext::kokkos::create\_default\_executor();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ correct\_u\ =\ []\ KOKKOS\_FUNCTION(ValueType\ x)\ \{\ \textcolor{keywordflow}{return}\ x\ *\ x\ *\ x;\ \};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ f\ =\ []\ KOKKOS\_FUNCTION(ValueType\ x)\ \{\ \textcolor{keywordflow}{return}\ ValueType\{6\}\ *\ x;\ \};}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ u0\ =\ correct\_u(0);}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ u1\ =\ correct\_u(1);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ \doxymbox{\hyperlink{namespacegko_1_1solver_a82d21321745fbd3dc65c276d5838bb8aa83ff9f9e3dd7561d3dd91204cf546b7e}{rhs}}\ =\ vec::create(exec,\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}(discretization\_points,\ 1));}
\DoxyCodeLine{\ \ \ \ generate\_rhs(f,\ u0,\ u1,\ \doxymbox{\hyperlink{namespacegko_1_1solver_a82d21321745fbd3dc65c276d5838bb8aa83ff9f9e3dd7561d3dd91204cf546b7e}{rhs}}.get());}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ u\ =\ vec::create(exec,\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}(discretization\_points,\ 1));}
\DoxyCodeLine{\ \ \ \ u-\/>\doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense_af8eb9f6120517fbc19cee8e9ddfceb05}{fill}}(0.0);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{auto}\ A\ =\ \doxymbox{\hyperlink{namespacegko_ae99fdd8bfa5ac694adcb7297d432967e}{share}}(mtx::create(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ exec,\ \doxymbox{\hyperlink{structgko_1_1dim}{gko::dim<2>}}\{discretization\_points,\ discretization\_points\}));}
\DoxyCodeLine{\ \ \ \ generate\_stencil\_matrix(A.get());}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ \textcolor{keyword}{const}\ RealValueType\ reduction\_factor\{1e-\/7\};}
\DoxyCodeLine{\ \ \ \ cg::build()}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_criteria(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ gko::stop::Iteration::build().with\_max\_iters(discretization\_points),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ gko::stop::ResidualNorm<ValueType>::build().with\_reduction\_factor(}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ reduction\_factor))}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .with\_preconditioner(bj::build())}
\DoxyCodeLine{\ \ \ \ \ \ \ \ .on(exec)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ -\/>generate(A)}
\DoxyCodeLine{\ \ \ \ \ \ \ \ -\/>apply(rhs,\ u);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ std::cout\ <<\ \textcolor{stringliteral}{"{}\(\backslash\)nSolve\ complete."{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ \textcolor{stringliteral}{"{}\(\backslash\)nThe\ average\ relative\ error\ is\ "{}}}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ calculate\_error(discretization\_points,\ u.get(),\ correct\_u)\ /}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ discretization\_points}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ std::endl;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 