From 07790aab169b2610a86ff0391f11bd114de18491 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Thu, 22 Nov 2007 15:40:46 +0000 Subject: [PATCH] Updated prologs for Krylov subspace methods. --- krylov/psb_dbicg.f90 | 103 ++++++++------ krylov/psb_dcg.f90 | 44 ++++-- krylov/psb_dcgs.f90 | 43 ++++-- krylov/psb_dcgstab.F90 | 47 +++++-- krylov/psb_dcgstabl.f90 | 48 +++++-- krylov/psb_dgmresr.f90 | 46 +++++-- krylov/psb_krylov_mod.f90 | 278 +++++++++++++++++++++++++------------- krylov/psb_zcgs.f90 | 120 +++++++++------- krylov/psb_zcgstab.f90 | 51 ++++--- krylov/psb_zgmresr.f90 | 50 +++++-- 10 files changed, 540 insertions(+), 290 deletions(-) diff --git a/krylov/psb_dbicg.f90 b/krylov/psb_dbicg.f90 index ed27e30b..97aec5e9 100644 --- a/krylov/psb_dbicg.f90 +++ b/krylov/psb_dbicg.f90 @@ -60,21 +60,36 @@ ! This subroutine implements the BiCG method. ! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! istop - integer(optional). The stopping criterium. ! -subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err, itrace,istop) +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - real,dimension(:) Input: vector containing the +! right hand side B +! x - real,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +! +subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop) use psb_base_mod use psb_prec_mod implicit none @@ -168,11 +183,11 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& if (info == 0) call psb_geall(wwrk,desc_a,info,n=9) if (info == 0) call psb_geasb(wwrk,desc_a,info) if(info.ne.0) then - info=4011 - ch_err='psb_asb' - err=info - call psb_errpush(info,name,a_err=ch_err) - goto 9999 + info=4011 + ch_err='psb_asb' + err=info + call psb_errpush(info,name,a_err=ch_err) + goto 9999 end if q => wwrk(:,1) @@ -198,21 +213,21 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& end if itx = 0 - + if (istop_ == 1) then - ani = psb_spnrmi(a,desc_a,info) - bni = psb_geamax(b,desc_a,info) + ani = psb_spnrmi(a,desc_a,info) + bni = psb_geamax(b,desc_a,info) else if (istop_ == 2) then - bn2 = psb_genrm2(b,desc_a,info) + bn2 = psb_genrm2(b,desc_a,info) endif - + if(info.ne.0) then - info=4011 - err=info - call psb_errpush(info,name,a_err=ch_err) - goto 9999 + info=4011 + err=info + call psb_errpush(info,name,a_err=ch_err) + goto 9999 end if - + restart: do !!$ !!$ r0 = b-ax0 @@ -224,9 +239,9 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& if (debug) write(0,*) me,' Done spmm',info if (info == 0) call psb_geaxpby(done,r,dzero,rt,desc_a,info) if(info.ne.0) then - info=4011 - call psb_errpush(info,name) - goto 9999 + info=4011 + call psb_errpush(info,name) + goto 9999 end if rho = dzero @@ -238,9 +253,9 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& rni = psb_genrm2(r,desc_a,info) endif if(info.ne.0) then - info=4011 - call psb_errpush(info,name) - goto 9999 + info=4011 + call psb_errpush(info,name) + goto 9999 end if if (istop_ == 1) then @@ -251,11 +266,11 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& endif if(info.ne.0) then - info=4011 - call psb_errpush(info,name) - goto 9999 + info=4011 + call psb_errpush(info,name) + goto 9999 end if - + if (rerr<=eps) then exit restart end if @@ -336,7 +351,7 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& If (itrace_ > 0) then if (me == 0) write(*,'(a,i4,3(2x,es10.4))') 'bicg: ',itx,rerr end If - + if (present(err)) err=rerr if (present(iter)) iter = itx if (rerr>eps) then @@ -352,8 +367,8 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& call psb_restore_coher(ictxt,isvch) if(info/=0) then - call psb_errpush(info,name) - goto 9999 + call psb_errpush(info,name) + goto 9999 end if call psb_erractionrestore(err_act) @@ -362,8 +377,8 @@ subroutine psb_dbicg(a,prec,b,x,eps,desc_a,info,& 9999 continue call psb_erractionrestore(err_act) if (err_act.eq.psb_act_abort_) then - call psb_error() - return + call psb_error() + return end if return diff --git a/krylov/psb_dcg.f90 b/krylov/psb_dcg.f90 index 02a2f78f..01d035f8 100644 --- a/krylov/psb_dcg.f90 +++ b/krylov/psb_dcg.f90 @@ -59,22 +59,38 @@ ! Subroutine: psb_dcg ! This subroutine implements the Conjugate Gradient method. ! +! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! istop - integer(optional). The stopping criterium. ! -Subroutine psb_dcg(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err, itrace, istop) +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - real,dimension(:) Input: vector containing the +! right hand side B +! x - real,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +! +Subroutine psb_dcg(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop) use psb_base_mod use psb_prec_mod implicit none diff --git a/krylov/psb_dcgs.f90 b/krylov/psb_dcgs.f90 index 209a35f7..741522e4 100644 --- a/krylov/psb_dcgs.f90 +++ b/krylov/psb_dcgs.f90 @@ -56,20 +56,39 @@ ! File: psb_dcgs.f90 ! ! Subroutine: psb_dcgs +! Implements the Conjugate Gradient Squared method. +! ! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! istop - integer(optional). The stopping criterium. +! +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - real,dimension(:) Input: vector containing the +! right hand side B +! x - real,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +! ! Subroutine psb_dcgs(a,prec,b,x,eps,desc_a,info,& &itmax,iter,err,itrace,istop) diff --git a/krylov/psb_dcgstab.F90 b/krylov/psb_dcgstab.F90 index 6cf14bac..705249a2 100644 --- a/krylov/psb_dcgstab.F90 +++ b/krylov/psb_dcgstab.F90 @@ -56,24 +56,41 @@ ! File: psb_dcgstab.f90 ! ! Subroutine: psb_dcgstab -! This subroutine implements the CG Stabilized method. +! This subroutine implements the BiCG Stabilized method. +! ! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! istop - integer(optional). The stopping criterium. ! -Subroutine psb_dcgstab(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace, istop) +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - real,dimension(:) Input: vector containing the +! right hand side B +! x - real,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +! +! +Subroutine psb_dcgstab(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop) use psb_base_mod use psb_prec_mod Implicit None diff --git a/krylov/psb_dcgstabl.f90 b/krylov/psb_dcgstabl.f90 index a019d5bd..443f4e8d 100644 --- a/krylov/psb_dcgstabl.f90 +++ b/krylov/psb_dcgstabl.f90 @@ -63,23 +63,43 @@ ! File: psb_dcgstabl.f90 ! ! Subroutine: psb_dcgstabl +! Implements the BICGSTAB(L) method +! ! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! istop - integer(optional). The stopping criterium. ! -Subroutine psb_dcgstabl(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,irst,istop) +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - real,dimension(:) Input: vector containing the +! right hand side B +! x - real,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! irst - integer(optional) Input: restart parameter L +! +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +! +! +Subroutine psb_dcgstabl(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,irst,istop) use psb_base_mod use psb_prec_mod implicit none diff --git a/krylov/psb_dgmresr.f90 b/krylov/psb_dgmresr.f90 index d4749508..04e5bf42 100644 --- a/krylov/psb_dgmresr.f90 +++ b/krylov/psb_dgmresr.f90 @@ -70,23 +70,39 @@ ! This subroutine implements the restarted GMRES method with right ! preconditioning. ! +! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! irst - integer(optional). The restart value. -! istop - integer(optional). The stopping criterium. ! -Subroutine psb_dgmresr(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,irst,istop) +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - real,dimension(:) Input: vector containing the +! right hand side B +! x - real,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! irst - integer(optional) Input: restart parameter +! +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +Subroutine psb_dgmresr(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,irst,istop) use psb_base_mod use psb_prec_mod implicit none diff --git a/krylov/psb_krylov_mod.f90 b/krylov/psb_krylov_mod.f90 index d8e43bb3..30a9d0d2 100644 --- a/krylov/psb_krylov_mod.f90 +++ b/krylov/psb_krylov_mod.f90 @@ -36,72 +36,72 @@ Module psb_krylov_mod end interface interface psb_cg - subroutine psb_dcg(a,prec,b,x,eps,& - & desc_a,info,itmax,iter,err,itrace,istop) - use psb_base_mod - use psb_prec_mod - type(psb_dspmat_type), intent(in) :: a - type(psb_desc_type), intent(in) :: desc_a - real(kind(1.d0)), intent(in) :: b(:) - real(kind(1.d0)), intent(inout) :: x(:) - real(kind(1.d0)), intent(in) :: eps - type(psb_dprec_type), intent(in) :: prec - integer, intent(out) :: info - integer, optional, intent(in) :: itmax, itrace,istop - integer, optional, intent(out) :: iter - real(kind(1.d0)), optional, intent(out) :: err - end subroutine psb_dcg + subroutine psb_dcg(a,prec,b,x,eps,& + & desc_a,info,itmax,iter,err,itrace,istop) + use psb_base_mod + use psb_prec_mod + type(psb_dspmat_type), intent(in) :: a + type(psb_desc_type), intent(in) :: desc_a + real(kind(1.d0)), intent(in) :: b(:) + real(kind(1.d0)), intent(inout) :: x(:) + real(kind(1.d0)), intent(in) :: eps + type(psb_dprec_type), intent(in) :: prec + integer, intent(out) :: info + integer, optional, intent(in) :: itmax, itrace,istop + integer, optional, intent(out) :: iter + real(kind(1.d0)), optional, intent(out) :: err + end subroutine psb_dcg end interface interface psb_bicg - subroutine psb_dbicg(a,prec,b,x,eps,& - & desc_a,info,itmax,iter,err,itrace,istop) - use psb_base_mod - use psb_prec_mod - type(psb_dspmat_type), intent(in) :: a - type(psb_desc_type), intent(in) :: desc_a - real(kind(1.d0)), intent(in) :: b(:) - real(kind(1.d0)), intent(inout) :: x(:) - real(kind(1.d0)), intent(in) :: eps - type(psb_dprec_type), intent(in) :: prec - integer, intent(out) :: info - integer, optional, intent(in) :: itmax, itrace,istop - integer, optional, intent(out) :: iter - real(kind(1.d0)), optional, intent(out) :: err - end subroutine psb_dbicg + subroutine psb_dbicg(a,prec,b,x,eps,& + & desc_a,info,itmax,iter,err,itrace,istop) + use psb_base_mod + use psb_prec_mod + type(psb_dspmat_type), intent(in) :: a + type(psb_desc_type), intent(in) :: desc_a + real(kind(1.d0)), intent(in) :: b(:) + real(kind(1.d0)), intent(inout) :: x(:) + real(kind(1.d0)), intent(in) :: eps + type(psb_dprec_type), intent(in) :: prec + integer, intent(out) :: info + integer, optional, intent(in) :: itmax, itrace,istop + integer, optional, intent(out) :: iter + real(kind(1.d0)), optional, intent(out) :: err + end subroutine psb_dbicg end interface interface psb_bicgstab - subroutine psb_dcgstab(a,prec,b,x,eps,& - & desc_a,info,itmax,iter,err,itrace,istop) - use psb_base_mod - use psb_prec_mod - type(psb_dspmat_type), intent(in) :: a - type(psb_desc_type), intent(in) :: desc_a - real(kind(1.d0)), intent(in) :: b(:) - real(kind(1.d0)), intent(inout) :: x(:) - real(kind(1.d0)), intent(in) :: eps - type(psb_dprec_type), intent(in) :: prec - integer, intent(out) :: info - integer, optional, intent(in) :: itmax, itrace,istop - integer, optional, intent(out) :: iter - real(kind(1.d0)), optional, intent(out) :: err - end subroutine psb_dcgstab - subroutine psb_zcgstab(a,prec,b,x,eps,& - & desc_a,info,itmax,iter,err,itrace,istop) - use psb_base_mod - use psb_prec_mod - type(psb_zspmat_type), intent(in) :: a - type(psb_desc_type), intent(in) :: desc_a - complex(kind(1.d0)), intent(in) :: b(:) - complex(kind(1.d0)), intent(inout) :: x(:) - real(kind(1.d0)), intent(in) :: eps - type(psb_zprec_type), intent(in) :: prec - integer, intent(out) :: info - integer, optional, intent(in) :: itmax, itrace,istop - integer, optional, intent(out) :: iter - real(kind(1.d0)), optional, intent(out) :: err - end subroutine psb_zcgstab + subroutine psb_dcgstab(a,prec,b,x,eps,& + & desc_a,info,itmax,iter,err,itrace,istop) + use psb_base_mod + use psb_prec_mod + type(psb_dspmat_type), intent(in) :: a + type(psb_desc_type), intent(in) :: desc_a + real(kind(1.d0)), intent(in) :: b(:) + real(kind(1.d0)), intent(inout) :: x(:) + real(kind(1.d0)), intent(in) :: eps + type(psb_dprec_type), intent(in) :: prec + integer, intent(out) :: info + integer, optional, intent(in) :: itmax, itrace,istop + integer, optional, intent(out) :: iter + real(kind(1.d0)), optional, intent(out) :: err + end subroutine psb_dcgstab + subroutine psb_zcgstab(a,prec,b,x,eps,& + & desc_a,info,itmax,iter,err,itrace,istop) + use psb_base_mod + use psb_prec_mod + type(psb_zspmat_type), intent(in) :: a + type(psb_desc_type), intent(in) :: desc_a + complex(kind(1.d0)), intent(in) :: b(:) + complex(kind(1.d0)), intent(inout) :: x(:) + real(kind(1.d0)), intent(in) :: eps + type(psb_zprec_type), intent(in) :: prec + integer, intent(out) :: info + integer, optional, intent(in) :: itmax, itrace,istop + integer, optional, intent(out) :: iter + real(kind(1.d0)), optional, intent(out) :: err + end subroutine psb_zcgstab end interface interface psb_bicgstabl @@ -171,25 +171,70 @@ Module psb_krylov_mod integer, optional, intent(out) :: iter real(kind(1.d0)), optional, intent(out) :: err end subroutine psb_dcgs - subroutine psb_zcgs(a,prec,b,x,eps,& - & desc_a,info,itmax,iter,err,itrace,istop) - use psb_base_mod - use psb_prec_mod - type(psb_zspmat_type), intent(in) :: a - type(psb_desc_type), intent(in) :: desc_a - complex(kind(1.d0)), intent(in) :: b(:) - complex(kind(1.d0)), intent(inout) :: x(:) - real(kind(1.d0)), intent(in) :: eps - type(psb_zprec_type), intent(in) :: prec - integer, intent(out) :: info - integer, optional, intent(in) :: itmax, itrace,istop - integer, optional, intent(out) :: iter - real(kind(1.d0)), optional, intent(out) :: err - end subroutine psb_zcgs + subroutine psb_zcgs(a,prec,b,x,eps,& + & desc_a,info,itmax,iter,err,itrace,istop) + use psb_base_mod + use psb_prec_mod + type(psb_zspmat_type), intent(in) :: a + type(psb_desc_type), intent(in) :: desc_a + complex(kind(1.d0)), intent(in) :: b(:) + complex(kind(1.d0)), intent(inout) :: x(:) + real(kind(1.d0)), intent(in) :: eps + type(psb_zprec_type), intent(in) :: prec + integer, intent(out) :: info + integer, optional, intent(in) :: itmax, itrace,istop + integer, optional, intent(out) :: iter + real(kind(1.d0)), optional, intent(out) :: err + end subroutine psb_zcgs end interface - -contains +contains + ! + ! File: psb_krylov_mod.f90 + ! + ! Subroutine: psb_dkrylov + ! + ! Front-end for the Krylov subspace iterations, real version + ! + ! Arguments: + ! + ! methd - character The specific method; can take the values: + ! CG + ! CGS + ! BICG + ! BICGSTAB + ! BICGSTABL + ! RGMRES + ! + ! a - type() Input: sparse matrix containing A. + ! prec - type() Input: preconditioner + ! b - real,dimension(:) Input: vector containing the + ! right hand side B + ! x - real,dimension(:) Input/Output: vector containing the + ! initial guess and final solution X. + ! eps - real Input: Stopping tolerance; the iteration is + ! stopped when the error estimate + ! |err| <= eps + ! desc_a - type(). Input: The communication descriptor. + ! info - integer. Output: Return code + ! + ! itmax - integer(optional) Input: maximum number of iterations to be + ! performed. + ! iter - integer(optional) Output: how many iterations have been + ! performed. + ! err - real (optional) Output: error estimate on exit + ! itrace - integer(optional) Input: print an informational message + ! with the error estimate every itrace + ! iterations + ! irst - integer(optional) Input: restart parameter for RGMRES and + ! BICGSTAB(L) methods + ! istop - integer(optional) Input: stopping criterion, or how + ! to estimate the error. + ! 1: err = |r|/|b| + ! 2: err = |r|/(|a||x|+|b|) + ! where r is the (preconditioned, recursive + ! estimate of) residual + ! Subroutine psb_dkrylov(method,a,prec,b,x,eps,desc_a,info,& &itmax,iter,err,itrace,irst,istop) @@ -218,53 +263,96 @@ contains ictxt=psb_cd_get_context(desc_a) - + call psb_info(ictxt, me, np) select case(toupper(method)) case('CG') call psb_cg(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) + &itmax,iter,err,itrace,istop) case('CGS') call psb_cgs(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) + &itmax,iter,err,itrace,istop) case('BICG') call psb_bicg(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) + &itmax,iter,err,itrace,istop) case('BICGSTAB') call psb_bicgstab(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) + &itmax,iter,err,itrace,istop) case('RGMRES') call psb_rgmres(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,irst,istop) + &itmax,iter,err,itrace,irst,istop) case('BICGSTABL') call psb_bicgstabl(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,irst,istop) + &itmax,iter,err,itrace,irst,istop) case default if (me==0) write(0,*) 'Warning: Unknown method ',method,& & ' in PSB_KRYLOV, defaulting to BiCGSTAB' call psb_bicgstab(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) + &itmax,iter,err,itrace,istop) end select if(info/=0) then call psb_errpush(info,name) goto 9999 end if - + call psb_erractionrestore(err_act) return - + 9999 continue call psb_erractionrestore(err_act) if (err_act.eq.psb_act_abort_) then call psb_error(ictxt) return end if - + end subroutine psb_dkrylov + ! + ! File: psb_krylov_mod.f90 + ! + ! Subroutine: psb_zkrylov + ! + ! Front-end for the Krylov subspace iterations, complexversion + ! + ! Arguments: + ! + ! methd - character The specific method; can take the values: + ! CGS + ! BICGSTAB + ! RGMRES + ! + ! a - type() Input: sparse matrix containing A. + ! prec - type() Input: preconditioner + ! b - complex,dimension(:) Input: vector containing the + ! right hand side B + ! x - complex,dimension(:) Input/Output: vector containing the + ! initial guess and final solution X. + ! eps - real Input: Stopping tolerance; the iteration is + ! stopped when the error estimate + ! |err| <= eps + ! desc_a - type(). Input: The communication descriptor. + ! info - integer. Output: Return code + ! + ! itmax - integer(optional) Input: maximum number of iterations to be + ! performed. + ! iter - integer(optional) Output: how many iterations have been + ! performed. + ! err - real (optional) Output: error estimate on exit + ! itrace - integer(optional) Input: print an informational message + ! with the error estimate every itrace + ! iterations + ! irst - integer(optional) Input: restart parameter for RGMRES and + ! BICGSTAB(L) methods + ! istop - integer(optional) Input: stopping criterion, or how + ! to estimate the error. + ! 1: err = |r|/|b| + ! 2: err = |r|/(|a||x|+|b|) + ! where r is the (preconditioned, recursive + ! estimate of) residual + ! Subroutine psb_zkrylov(method,a,prec,b,x,eps,desc_a,info,& &itmax,iter,err,itrace,irst,istop) use psb_base_mod @@ -290,9 +378,9 @@ contains ictxt=psb_cd_get_context(desc_a) - + call psb_info(ictxt, me, np) - + select case(toupper(method)) !!$ case('CG') @@ -300,7 +388,7 @@ contains !!$ &itmax,iter,err,itrace,istop) case('CGS') call psb_cgs(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) + &itmax,iter,err,itrace,istop) !!$ case('BICG') !!$ call psb_bicg(a,prec,b,x,eps,desc_a,info,& !!$ &itmax,iter,err,itrace,istop) @@ -317,24 +405,24 @@ contains if (me==0) write(0,*) 'Warning: Unknown method ',method,& & ' in PSB_KRYLOV, defaulting to BiCGSTAB' call psb_bicgstab(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) + &itmax,iter,err,itrace,istop) end select if(info/=0) then call psb_errpush(info,name) goto 9999 end if - + call psb_erractionrestore(err_act) return - + 9999 continue call psb_erractionrestore(err_act) if (err_act.eq.psb_act_abort_) then call psb_error(ictxt) return end if - + end subroutine psb_zkrylov diff --git a/krylov/psb_zcgs.f90 b/krylov/psb_zcgs.f90 index 0dfca64a..fda690ce 100644 --- a/krylov/psb_zcgs.f90 +++ b/krylov/psb_zcgs.f90 @@ -56,23 +56,43 @@ ! File: psb_zcgs.f90 ! ! Subroutine: psb_zcgs -! +! Implements the Conjugate Gradient Squared method. +! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! istop - integer(optional). The stopping criterium. ! -Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace,istop) +! methd - character The specific method; can take the values: +! CGS +! BICGSTAB +! RGMRES +! +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - complex,dimension(:) Input: vector containing the +! right hand side B +! x - complex,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop) use psb_base_mod use psb_prec_mod implicit none @@ -123,17 +143,17 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& Else istop_ = 1 Endif -! -! istop_ = 1: normwise backward error, infinity norm -! istop_ = 2: ||r||/||b|| norm 2 -! + ! + ! istop_ = 1: normwise backward error, infinity norm + ! istop_ = 2: ||r||/||b|| norm 2 + ! !!$ !!$ If ((prec%prec < 0).Or.(prec%prec > 6) ) Then !!$ Write(0,*) 'f90_cgstab: invalid iprec',prec%prec !!$ If (Present(ierr)) ierr=-1 !!$ Return !!$ Endif - + if ((istop_ < 1 ).or.(istop_ > 2 ) ) then write(0,*) 'psb_cgs: invalid istop',istop_ info=5001 @@ -161,9 +181,9 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& if (info == 0) Call psb_geall(wwrk,desc_a,info,n=11) if (info == 0) Call psb_geasb(wwrk,desc_a,info) if (info.ne.0) Then - info=4011 - call psb_errpush(info,name) - goto 9999 + info=4011 + call psb_errpush(info,name) + goto 9999 End If q => wwrk(:,1) @@ -186,14 +206,14 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& Endif If (Present(itrace)) Then - itrace_ = itrace + itrace_ = itrace Else - itrace_ = 0 + itrace_ = 0 End If ! Ensure global coherence for convergence checks. call psb_set_coher(ictxt,isvch) - + itx = 0 if (istop_ == 1) then @@ -203,9 +223,9 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& bn2 = psb_genrm2(b,desc_a,info) endif if(info/=0)then - info=4011 - call psb_errpush(info,name) - goto 9999 + info=4011 + call psb_errpush(info,name) + goto 9999 end if restart: Do @@ -218,11 +238,11 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& Call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux) Call psb_geaxpby(zone,r,zzero,rt,desc_a,info) if(info/=0)then - info=4011 - call psb_errpush(info,name) - goto 9999 + info=4011 + call psb_errpush(info,name) + goto 9999 end if - + rho = zzero If (debug) Write(*,*) 'on entry to amax: b: ',Size(b) @@ -235,11 +255,11 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& rerr = rni/bn2 endif if(info/=0)then - info=4011 - call psb_errpush(info,name) - goto 9999 + info=4011 + call psb_errpush(info,name) + goto 9999 end if - + If (rerr<=eps) Then Exit restart End If @@ -255,7 +275,7 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& rho_old = rho rho = psb_gedot(rt,r,desc_a,info) If (rho==zzero) Then - If (debug) Write(0,*) 'cgs iteration breakdown r',rho + If (debug) Write(0,*) 'cgs iteration breakdown r',rho Exit iteration Endif @@ -278,27 +298,27 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& sigma = psb_gedot(rt,v,desc_a,info) If (sigma==zzero) Then - If (debug) Write(0,*) 'cgs iteration breakdown s1', sigma - Exit iteration + If (debug) Write(0,*) 'cgs iteration breakdown s1', sigma + Exit iteration Endif - + alpha = rho/sigma Call psb_geaxpby(zone,uv,zzero,q,desc_a,info) Call psb_geaxpby(-alpha,v,zone,q,desc_a,info) Call psb_geaxpby(zone,uv,zzero,s,desc_a,info) Call psb_geaxpby(zone,q,zone,s,desc_a,info) - + Call psb_precaply(prec,s,z,desc_a,info,work=aux) Call psb_geaxpby(alpha,z,zone,x,desc_a,info) Call psb_spmm(zone,a,z,zzero,qt,desc_a,info,& & work=aux) - + Call psb_geaxpby(-alpha,qt,zone,r,desc_a,info) - - + + if (istop_ == 1) then rni = psb_geamax(r,desc_a,info) xni = psb_geamax(x,desc_a,info) @@ -317,7 +337,7 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& if ((mod(itx,itrace_)==0).and.(me == 0))& & write(*,'(a,i4,3(2x,es10.4))') 'cgs: ',itx,rerr end If - + End Do iteration End Do restart If (itrace_ > 0) then @@ -338,8 +358,8 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& call psb_restore_coher(ictxt,isvch) if(info/=0) then - call psb_errpush(info,name) - goto 9999 + call psb_errpush(info,name) + goto 9999 end if call psb_erractionrestore(err_act) @@ -348,8 +368,8 @@ Subroutine psb_zcgs(a,prec,b,x,eps,desc_a,info,& 9999 continue call psb_erractionrestore(err_act) if (err_act.eq.psb_act_abort_) then - call psb_error() - return + call psb_error() + return end if return diff --git a/krylov/psb_zcgstab.f90 b/krylov/psb_zcgstab.f90 index 18b7dd39..9e633c3c 100644 --- a/krylov/psb_zcgstab.f90 +++ b/krylov/psb_zcgstab.f90 @@ -56,25 +56,44 @@ ! File: psb_zcgstab.f90 ! ! Subroutine: psb_zcgstab -! This subroutine implements the CG Stabilized method. +! This subroutine implements the BiCG Stabilized method. ! +! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the -! preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! istop - integer(optional). The stopping criterium. ! -Subroutine psb_zcgstab(a,prec,b,x,eps,desc_a,info,& - &itmax,iter,err,itrace, istop) +! methd - character The specific method; can take the values: +! CGS +! BICGSTAB +! RGMRES +! +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - complex,dimension(:) Input: vector containing the +! right hand side B +! x - complex,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +Subroutine psb_zcgstab(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop) use psb_base_mod use psb_prec_mod Implicit None diff --git a/krylov/psb_zgmresr.f90 b/krylov/psb_zgmresr.f90 index a9d8d7c4..c4bddea6 100644 --- a/krylov/psb_zgmresr.f90 +++ b/krylov/psb_zgmresr.f90 @@ -71,22 +71,42 @@ ! preconditioning. ! ! Arguments: -! a - type(). The sparse matrix containing A. -! prec - type(). The data structure containing the preconditioner. -! b - real,dimension(:). The right hand side. -! x - real,dimension(:). The vector of unknowns. -! eps - real. The error tolerance. -! desc_a - type(). The communication descriptor. -! info - integer. Return code -! itmax - integer(optional). The maximum number of iterations. -! iter - integer(optional). The number of iterations performed. -! err - real(optional). The error on return. -! itrace - integer(optional). The unit to write messages onto. -! irst - integer(optional). The restart value. -! istop - integer(optional). The stopping criterium. ! -Subroutine psb_zgmresr(a,prec,b,x,eps,desc_a,info,& - & itmax,iter,err,itrace,irst,istop) +! methd - character The specific method; can take the values: +! CGS +! BICGSTAB +! RGMRES +! +! a - type() Input: sparse matrix containing A. +! prec - type() Input: preconditioner +! b - complex,dimension(:) Input: vector containing the +! right hand side B +! x - complex,dimension(:) Input/Output: vector containing the +! initial guess and final solution X. +! eps - real Input: Stopping tolerance; the iteration is +! stopped when the error estimate +! |err| <= eps +! desc_a - type(). Input: The communication descriptor. +! info - integer. Output: Return code +! +! itmax - integer(optional) Input: maximum number of iterations to be +! performed. +! iter - integer(optional) Output: how many iterations have been +! performed. +! err - real (optional) Output: error estimate on exit +! itrace - integer(optional) Input: print an informational message +! with the error estimate every itrace +! iterations +! irst - integer(optional) Input: restart parameter +! +! istop - integer(optional) Input: stopping criterion, or how +! to estimate the error. +! 1: err = |r|/|b| +! 2: err = |r|/(|a||x|+|b|) +! where r is the (preconditioned, recursive +! estimate of) residual +! +Subroutine psb_zgmresr(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,irst,istop) use psb_base_mod use psb_prec_mod implicit none