mirror of
https://github.com/sfilippone/amg4psblas.git
synced 2026-10-24 14:51:50 +00:00
New GPU comments and sample program in docs.
This commit is contained in:
+159
-18
@@ -419,41 +419,182 @@ call P%build(A,desc_A,info)
|
||||
|
||||
\subsection{GPU example\label{sec:gpu-example}}
|
||||
|
||||
The code reported in Figure~\ref{fig:gpu-ex1} shows how to set up a
|
||||
The code discussed here shows how to set up a
|
||||
program exploiting the combined GPU capabilities of PSBLAS and
|
||||
AMG4PSBLAS.
|
||||
AMG4PSBLAS. The code example is availabile in the source distribution
|
||||
directory \verb|amg4psblas/tests/gpu|.
|
||||
|
||||
First of all, we need to include the appropriate modules and
|
||||
declare some auxiliary variables:
|
||||
\begin{listing}[h!]
|
||||
\ifpdf
|
||||
\begin{minted}[breaklines=true,bgcolor=bg,fontsize=\small]{fortran}
|
||||
! build a one-level RAS with overlap 2 and ILU(0) on the local blocks.
|
||||
call P%init('AS',info)
|
||||
call P%set('SUB_OVR',2,info)
|
||||
call P%build(A,desc_A,info)
|
||||
... ...
|
||||
! solve Ax=b with preconditioned BiCGSTAB
|
||||
call psb_krylov('BICGSTAB',A,P,b,x,tol,desc_A,info)
|
||||
program amg_d_pde3d
|
||||
use psb_base_mod
|
||||
use amg_prec_mod
|
||||
use psb_krylov_mod
|
||||
use psb_util_mod
|
||||
use psb_gpu_mod
|
||||
use data_input
|
||||
use amg_d_pde3d_base_mod
|
||||
use amg_d_pde3d_exp_mod
|
||||
use amg_d_pde3d_gauss_mod
|
||||
use amg_d_genpde_mod
|
||||
implicit none
|
||||
.......
|
||||
! GPU variables
|
||||
type(psb_d_hlg_sparse_mat) :: agmold
|
||||
type(psb_d_vect_gpu) :: vgmold
|
||||
type(psb_i_vect_gpu) :: igmold
|
||||
\end{minted}
|
||||
\else
|
||||
\begin{center}
|
||||
\begin{minipage}{.90\textwidth}
|
||||
{\small
|
||||
\begin{verbatim}
|
||||
! build a one-level RAS with overlap 2 and ILU(0) on the local blocks.
|
||||
call P%init('AS',info)
|
||||
call P%set('SUB_OVR',2,info)
|
||||
call P%build(A,desc_A,info)
|
||||
... ...
|
||||
! solve Ax=b with preconditioned BiCGSTAB
|
||||
call psb_krylov('BICGSTAB',A,P,b,x,tol,desc_A,info)
|
||||
\end{verbatim}
|
||||
program amg_d_pde3d
|
||||
use psb_base_mod
|
||||
use amg_prec_mod
|
||||
use psb_krylov_mod
|
||||
use psb_util_mod
|
||||
use psb_gpu_mod
|
||||
use data_input
|
||||
use amg_d_pde3d_base_mod
|
||||
use amg_d_pde3d_exp_mod
|
||||
use amg_d_pde3d_gauss_mod
|
||||
use amg_d_genpde_mod
|
||||
implicit none
|
||||
.......
|
||||
! GPU variables
|
||||
type(psb_d_hlg_sparse_mat) :: agmold
|
||||
type(psb_d_vect_gpu) :: vgmold
|
||||
type(psb_i_vect_gpu) :: igmold
|
||||
|
||||
\end{verbatim}
|
||||
}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
\fi
|
||||
\caption{setup of a one-level Schwarz preconditioner.\label{fig:gpu-ex1}}
|
||||
\caption{setup of a GPU-enabled test program part one.\label{fig:gpu-ex1}}
|
||||
\end{listing}
|
||||
|
||||
We then have to initialize the GPU environment, and pass the
|
||||
appropriate MOLD variables to the build methods
|
||||
\begin{listing}[h!]
|
||||
\ifpdf
|
||||
\begin{minted}[breaklines=true,bgcolor=bg,fontsize=\small]{fortran}
|
||||
call psb_init(ctxt)
|
||||
call psb_info(ctxt,iam,np)
|
||||
!
|
||||
! BEWARE: if you have NGPUS per node, the default is to
|
||||
! attach to mod(IAM,NGPUS)
|
||||
!
|
||||
call psb_gpu_init(ictxt)
|
||||
......
|
||||
t1 = psb_wtime()
|
||||
call prec%smoothers_build(a,desc_a,info, amold=agmold, vmold=vgmold, imold=igmold)
|
||||
|
||||
\end{minted}
|
||||
\else
|
||||
\begin{center}
|
||||
\begin{minipage}{.90\textwidth}
|
||||
{\small
|
||||
\begin{verbatim}
|
||||
call psb_init(ctxt)
|
||||
call psb_info(ctxt,iam,np)
|
||||
!
|
||||
! BEWARE: if you have NGPUS per node, the default is to
|
||||
! attach to mod(IAM,NGPUS)
|
||||
!
|
||||
call psb_gpu_init(ictxt)
|
||||
......
|
||||
t1 = psb_wtime()
|
||||
call prec%smoothers_build(a,desc_a,info, amold=agmold, vmold=vgmold, imold=igmold)
|
||||
|
||||
\end{verbatim}
|
||||
}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
\fi
|
||||
\caption{setup of a GPU-enabled test program part two.\label{fig:gpu-ex2}}
|
||||
\end{listing}
|
||||
Finally, we convert the input matrix, the descriptor and the vectors,
|
||||
then preallocate the preconditioner workspace before entering the
|
||||
Krylov method. At the end of the code, we close the GPU environment
|
||||
\begin{listing}[h!]
|
||||
\ifpdf
|
||||
\begin{minted}[breaklines=true,bgcolor=bg,fontsize=\small]{fortran}
|
||||
call desc_a%cnv(mold=igmold)
|
||||
call a%cscnv(info,mold=agmold)
|
||||
call psb_geasb(x,desc_a,info,mold=vgmold)
|
||||
call psb_geasb(b,desc_a,info,mold=vgmold)
|
||||
|
||||
!
|
||||
! iterative method parameters
|
||||
!
|
||||
call psb_barrier(ctxt)
|
||||
call prec%allocate_wrk(info)
|
||||
t1 = psb_wtime()
|
||||
call psb_krylov(s_choice%kmethd,a,prec,b,x,s_choice%eps,&
|
||||
& desc_a,info,itmax=s_choice%itmax,iter=iter,err=err,itrace=s_choice%itrace,&
|
||||
& istop=s_choice%istopc,irst=s_choice%irst)
|
||||
call prec%deallocate_wrk(info)
|
||||
call psb_barrier(ctxt)
|
||||
tslv = psb_wtime() - t1
|
||||
|
||||
......
|
||||
call psb_gpu_exit()
|
||||
call psb_exit(ctxt)
|
||||
stop
|
||||
|
||||
|
||||
\end{minted}
|
||||
\else
|
||||
\begin{center}
|
||||
\begin{minipage}{.90\textwidth}
|
||||
{\small
|
||||
\begin{verbatim}
|
||||
call desc_a%cnv(mold=igmold)
|
||||
call a%cscnv(info,mold=agmold)
|
||||
call psb_geasb(x,desc_a,info,mold=vgmold)
|
||||
call psb_geasb(b,desc_a,info,mold=vgmold)
|
||||
|
||||
!
|
||||
! iterative method parameters
|
||||
!
|
||||
call psb_barrier(ctxt)
|
||||
call prec%allocate_wrk(info)
|
||||
t1 = psb_wtime()
|
||||
call psb_krylov(s_choice%kmethd,a,prec,b,x,s_choice%eps,&
|
||||
& desc_a,info,itmax=s_choice%itmax,iter=iter,err=err,itrace=s_choice%itrace,&
|
||||
& istop=s_choice%istopc,irst=s_choice%irst)
|
||||
call prec%deallocate_wrk(info)
|
||||
call psb_barrier(ctxt)
|
||||
tslv = psb_wtime() - t1
|
||||
|
||||
......
|
||||
call psb_gpu_exit()
|
||||
call psb_exit(ctxt)
|
||||
stop
|
||||
|
||||
\end{verbatim}
|
||||
}
|
||||
\end{minipage}
|
||||
\end{center}
|
||||
\fi
|
||||
\caption{setup of a GPU-enabled test program part three.\label{fig:gpu-ex3}}
|
||||
\end{listing}
|
||||
|
||||
It is very important to employ solvers that are suited
|
||||
to the GPU, i.e. solvers that do NOT employ triangular
|
||||
system solve kernels. Solvers that satisfy this constraint include:
|
||||
\begin{itemize}
|
||||
\item \verb|JACOBI|
|
||||
\item \verb|INVK|
|
||||
\item \verb|INVT|
|
||||
\item \verb|AINV|
|
||||
\end{itemize}
|
||||
and their \verb|L1| variants.
|
||||
|
||||
%%% Local Variables:
|
||||
%%% mode: latex
|
||||
|
||||
Reference in New Issue
Block a user