X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/kahina_paper1.git/blobdiff_plain/944acbd1d3f1134e456324577c906ede08485b2f..22285cf247eb5754cde0cd2568dfd8c0f8ee3d4d:/Root.tex?ds=inline diff --git a/Root.tex b/Root.tex index 5134838..b4edff1 100644 --- a/Root.tex +++ b/Root.tex @@ -3,13 +3,15 @@ \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} +%%\usepackage{algorithm2e} +\usepackage[ruled,vlined]{algorithm2e} +%%\usepackage{algo} \author{ghidouche} \title{Paper1_kahina} \begin{document} \section{Root finding problem} -we consider a polynomial of degree \textit{n} having coefficients -in the complex \textit{C} and zeros $\alpha -_{i},\textit{i=1,...,n}$. \\ +We consider a polynomial of degree \textit{n} having coefficients +in the complex \textit{C} and zeros $\alpha_{i},\textit{i=1,...,n}$. \\ \begin{center} \begin{equation} {\Large p(x)=\sum{a_{i}x^{i}}=a_{n}\prod(x-\alpha_{i}),a_{0} a_{n}\neq 0} @@ -353,9 +355,145 @@ texture space, which reside in external DRAM, and are accessed via read-only caches \subsection{A parallel implementation of the Aberth's method } -\subsection{A CUDA implementation of the Aberth's method } -\subsection{A GPU implementation of the Aberth's method } -\subsubsection{the step to parallelize} +%%\subsection{A CUDA implementation of the Aberth's method } +%%\subsection{A GPU implementation of the Aberth's method } + + + +\subsubsection{A sequential Aberth algorithm} +The means steps of Aberth's method can expressed as an algorithm +like: + +\begin{algorithm}[H] +\LinesNumbered +\caption{Algorithm to find root polynomial with Aberth method} + +\KwIn{$Z^{0}$(Initial root's vector),$\varepsilon$ (error +tolerance threshold),P(Polynomial to solve)} + +\KwOut {Z(The solution root's vector)} + +\BlankLine + +Initialization of the parameter of the polynomial to solve\; +Initialization of the solution vector $Z^{0}$\; + +\While {$\Delta z_{max}\succ \epsilon$}{ + Let $\Delta z_{max}=0$\; +\For{$j \gets 0 $ \KwTo $n$}{ +$ZPrec\left[j\right]=Z\left[j\right]$\; +$Z\left[j\right]=H\left(j,Z\right)$\; +} + +\For{$i \gets 0 $ \KwTo $n-1$}{ +$c=\frac{\left|Z\left[i\right]-ZPrec\left[i\right]\right|}{Z\left[i\right]}$\; +\If{$c\succ\Delta z_{max}$ }{ +$\Delta z_{max}$=c\;} +} +} +\end{algorithm} +~\\ +~\\ +In this sequential algorithm one thread CPU execute all steps, let see the step 3 the execution of the iterative function , 2 instructions are needed, the first instruction \textit{save} the solution vector for the previous iteration, the second instruction \textit{update} or compute a new values of the roots. +We have two manner to execute the iterative function, taking a Jacobi iteration who need all the previous value $z^{(k)}_{i}$ to compute the new value $z^{(k+1)}_{i}$we have: + +\begin{equation} +H(i,z^{k+1})=\frac{p(z^{(k)}_{i})}{p'(z^{(k)}_{i})-p(z^{(k)}_{i})\sum^{n}_{j=1 j\neq i}\frac{1}{z^{(k)}_{i}-z^{(k)}_{j}}}, i=1,...,n. +\end{equation} + +Or with the Gauss-seidel iteration, we have: +\begin{equation} +H(i,z^{k+1})=\frac{p(z^{(k)}_{i})}{p'(z^{(k)}_{i})-p(z^{(k)}_{i})\sum^{i-1}_{j=1}\frac{1}{z^{(k)}_{i}-z^{(k)}_{j}}+\sum^{n}_{j=i+1}\frac{1}{z^{(k)}_{i}-z^{(k)}_{j}}}, i=1,...,n. +\end{equation} + +In formula(16) the iteration function use the $z^{k+1}_{i}$ computed in the current iteration to compute the rest of the roots, which take him to converge more quickly compare to the jacobi iteration (it's well now that the Gauss-seidel iteration converge more quickly because they used the most fresh computed root, so we used Gauss-seidel iteration.) + +The steps 4 of the Aberth's method compute the convergence of the roots, using(9) formula. +Both steps 3 and 4 use 1 thread to compute N roots on CPU, which is faster and hard, it make the algorithm faster and hard for the large polynomial's roots finding. + +\paragraph{The execution time} +Let $T_{i}(N)$: the time to compute one new root's value of the step 3,$T_{i}$ depend on the polynomial's degrees N, when N increase $T_{i}$ increase to.We need $N.T_{i}(N)$ to compute all the new root's value in one iteration on the step 3. + +Let $T_{j}$: the time to compute one root's convergence value of the step 4, we need $N.T_{j}$ to compute all the root's convergence value in one iteration on the step 4. + +The execution time for both steps 3 and 4 can see like: +\begin{equation} +T_{exe}=N(T_{i}(N)+T_{j})+O(n). +\end{equation} +Let Nbr\_iter the number of iteration necessary to compute all the roots,so the total execution time $Total\_time_{exe}$ can give like: + +\begin{equation} +Total\_time_{exe}=\left[N\left(T_{i}(N)+T_{j}\right)+O(n)\right].Nbr\_iter. +\end{equation} +The execution time increase with the increasing of the polynomial's root, which take necessary to parallelize this step to reduce the execution time. In the following paper you explain how we parrallelize this step using GPU architecture with CUDA platform. + +\subsubsection{Parallelize the steps on GPU } +On the CPU Aberth algorithm both steps 3 and 4 contain the loop \verb=for= , it use one thread to execute all the instruction in the loop N times.Here we explain how the GPU architecture can compute this loop and reduce the execution time. +The GPU architecture affect the execution of this loop to a groups of parallel threads organized as a grid of blocks each block contain a number of threads. All threads within a block are executed concurrently in parallel. the instruction are executed as a kernel. + +Let nbr\_thread be the number of threads executed in parallel, so you can easily transform the (18)formula like this: + +\begin{equation} +Total\_time_{exe}=\left[\frac{N}{nbr\_thread}\left(T_{i}(N)+T_{j}\right)+O(n)\right].Nbr\_iter. +\end{equation} + +In theory, the $Total\_time_{exe}$ on GPU is speed up nbr\_thread times as a $Total\_time_{exe}$ on CPU. We show more details in the experiment part. +~\\ +~\\ +In CUDA platform, All the instruction of the loop \verb=for= are executed by the GPU as a kernel form. A kernel is a procedure written in CUDA and defined by a heading \verb=__global__=, which means that it is to be executed by the GPU.the following algorithm see the Aberth algorithm on GPU: + +\begin{algorithm}[H] +\LinesNumbered +\caption{Algorithm to find root polynomial with Aberth method} + +\KwIn{$Z^{0}$(Initial root's vector),$\varepsilon$ (error +tolerance threshold),P(Polynomial to solve)} + +\KwOut {Z(The solution root's vector)} + +\BlankLine + +Initialization of the parameter of the polynomial to solve\; +Initialization of the solution vector $Z^{0}$\; +Allocate and fill the data in the global memory GPU\; + +\While {$\Delta z_{max}\succ \epsilon$}{ + Let $\Delta z_{max}=0$\; +$ kernel\_save(d\_Z^{k-1})$\; +$ kernel\_update(d\_z^{k})$\; +$kernel\_testConverge (d_?z_{max},d_Z^{k},d_Z^{k-1})$\; +} +\end{algorithm} +~\\ + +After the initialization step, all data of the root finding problem to be solved must be copied from the CPU memory to the GPU global memory, because the GPUs only work on the data filled in their memories. Next, all the data-parallel arithmetic operations inside the main loop \verb=(do ... while(...))= are executed as kernels by the GPU. The first kernel \textit{save} in line( 6, Algorithm 2) consist to save the vector of polynomial's root found at the previous time step on GPU memory, in order to test the convergence of the root at each iteration in line (8, Algorithme2). + +The second kernel executes the iterative function and update Z(k),as formula (), we notice that the kernel update are called in two forms, separated with the value of R which determines the radius beyond which we apply the logarithm formula like this: + +\begin{algorithm}[H] +\LinesNumbered +\caption{A global Algorithm for the iterative function} + +\eIf{$(\left|Z^{(k)}\right|<= R)$}{ +$kernel\_update(d\_z^{k})$\;} +{ +$kernel\_update\_Log(d\_z^{k})$\; +} +\end{algorithm} + +The first form execute the formula(8) if all the module's $( |Z(k)|<= R)$, else the kernel execute the formulas(13,14).the radius R was computed like: + +$$R = \exp( \log(DBL\_MAX) / (2*(double).N) )$$ + +where N the degree of the polynomial,DBL\_MAX is the maximum value of a double. +The last kernel verify the convergence of the root after each update of $Z^{(k)}$, as formula(), we used the function of the CUBLAS Library (CUDA Basic Linear Algebra Subroutines) to implement this kernel. + +The kernels terminates its computations when all the root are converged. Finally, the solution of the root finding problem is copied back from the GPU global memory to the CPU memory. We use the communication functions of CUDA for the memory allocations in the GPU \verb=(cudaMalloc())= and the data transfers from the CPU memory to the GPU memory \verb=(cudaMemcpyHostToDevice)= +or from the GPU memory to the CPU memory \verb=(cudaMemcpyDeviceToHost))=. + + + + \subsubsection{the kernel corresponding } \subsubsection{Comparison between sequential algorithm and GPU algorithm } \bibliographystyle{plain}