mirror of
https://github.com/sfilippone/psblas3.git
synced 2026-10-07 07:04:57 +00:00
Restructuring linsolve.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
include ../../Make.inc
|
||||
|
||||
LIBDIR=../../lib
|
||||
INCDIR=../../include
|
||||
MODDIR=../../modules
|
||||
HERE=..
|
||||
OBJS=psb_dkrylov.o psb_skrylov.o psb_ckrylov.o psb_zkrylov.o \
|
||||
psb_drichardson.o psb_srichardson.o psb_crichardson.o psb_zrichardson.o \
|
||||
psb_dcgstab.o psb_dcg.o psb_dfcg.o psb_dgcr.o psb_dcgs.o \
|
||||
psb_dbicg.o psb_dcgstabl.o psb_drgmres.o\
|
||||
psb_scgstab.o psb_scg.o psb_sfcg.o psb_sgcr.o psb_scgs.o \
|
||||
psb_sbicg.o psb_scgstabl.o psb_srgmres.o\
|
||||
psb_ccgstab.o psb_ccg.o psb_cfcg.o psb_cgcr.o psb_ccgs.o \
|
||||
psb_cbicg.o psb_ccgstabl.o psb_crgmres.o\
|
||||
psb_zcgstab.o psb_zcg.o psb_zfcg.o psb_zgcr.o psb_zcgs.o \
|
||||
psb_zbicg.o psb_zcgstabl.o psb_zrgmres.o
|
||||
|
||||
LIBNAME=$(METHDLIBNAME)
|
||||
COBJS=
|
||||
FINCLUDES=$(FMFLAG).. $(FMFLAG)$(MODDIR)
|
||||
|
||||
objs: $(OBJS)
|
||||
lib: objs
|
||||
$(AR) $(HERE)/$(LIBNAME) $(OBJS)
|
||||
$(RANLIB) $(HERE)/$(LIBNAME)
|
||||
|
||||
veryclean: clean
|
||||
|
||||
clean:
|
||||
/bin/rm -f $(OBJS) $(LOCAL_MODS)
|
||||
@@ -0,0 +1,335 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
!
|
||||
! File: psb_cbicg.f90
|
||||
!
|
||||
! Subroutine: psb_cbicg
|
||||
! This subroutine implements the BiCG method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_type) Input: preconditioner
|
||||
! b(:) - complex Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - complex 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(psb_desc_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. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
|
||||
subroutine psb_cbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_spk_), optional, intent(out) :: err
|
||||
! !$ local data
|
||||
complex(psb_spk_), allocatable, target :: aux(:)
|
||||
type(psb_c_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_c_vect_type), pointer :: ww, q, r, p,&
|
||||
& zt, pt, z, rt, qt
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, istop_, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
logical, parameter :: exchange=.true., noexchange=.false.
|
||||
integer(psb_ipk_), parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
complex(psb_spk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name,ch_err
|
||||
character(len=*), parameter :: methdname='BiCG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_cbicg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! istop_ = 1: normwise backward error, infinity norm
|
||||
! istop_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
|
||||
allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=9_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
ch_err='psb_asb'
|
||||
err=info
|
||||
call psb_errpush(info,name,a_err=ch_err)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
pt => wwrk(6)
|
||||
z => wwrk(7)
|
||||
zt => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
itx = 0
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: do
|
||||
! !$
|
||||
! !$ r0 = b-ax0
|
||||
! !$
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(cone,b,czero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),' Done spmm',info
|
||||
if (info == psb_success_) call psb_geaxpby(cone,r,czero,rt,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = czero
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call prec%apply(rt,zt,desc_a,info,trans='c',work=aux)
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,z,desc_a,info)
|
||||
if (rho == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(cone,z,czero,p,desc_a,info)
|
||||
call psb_geaxpby(cone,zt,czero,pt,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(cone,z,beta,p,desc_a,info)
|
||||
call psb_geaxpby(cone,zt,beta,pt,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(cone,a,p,czero,q,desc_a,info,&
|
||||
& work=aux)
|
||||
call psb_spmm(cone,a,pt,czero,qt,desc_a,info,&
|
||||
& work=aux,trans='c')
|
||||
|
||||
sigma = psb_gedot(pt,q,desc_a,info)
|
||||
if (sigma == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,cone,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,cone,r,desc_a,info)
|
||||
call psb_geaxpby(-alpha,qt,cone,rt,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_cbicg_vect
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_ccg.f90
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_ccg.f90
|
||||
!
|
||||
! Subroutine: psb_ccg
|
||||
! This subroutine implements the Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_type) Input: preconditioner
|
||||
! b(:) - complex Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - complex 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_ccg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
complex(psb_spk_), allocatable, target :: aux(:),td(:),tu(:),eig(:),ewrk(:)
|
||||
integer(psb_mpk_), allocatable :: ibl(:), ispl(:), iwrk(:)
|
||||
type(psb_c_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_c_vect_type), pointer :: q, p, r, z, w
|
||||
complex(psb_spk_) :: alpha, beta, rho, rho_old, sigma,alpha_old,beta_old
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,err_act, ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
logical :: do_cond
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_ccg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
do_cond=present(cond)
|
||||
if (do_cond) then
|
||||
istebz = 0
|
||||
end if
|
||||
itx=0
|
||||
alpha = czero
|
||||
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-Ax0
|
||||
! =
|
||||
if (itx>= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(cone,b,czero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = czero
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
rho_old = rho
|
||||
rho = psb_gedot(r,z,desc_a,info)
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(cone,z,czero,p,desc_a,info)
|
||||
else
|
||||
if (rho_old == czero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown rho'
|
||||
exit iteration
|
||||
endif
|
||||
beta = rho/rho_old
|
||||
call psb_geaxpby(cone,z,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(cone,a,p,czero,q,desc_a,info,work=aux)
|
||||
sigma = psb_gedot(p,q,desc_a,info)
|
||||
if (sigma == czero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown sigma'
|
||||
exit iteration
|
||||
endif
|
||||
alpha_old = alpha
|
||||
alpha = rho/sigma
|
||||
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,cone,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,cone,r,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
if (do_cond) then
|
||||
cond = szero
|
||||
end if
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_ccg_vect
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_ccgs.f90
|
||||
!
|
||||
! Subroutine: psb_ccgs
|
||||
! Implements the Conjugate Gradient Squared method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_ccgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_spk_), allocatable, target :: aux(:)
|
||||
type(psb_c_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_c_vect_type), pointer :: ww, q, r, p, v,&
|
||||
& s, z, f, rt, qt, uv
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col,istop_, itx, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
complex(psb_spk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CGS'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_ccgs'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
Allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=11_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) Then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
v => wwrk(6)
|
||||
uv => wwrk(7)
|
||||
z => wwrk(8)
|
||||
f => wwrk(9)
|
||||
s => wwrk(10)
|
||||
ww => wwrk(11)
|
||||
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(cone,b,czero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_geaxpby(cone,r,czero,rt,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
rho = czero
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,r,desc_a,info)
|
||||
|
||||
if (rho == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(cone,r,czero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(cone,r,czero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(cone,r,czero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(beta,q,cone,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(cone,q,beta,p,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(cone,uv,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
if (info == psb_success_) call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(cone,a,f,czero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='First loop part ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(rt,v,desc_a,info)
|
||||
if (sigma == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(cone,uv,czero,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,v,cone,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(cone,uv,czero,s,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(cone,q,cone,s,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call prec%apply(s,z,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(alpha,z,cone,x,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(cone,a,z,czero,qt,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,qt,cone,r,desc_a,info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X update ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_ccgs_vect
|
||||
@@ -0,0 +1,393 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_ccgstab.f90
|
||||
!
|
||||
! Subroutine: psb_ccgstab
|
||||
! This subroutine implements the BiCG Stabilized method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_ccgstab_vect(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
class(psb_cprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = Local data
|
||||
complex(psb_spk_), allocatable, target :: aux(:),wwrk(:,:)
|
||||
type(psb_c_vect_type) :: q, r, p, v, s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it,itrace_,&
|
||||
& n_row, n_col
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., debug1 = .False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, err_act, i
|
||||
integer(psb_ipk_) :: istop_
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
complex(psb_spk_) :: alpha, beta, rho, rho_old, sigma, omega, tau
|
||||
type(psb_itconv_type) :: stopdat
|
||||
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_ccgstab'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
! = if (.not.same_type_as(x,b)) then
|
||||
! = write(0,*) 'Warning: different dynamic types for X and B '
|
||||
! = end if
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
naux=6*n_col
|
||||
if (info == psb_success_) allocate(aux(naux),stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
|
||||
call psb_geasb(q,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(r,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(p,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(v,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(s,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(t,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(z,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(f,desc_a,info,mold=x%v,scratch=.true.)
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(cone,b,czero,r,desc_a,info)
|
||||
|
||||
call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
call psb_geaxpby(cone,r,czero,q,desc_a,info)
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='Init residual chk')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
rho = czero
|
||||
|
||||
iteration: Do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(q,r,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call r%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rho: ',rho
|
||||
|
||||
if (rho == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown R',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(cone,r,czero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)*(alpha/omega)
|
||||
call psb_geaxpby(-omega,v,cone,p,desc_a,info)
|
||||
call psb_geaxpby(cone,r,beta,p,desc_a,info)
|
||||
End If
|
||||
|
||||
call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(cone,a,f,czero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
|
||||
sigma = psb_gedot(q,v,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call v%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Sigma: ',sigma
|
||||
|
||||
if (sigma == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
call psb_geaxpby(cone,r,czero,s,desc_a,info)
|
||||
call psb_geaxpby(-alpha,v,cone,s,desc_a,info)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' alpha: ',alpha
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='psb_geaxpby')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call prec%apply(s,z,desc_a,info,work=aux)
|
||||
Call psb_spmm(cone,a,z,czero,t,desc_a,info,work=aux)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='precaply/spmm')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(t,t,desc_a,info)
|
||||
if (sigma == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S2', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
tau = psb_gedot(t,s,desc_a,info)
|
||||
omega = tau/sigma
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call t%sync()
|
||||
call s%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' sigma, tau, omega: ',sigma, tau, omega
|
||||
|
||||
if (omega == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown O',omega
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
call psb_geaxpby(alpha,f,cone,x,desc_a,info)
|
||||
call psb_geaxpby(omega,z,cone,x,desc_a,info)
|
||||
call psb_geaxpby(cone,s,czero,r,desc_a,info)
|
||||
call psb_geaxpby(-omega,t,cone,r,desc_a,info)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X/R update ')
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
deallocate(aux,stat=info)
|
||||
|
||||
call x%sync()
|
||||
call psb_gefree(q,desc_a,info)
|
||||
call psb_gefree(r,desc_a,info)
|
||||
call psb_gefree(p,desc_a,info)
|
||||
call psb_gefree(v,desc_a,info)
|
||||
call psb_gefree(s,desc_a,info)
|
||||
call psb_gefree(t,desc_a,info)
|
||||
call psb_gefree(z,desc_a,info)
|
||||
call psb_gefree(f,desc_a,info)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_ccgstab_vect
|
||||
@@ -0,0 +1,421 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_ccgstabl.f90
|
||||
!
|
||||
! Subroutine: psb_ccgstabl
|
||||
! Implements the BICGSTAB(L) method
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_type) Input: preconditioner
|
||||
! b(:) - complex Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - complex 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration
|
||||
! is stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter L
|
||||
!
|
||||
!
|
||||
!
|
||||
Subroutine psb_ccgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
class(psb_cprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_spk_), allocatable, target :: aux(:), gamma(:),&
|
||||
& gamma1(:), gamma2(:), taum(:,:), sigma(:)
|
||||
type(psb_c_vect_type), allocatable, target :: wwrk(:),uh(:), rh(:)
|
||||
type(psb_c_vect_type), Pointer :: ww, q, r, rt0, p, v, &
|
||||
& s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, nl, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_,j, k
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
complex(psb_spk_) :: alpha, beta, rho, rho_old, rni, xni, bni, ani,bn2,&
|
||||
& omega
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab(L)'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_ccgstabl'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& 'present: irst: ',irst,nl
|
||||
else
|
||||
nl = 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),gamma(0:nl),gamma1(nl),&
|
||||
&gamma2(nl),taum(nl,nl),sigma(nl), stat=info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=10_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geall(uh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geall(rh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(uh,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(rh,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
r => wwrk(2)
|
||||
p => wwrk(3)
|
||||
v => wwrk(4)
|
||||
f => wwrk(5)
|
||||
s => wwrk(6)
|
||||
t => wwrk(7)
|
||||
z => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
rt0 => wwrk(10)
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),' restart: ',itx,it
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(cone,b,czero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call prec%apply(r,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(cone,r,czero,rt0,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(cone,r,czero,rh(0),desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(czero,r,czero,uh(0),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = cone
|
||||
alpha = czero
|
||||
omega = cone
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows()
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + nl
|
||||
itx = itx + nl
|
||||
rho = -omega*rho
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration: ',itx, rho
|
||||
|
||||
do j = 0, nl -1
|
||||
If (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'bicg part: ',j, nl
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rh(j),rt0,desc_a,info)
|
||||
if (rho == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
beta = alpha*rho/rho_old
|
||||
rho_old = rho
|
||||
do k=0, j
|
||||
! = call psb_geaxpby(cone,rh(:,0:j),-beta,uh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(cone,rh(k),-beta,uh(k),desc_a,info)
|
||||
end do
|
||||
call psb_spmm(cone,a,uh(j),czero,uh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(uh(j+1),desc_a,info)
|
||||
|
||||
gamma(j) = psb_gedot(uh(j+1),rt0,desc_a,info)
|
||||
|
||||
if (gamma(j) == czero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown s2',gamma(j)
|
||||
exit iteration
|
||||
endif
|
||||
alpha = rho/gamma(j)
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bicg part: alpha=r/g ',alpha,rho,gamma(j)
|
||||
|
||||
do k=0,j
|
||||
! = call psb_geaxpby(-alpha,uh(:,1:j+1),cone,rh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(-alpha,uh(k+1),cone,rh(k),desc_a,info)
|
||||
end do
|
||||
call psb_geaxpby(alpha,uh(0),cone,x,desc_a,info)
|
||||
call psb_spmm(cone,a,rh(j),czero,rh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(rh(j+1),desc_a,info)
|
||||
|
||||
enddo
|
||||
|
||||
do j=1, nl
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' mod g-s part: ',j, nl
|
||||
|
||||
do i=1, j-1
|
||||
taum(i,j) = psb_gedot(rh(i),rh(j),desc_a,info)
|
||||
taum(i,j) = taum(i,j)/sigma(i)
|
||||
call psb_geaxpby(-taum(i,j),rh(i),cone,rh(j),desc_a,info)
|
||||
enddo
|
||||
sigma(j) = psb_gedot(rh(j),rh(j),desc_a,info)
|
||||
gamma1(j) = psb_gedot(rh(0),rh(j),desc_a,info)
|
||||
gamma1(j) = gamma1(j)/sigma(j)
|
||||
enddo
|
||||
|
||||
gamma(nl) = gamma1(nl)
|
||||
omega = gamma(nl)
|
||||
|
||||
do j=nl-1,1,-1
|
||||
gamma(j) = gamma1(j)
|
||||
do i=j+1,nl
|
||||
gamma(j) = gamma(j) - taum(j,i) * gamma(i)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
do j=1,nl-1
|
||||
gamma2(j) = gamma(j+1)
|
||||
do i=j+1,nl-1
|
||||
gamma2(j) = gamma2(j) + taum(j,i) * gamma(i+1)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
call psb_geaxpby(gamma(1),rh(0),cone,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(nl),rh(nl),cone,rh(0),desc_a,info)
|
||||
call psb_geaxpby(-gamma(nl),uh(nl),cone,uh(0),desc_a,info)
|
||||
|
||||
do j=1, nl-1
|
||||
call psb_geaxpby(-gamma(j),uh(j),cone,uh(0),desc_a,info)
|
||||
call psb_geaxpby(gamma2(j),rh(j),cone,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(j),rh(j),cone,rh(0),desc_a,info)
|
||||
enddo
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,rh(0),desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(uh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(rh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_ccgstabl_vect
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_cfcg.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Flexible Conjugate gradients C
|
||||
! C SIAM Journal on Scientific Computing 22(4), C
|
||||
! C pp. 1444-1460, 2000 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_cfcg.f90
|
||||
!
|
||||
! Subroutine: psb_cfcg
|
||||
! This subroutine implements the Flexible Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_cfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_spk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
type(psb_c_vect_type) :: v, w, d , q, r
|
||||
complex(psb_spk_) :: alpha, beta, delta, gamma, theta
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: i, idx, nc2l, it, itx, istop_, itmax_, itrace_
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
complex(psb_spk_), allocatable, target :: aux(:)
|
||||
complex(psb_spk_) :: vres(3)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='FCG'
|
||||
logical, parameter :: debug = .false.
|
||||
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_cfcg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
|
||||
!Assemble w, v, d, q, r, u
|
||||
call psb_geasb(w, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(v, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(d, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(q, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(r, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,&
|
||||
& a,x,b,eps,desc_a,stopdat,info)
|
||||
itx = 0
|
||||
|
||||
restart: do
|
||||
if (itx>= itmax_) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on itmax '
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! r=b -Ax
|
||||
call psb_geaxpby(cone,b,czero,r, desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-cone,a,x,cone,r,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
|
||||
! Apply the preconditioner v=Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(cone,a,v,czero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
|
||||
|
||||
call psb_sum(ctxt, vres(1:2))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart AB',itx, alpha, beta
|
||||
end if
|
||||
if (beta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on beta=0 from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! d = v
|
||||
call psb_geaxpby(cone, v, czero, d, desc_a, info)
|
||||
! q = w
|
||||
call psb_geaxpby(cone, w, czero, q, desc_a, info)
|
||||
|
||||
! compute delta=beta
|
||||
! then
|
||||
! x = x + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
delta = beta
|
||||
theta = alpha/delta
|
||||
call psb_geaxpby(theta, d, cone, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, cone, r, desc_a, info)
|
||||
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart DT',itx, delta, theta
|
||||
end if
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from iteration'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! Apply the preconditioner v = Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(cone,a,v,czero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual'); goto 9999
|
||||
end if
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
vres(3) = psb_gedot(q, v, desc_a, info, global = .false.)
|
||||
|
||||
call psb_sum(ctxt, vres(1:3))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
gamma = vres(3)
|
||||
|
||||
! Compute d = v-(gamma/delta)*d
|
||||
! q = w-(gamma/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
theta= gamma/delta
|
||||
call psb_geaxpby(cone, v, -theta, d, desc_a, info)
|
||||
call psb_geaxpby(cone, w, -theta, q , desc_a, info)
|
||||
|
||||
! update delta
|
||||
delta = beta - (gamma*gamma)/delta
|
||||
|
||||
if (delta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on delta=0 from iteration'
|
||||
exit iteration
|
||||
end if
|
||||
! update u and r
|
||||
! u = u + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
theta= alpha/delta
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' iteration ',itx, alpha,beta,gamma,delta,theta
|
||||
end if
|
||||
call psb_geaxpby(theta, d, cone, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, cone, r, desc_a, info)
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx ,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
return
|
||||
9999 continue
|
||||
call psb_erractionrestore(err_act)
|
||||
if (err_act.eq.psb_act_abort_) then
|
||||
call psb_error()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_cfcg_vect
|
||||
@@ -0,0 +1,370 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_cgcr.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Aggregation-based algebraic multigrid method C
|
||||
! C SIAM Journal on Scientific Computing 34, C
|
||||
! C pp. A2288-A2316, 2012 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_cgcr.f90
|
||||
!
|
||||
! Subroutine: psb_cgcr
|
||||
! This subroutine implements the GCR method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_cgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace, irst, istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
|
||||
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_spk_), allocatable :: alpha(:), h(:,:)
|
||||
type(psb_c_vect_type), allocatable :: z(:), c(:), c_scale(:)
|
||||
type(psb_c_vect_type) :: r
|
||||
|
||||
real(psb_dpk_) :: r_norm, b_norm, a_norm, derr
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: i, j, it, itx, istop_, itmax_, itrace_, nl, m, nrst
|
||||
complex(psb_spk_) :: hjj
|
||||
complex(psb_spk_), allocatable, target :: aux(:)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='GCR'
|
||||
info = psb_success_
|
||||
name = 'psb_cgcr'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c_scale(nl+1),c(nl+1),z(nl+1), alpha(nl+1), stat=info)
|
||||
|
||||
h = czero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_geasb(r, desc_a,info, scratch=.true.,mold=x%v)
|
||||
|
||||
do i =1,nl+1
|
||||
call psb_geasb(c(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(z(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(c_scale(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
end do
|
||||
|
||||
itx = 0
|
||||
|
||||
nrst = -1
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
restart: do
|
||||
if (itx>= itmax_) exit restart
|
||||
h = czero
|
||||
|
||||
it = 0
|
||||
! compute r0 = b-ax0
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_geaxpby(cone, b, czero, r, desc_a, info)
|
||||
call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
nrst = nrst + 1
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
it = it + 1
|
||||
j = it
|
||||
!Apply preconditioner
|
||||
call prec%apply(r,z(j),desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(cone,a,z(j),czero,c(1),desc_a,info,work=aux)
|
||||
do i =1, j - 1
|
||||
|
||||
h(i,j) = psb_gedot(c_scale(i), c(i), desc_a, info)
|
||||
|
||||
call psb_geaxpby(cone, c(i), czero, c(i+1), desc_a, info)
|
||||
call psb_geaxpby(-h(i,j), c_scale(i), cone, c(i+1), desc_a, info)
|
||||
end do
|
||||
|
||||
h(j,j) = psb_norm2(c(j), desc_a, info)
|
||||
hjj = cone/h(j,j)
|
||||
call psb_geaxpby(hjj, c(j), czero, c_scale(j), desc_a, info)
|
||||
|
||||
alpha(j) = psb_gedot(c_scale(j), r, desc_a, info)
|
||||
|
||||
!Update residual
|
||||
call psb_geaxpby(cone, r, czero, r, desc_a, info)
|
||||
call psb_geaxpby(-alpha(j), c_scale(j), cone, r, desc_a, info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (j >= irst) exit iteration
|
||||
|
||||
|
||||
end do iteration
|
||||
|
||||
m = j
|
||||
|
||||
!Compute solution
|
||||
|
||||
call ctrsm('l','u','n','n',m,1,cone,h,size(h,1),alpha,size(alpha,1))
|
||||
|
||||
if (nrst == 0 ) then
|
||||
call x%set(czero)
|
||||
endif
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), cone, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
|
||||
|
||||
|
||||
end do restart
|
||||
m = j
|
||||
!Compute solution
|
||||
call ctrsm('l','u','n','n',m,1,cone,h,size(h,1),alpha,size(alpha,1))
|
||||
call x%set(czero)
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), cone, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
iter = j
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(r,desc_a,info)
|
||||
|
||||
do j = 1,m
|
||||
if (info == psb_success_) call psb_gefree(z(j),desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(c_scale(j),desc_a,info)
|
||||
enddo
|
||||
|
||||
do i =1,nl+1
|
||||
if (info == psb_success_) call psb_gefree(c(i),desc_a,info)
|
||||
end do
|
||||
|
||||
if (info == psb_success_) deallocate(aux,h,c_scale,z,c,alpha,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
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()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_cgcr_vect
|
||||
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_krylov_mod.f90
|
||||
! Interfaces for Krylov subspace iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_ckrylov
|
||||
!
|
||||
! Front-end for the Krylov subspace iterations, complexversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! methd - character The specific method; can take the values:
|
||||
! CG
|
||||
! FCG
|
||||
! CGS
|
||||
! BICG
|
||||
! BICGSTAB
|
||||
! BICGSTABL
|
||||
! RGMRES
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_ckrylov_vect(method,a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop,cond)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod,only : psb_cprec_type
|
||||
use psb_linsolve_mod, psb_protect_name => psb_ckrylov_vect
|
||||
|
||||
character(len=*) :: method
|
||||
Type(psb_cspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err,cond
|
||||
|
||||
|
||||
abstract interface
|
||||
subroutine psb_ckryl_vect(a,prec,b,x,eps,&
|
||||
& desc_a,info,itmax,iter,err,itrace,istop)
|
||||
import :: psb_ipk_, psb_spk_, psb_desc_type, &
|
||||
& psb_cspmat_type, psb_cprec_type, psb_c_vect_type
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), intent(in) :: eps
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_spk_), optional, intent(out) :: err
|
||||
end subroutine psb_ckryl_vect
|
||||
Subroutine psb_ckryl_rest_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,irst,istop)
|
||||
import :: psb_ipk_, psb_spk_, psb_desc_type, &
|
||||
& psb_cspmat_type, psb_cprec_type, psb_c_vect_type
|
||||
Type(psb_cspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
end subroutine psb_ckryl_rest_vect
|
||||
Subroutine psb_ckryl_cond_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,istop,cond)
|
||||
import :: psb_ipk_, psb_spk_, psb_desc_type, &
|
||||
& psb_cspmat_type, psb_cprec_type, psb_c_vect_type
|
||||
Type(psb_cspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err, cond
|
||||
end subroutine psb_ckryl_cond_vect
|
||||
end interface
|
||||
|
||||
procedure(psb_ckryl_vect) :: psb_cbicg_vect, psb_ccgstab_vect,&
|
||||
& psb_ccgs_vect
|
||||
procedure(psb_ckryl_rest_vect) :: psb_crgmres_vect, psb_ccgstabl_vect, psb_cgcr_vect
|
||||
procedure(psb_ckryl_cond_vect) :: psb_ccg_vect, psb_cfcg_vect
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act, itrace_
|
||||
character(len=20) :: name
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_krylov'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
! Default return for COND
|
||||
if (present(cond)) cond = szero
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
select case(psb_toupper(method))
|
||||
case('CG')
|
||||
call psb_ccg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('FCG')
|
||||
call psb_cfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('GCR')
|
||||
call psb_cgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('CGS')
|
||||
call psb_ccgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICG')
|
||||
call psb_cbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICGSTAB')
|
||||
call psb_ccgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('RGMRES','GMRES')
|
||||
call psb_crgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case('BICGSTABL')
|
||||
call psb_ccgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case default
|
||||
if (me == 0) write(psb_err_unit,*) trim(name),&
|
||||
& ': Warning: Unknown method ',method,&
|
||||
& ', defaulting to BiCGSTAB'
|
||||
call psb_ccgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
end select
|
||||
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(method))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_ckrylov_vect
|
||||
|
||||
@@ -0,0 +1,502 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Contributions to this routine:
|
||||
! Daniela di Serafino Second University of Naples
|
||||
! Pasqua D'Ambra ICAR-CNR
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_crgmres.f90
|
||||
!
|
||||
! Subroutine: psb_crgmres
|
||||
! This subroutine implements the restarted GMRES method with right
|
||||
! preconditioning.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_crgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_cspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_spk_), allocatable :: aux(:)
|
||||
complex(psb_spk_), allocatable :: c(:), s(:), h(:,:), rs(:), rst(:)
|
||||
type(psb_c_vect_type), allocatable :: v(:)
|
||||
type(psb_c_vect_type) :: w, w1, xt
|
||||
real(psb_spk_) :: tmp
|
||||
complex(psb_spk_) :: scal, gm, rti, rti1
|
||||
integer(psb_ipk_) ::litmax, naux, it, k, itrace_,&
|
||||
& n_row, n_col, nl
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., use_srot=.true.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_, err_act
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
Real(psb_spk_) :: rni, xni, bni, ani,bn2, dt, r0n2
|
||||
real(psb_dpk_) :: errnum, errden, deps, derr
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RGMRES'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_cgmres'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
litmax = itmax
|
||||
else
|
||||
litmax = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c(nl+1),s(nl+1),rs(nl+1), rst(nl+1),stat=info)
|
||||
|
||||
if (info == psb_success_) call psb_geall(v,desc_a,info,n=nl+1)
|
||||
if (info == psb_success_) call psb_geall(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(xt,desc_a,info)
|
||||
if (info == psb_success_) call psb_geasb(v,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w1,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(xt,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Size of V,W,W1 ',v(1)%get_nrows(),size(v),&
|
||||
& w%get_nrows(),w1%get_nrows()
|
||||
|
||||
|
||||
if (istop_ == 1) then
|
||||
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)
|
||||
else if (istop_ == 3) then
|
||||
call psb_geaxpby(cone,b,czero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-cone,a,x,cone,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
r0n2 = psb_genrm2(v(1),desc_a,info)
|
||||
endif
|
||||
errnum = czero
|
||||
errden = cone
|
||||
deps = eps
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if ((itrace_ > 0).and.(me == 0)) call log_header(methdname)
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
|
||||
! compute r0 = b-ax0
|
||||
! check convergence
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' restart: ',itx,it
|
||||
it = 0
|
||||
call psb_geaxpby(cone,b,czero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-cone,a,x,cone,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rs(1) = psb_genrm2(v(1),desc_a,info)
|
||||
rs(2:) = czero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
scal=cone/rs(1) ! rs(1) MIGHT BE VERY SMALL - USE DSCAL TO DEAL WITH IT?
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows(),rs(1),scal
|
||||
|
||||
!
|
||||
! check convergence
|
||||
!
|
||||
if (istop_ == 1) then
|
||||
rni = psb_geamax(v(1),desc_a,info)
|
||||
xni = psb_geamax(x,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
else if (istop_ == 2) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (errnum <= eps*errden) exit restart
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
call v(1)%scal(scal) !v(1) = v(1) * scal
|
||||
|
||||
if (itx >= litmax) exit restart
|
||||
|
||||
!
|
||||
! inner iterations
|
||||
!
|
||||
|
||||
inner: Do i=1,nl
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(v(i),w1,desc_a,info)
|
||||
call psb_spmm(cone,a,w1,czero,w,desc_a,info,work=aux)
|
||||
!
|
||||
|
||||
do k = 1, i
|
||||
h(k,i) = psb_gedot(v(k),w,desc_a,info)
|
||||
call psb_geaxpby(-h(k,i),v(k),cone,w,desc_a,info)
|
||||
end do
|
||||
h(i+1,i) = psb_genrm2(w,desc_a,info)
|
||||
scal=cone/h(i+1,i)
|
||||
call psb_geaxpby(scal,w,czero,v(i+1),desc_a,info)
|
||||
do k=2,i
|
||||
call crot(1,h(k-1,i),1,h(k,i),1,real(c(k-1),kind=psb_spk_),s(k-1))
|
||||
enddo
|
||||
|
||||
|
||||
rti = h(i,i)
|
||||
rti1 = h(i+1,i)
|
||||
call crotg(rti,rti1,tmp,s(i))
|
||||
c(i) = cmplx(tmp,szero)
|
||||
call crot(1,h(i,i),1,h(i+1,i),1,real(c(i),kind=psb_spk_),s(i))
|
||||
h(i+1,i) = czero
|
||||
call crot(1,rs(i),1,rs(i+1),1,real(c(i),kind=psb_spk_),s(i))
|
||||
|
||||
if (istop_ == 1) then
|
||||
!
|
||||
! build x and then compute the residual and its infinity norm
|
||||
!
|
||||
rst = rs
|
||||
call w1%set(czero)
|
||||
call ctrsm('l','u','n','n',i,1,cone,h,size(h,1),rst,size(rst,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rst(1:i)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rst(k),v(k),cone,xt,desc_a,info)
|
||||
end do
|
||||
call prec%apply(xt,desc_a,info)
|
||||
call psb_geaxpby(cone,x,cone,xt,desc_a,info)
|
||||
call psb_geaxpby(cone,b,czero,w1,desc_a,info)
|
||||
call psb_spmm(-cone,a,xt,cone,w1,desc_a,info,work=aux)
|
||||
rni = psb_geamax(w1,desc_a,info)
|
||||
xni = psb_geamax(xt,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
!
|
||||
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
|
||||
if (errnum <= eps*errden) then
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(cone,xt,czero,x,desc_a,info)
|
||||
! = x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call ctrsm('l','u','n','n',i,1,cone,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:i)
|
||||
call w1%set(czero)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rs(k),v(k),cone,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(cone,w,cone,x,desc_a,info)
|
||||
end if
|
||||
|
||||
exit restart
|
||||
|
||||
end if
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
end do inner
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(cone,xt,czero,x,desc_a,info)! x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call ctrsm('l','u','n','n',nl,1,cone,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:nl)
|
||||
call w1%set(czero)
|
||||
do k=1, nl
|
||||
call psb_geaxpby(rs(k),v(k),cone,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(cone,w,cone,x,desc_a,info)
|
||||
end if
|
||||
|
||||
end do restart
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,ione,errnum,errden,deps)
|
||||
|
||||
call log_end(methdname,me,itx,itrace_,errnum,errden,deps,err=derr,iter=iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
|
||||
if (info == psb_success_) call psb_gefree(v,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(xt,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,h,c,s,rs,rst, stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_crgmres_vect
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_richardson_mod.f90
|
||||
! Interfaces for Richardson iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_crichardson
|
||||
!
|
||||
! Front-end for the Richardson iterations, complexversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_cspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_cprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_crichardson_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_c_linsolve_conv_mod
|
||||
use psb_linsolve_mod, psb_protect_name => psb_crichardson_vect
|
||||
|
||||
Type(psb_cspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_cprec_type), intent(inout) :: prec
|
||||
type(psb_c_vect_type), Intent(inout) :: b
|
||||
type(psb_c_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act
|
||||
complex(psb_spk_), allocatable, target :: aux(:)
|
||||
type(psb_c_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_c_vect_type), pointer :: q, p, r, z, w
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RICHARDSON'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_crichardson'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
call psb_geaxpby(cone,b,czero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
loop: do itx=1,itmax_
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
call psb_geaxpby(cone,z,cone,x,desc_a,info)
|
||||
call psb_geaxpby(cone,b,czero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-cone,a,x,cone,r,desc_a,info,work=aux)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit loop
|
||||
end do loop
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(methdname))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_crichardson_vect
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
!
|
||||
! File: psb_dbicg.f90
|
||||
!
|
||||
! Subroutine: psb_dbicg
|
||||
! This subroutine implements the BiCG method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
|
||||
subroutine psb_dbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_dpk_), optional, intent(out) :: err
|
||||
! !$ local data
|
||||
real(psb_dpk_), allocatable, target :: aux(:)
|
||||
type(psb_d_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_d_vect_type), pointer :: ww, q, r, p,&
|
||||
& zt, pt, z, rt, qt
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, istop_, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
logical, parameter :: exchange=.true., noexchange=.false.
|
||||
integer(psb_ipk_), parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name,ch_err
|
||||
character(len=*), parameter :: methdname='BiCG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dbicg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! istop_ = 1: normwise backward error, infinity norm
|
||||
! istop_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
|
||||
allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=9_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
ch_err='psb_asb'
|
||||
err=info
|
||||
call psb_errpush(info,name,a_err=ch_err)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
pt => wwrk(6)
|
||||
z => wwrk(7)
|
||||
zt => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
itx = 0
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: do
|
||||
! !$
|
||||
! !$ r0 = b-ax0
|
||||
! !$
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),' Done spmm',info
|
||||
if (info == psb_success_) call psb_geaxpby(done,r,dzero,rt,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = dzero
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call prec%apply(rt,zt,desc_a,info,trans='c',work=aux)
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,z,desc_a,info)
|
||||
if (rho == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(done,z,dzero,p,desc_a,info)
|
||||
call psb_geaxpby(done,zt,dzero,pt,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(done,z,beta,p,desc_a,info)
|
||||
call psb_geaxpby(done,zt,beta,pt,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(done,a,p,dzero,q,desc_a,info,&
|
||||
& work=aux)
|
||||
call psb_spmm(done,a,pt,dzero,qt,desc_a,info,&
|
||||
& work=aux,trans='c')
|
||||
|
||||
sigma = psb_gedot(pt,q,desc_a,info)
|
||||
if (sigma == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,done,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,done,r,desc_a,info)
|
||||
call psb_geaxpby(-alpha,qt,done,rt,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_dbicg_vect
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_dcg.f90
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_dcg.f90
|
||||
!
|
||||
! Subroutine: psb_dcg
|
||||
! This subroutine implements the Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_dcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
real(psb_dpk_), allocatable, target :: aux(:),td(:),tu(:),eig(:),ewrk(:)
|
||||
integer(psb_mpk_), allocatable :: ibl(:), ispl(:), iwrk(:)
|
||||
type(psb_d_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_d_vect_type), pointer :: q, p, r, z, w
|
||||
real(psb_dpk_) :: alpha, beta, rho, rho_old, sigma,alpha_old,beta_old
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,err_act, ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
logical :: do_cond
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dcg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
do_cond=present(cond)
|
||||
if (do_cond) then
|
||||
istebz = 0
|
||||
allocate(td(itmax_),tu(itmax_), eig(itmax_),&
|
||||
& ibl(itmax_),ispl(itmax_),iwrk(3*itmax_),ewrk(4*itmax_),&
|
||||
& stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
end if
|
||||
itx=0
|
||||
alpha = dzero
|
||||
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-Ax0
|
||||
! =
|
||||
if (itx>= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = dzero
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
rho_old = rho
|
||||
rho = psb_gedot(r,z,desc_a,info)
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(done,z,dzero,p,desc_a,info)
|
||||
else
|
||||
if (rho_old == dzero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown rho'
|
||||
exit iteration
|
||||
endif
|
||||
beta = rho/rho_old
|
||||
call psb_geaxpby(done,z,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(done,a,p,dzero,q,desc_a,info,work=aux)
|
||||
sigma = psb_gedot(p,q,desc_a,info)
|
||||
if (sigma == dzero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown sigma'
|
||||
exit iteration
|
||||
endif
|
||||
alpha_old = alpha
|
||||
alpha = rho/sigma
|
||||
|
||||
if (do_cond) then
|
||||
istebz = istebz + 1
|
||||
if (istebz == 1) then
|
||||
td(istebz) = done/alpha
|
||||
else
|
||||
td(istebz) = done/alpha + beta/alpha_old
|
||||
tu(istebz-1) = sqrt(beta)/alpha_old
|
||||
end if
|
||||
end if
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,done,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,done,r,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
if (do_cond) then
|
||||
if (me == psb_root_) then
|
||||
#if defined(HAVE_LAPACK)
|
||||
call dstebz('A','E',istebz,dzero,dzero,0,0,-done,td,tu,&
|
||||
& ieg,nspl,eig,ibl,ispl,ewrk,iwrk,info)
|
||||
if (info < 0) then
|
||||
call psb_errpush(psb_err_from_subroutine_ai_,name,&
|
||||
& a_err='dstebz',i_err=(/info/))
|
||||
info=psb_err_from_subroutine_ai_
|
||||
goto 9999
|
||||
end if
|
||||
cond = eig(ieg)/eig(1)
|
||||
#else
|
||||
cond = dzero
|
||||
#endif
|
||||
info=psb_success_
|
||||
end if
|
||||
call psb_bcast(ctxt,cond)
|
||||
end if
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_dcg_vect
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_dcgs.f90
|
||||
!
|
||||
! Subroutine: psb_dcgs
|
||||
! Implements the Conjugate Gradient Squared method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_dcgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_dpk_), allocatable, target :: aux(:)
|
||||
type(psb_d_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_d_vect_type), pointer :: ww, q, r, p, v,&
|
||||
& s, z, f, rt, qt, uv
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col,istop_, itx, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
real(psb_dpk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CGS'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dcgs'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
Allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=11_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) Then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
v => wwrk(6)
|
||||
uv => wwrk(7)
|
||||
z => wwrk(8)
|
||||
f => wwrk(9)
|
||||
s => wwrk(10)
|
||||
ww => wwrk(11)
|
||||
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_geaxpby(done,r,dzero,rt,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
rho = dzero
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,r,desc_a,info)
|
||||
|
||||
if (rho == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(done,r,dzero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(done,r,dzero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(done,r,dzero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(beta,q,done,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(done,q,beta,p,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(done,uv,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
if (info == psb_success_) call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(done,a,f,dzero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='First loop part ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(rt,v,desc_a,info)
|
||||
if (sigma == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(done,uv,dzero,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,v,done,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(done,uv,dzero,s,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(done,q,done,s,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call prec%apply(s,z,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(alpha,z,done,x,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(done,a,z,dzero,qt,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,qt,done,r,desc_a,info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X update ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_dcgs_vect
|
||||
@@ -0,0 +1,393 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_dcgstab.f90
|
||||
!
|
||||
! Subroutine: psb_dcgstab
|
||||
! This subroutine implements the BiCG Stabilized method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_dcgstab_vect(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
class(psb_dprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = Local data
|
||||
real(psb_dpk_), allocatable, target :: aux(:),wwrk(:,:)
|
||||
type(psb_d_vect_type) :: q, r, p, v, s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it,itrace_,&
|
||||
& n_row, n_col
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., debug1 = .False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, err_act, i
|
||||
integer(psb_ipk_) :: istop_
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
real(psb_dpk_) :: alpha, beta, rho, rho_old, sigma, omega, tau
|
||||
type(psb_itconv_type) :: stopdat
|
||||
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dcgstab'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
! = if (.not.same_type_as(x,b)) then
|
||||
! = write(0,*) 'Warning: different dynamic types for X and B '
|
||||
! = end if
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
naux=6*n_col
|
||||
if (info == psb_success_) allocate(aux(naux),stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
|
||||
call psb_geasb(q,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(r,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(p,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(v,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(s,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(t,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(z,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(f,desc_a,info,mold=x%v,scratch=.true.)
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
||||
|
||||
call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
call psb_geaxpby(done,r,dzero,q,desc_a,info)
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='Init residual chk')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
rho = dzero
|
||||
|
||||
iteration: Do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(q,r,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call r%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rho: ',rho
|
||||
|
||||
if (rho == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown R',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(done,r,dzero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)*(alpha/omega)
|
||||
call psb_geaxpby(-omega,v,done,p,desc_a,info)
|
||||
call psb_geaxpby(done,r,beta,p,desc_a,info)
|
||||
End If
|
||||
|
||||
call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(done,a,f,dzero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
|
||||
sigma = psb_gedot(q,v,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call v%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Sigma: ',sigma
|
||||
|
||||
if (sigma == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
call psb_geaxpby(done,r,dzero,s,desc_a,info)
|
||||
call psb_geaxpby(-alpha,v,done,s,desc_a,info)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' alpha: ',alpha
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='psb_geaxpby')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call prec%apply(s,z,desc_a,info,work=aux)
|
||||
Call psb_spmm(done,a,z,dzero,t,desc_a,info,work=aux)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='precaply/spmm')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(t,t,desc_a,info)
|
||||
if (sigma == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S2', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
tau = psb_gedot(t,s,desc_a,info)
|
||||
omega = tau/sigma
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call t%sync()
|
||||
call s%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' sigma, tau, omega: ',sigma, tau, omega
|
||||
|
||||
if (omega == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown O',omega
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
call psb_geaxpby(alpha,f,done,x,desc_a,info)
|
||||
call psb_geaxpby(omega,z,done,x,desc_a,info)
|
||||
call psb_geaxpby(done,s,dzero,r,desc_a,info)
|
||||
call psb_geaxpby(-omega,t,done,r,desc_a,info)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X/R update ')
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
deallocate(aux,stat=info)
|
||||
|
||||
call x%sync()
|
||||
call psb_gefree(q,desc_a,info)
|
||||
call psb_gefree(r,desc_a,info)
|
||||
call psb_gefree(p,desc_a,info)
|
||||
call psb_gefree(v,desc_a,info)
|
||||
call psb_gefree(s,desc_a,info)
|
||||
call psb_gefree(t,desc_a,info)
|
||||
call psb_gefree(z,desc_a,info)
|
||||
call psb_gefree(f,desc_a,info)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_dcgstab_vect
|
||||
@@ -0,0 +1,421 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_dcgstabl.f90
|
||||
!
|
||||
! Subroutine: psb_dcgstabl
|
||||
! Implements the BICGSTAB(L) method
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration
|
||||
! is stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter L
|
||||
!
|
||||
!
|
||||
!
|
||||
Subroutine psb_dcgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
class(psb_dprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_dpk_), allocatable, target :: aux(:), gamma(:),&
|
||||
& gamma1(:), gamma2(:), taum(:,:), sigma(:)
|
||||
type(psb_d_vect_type), allocatable, target :: wwrk(:),uh(:), rh(:)
|
||||
type(psb_d_vect_type), Pointer :: ww, q, r, rt0, p, v, &
|
||||
& s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, nl, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_,j, k
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: alpha, beta, rho, rho_old, rni, xni, bni, ani,bn2,&
|
||||
& omega
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab(L)'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dcgstabl'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& 'present: irst: ',irst,nl
|
||||
else
|
||||
nl = 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),gamma(0:nl),gamma1(nl),&
|
||||
&gamma2(nl),taum(nl,nl),sigma(nl), stat=info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=10_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geall(uh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geall(rh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(uh,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(rh,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
r => wwrk(2)
|
||||
p => wwrk(3)
|
||||
v => wwrk(4)
|
||||
f => wwrk(5)
|
||||
s => wwrk(6)
|
||||
t => wwrk(7)
|
||||
z => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
rt0 => wwrk(10)
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),' restart: ',itx,it
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call prec%apply(r,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(done,r,dzero,rt0,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(done,r,dzero,rh(0),desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(dzero,r,dzero,uh(0),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = done
|
||||
alpha = dzero
|
||||
omega = done
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows()
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + nl
|
||||
itx = itx + nl
|
||||
rho = -omega*rho
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration: ',itx, rho
|
||||
|
||||
do j = 0, nl -1
|
||||
If (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'bicg part: ',j, nl
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rh(j),rt0,desc_a,info)
|
||||
if (rho == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
beta = alpha*rho/rho_old
|
||||
rho_old = rho
|
||||
do k=0, j
|
||||
! = call psb_geaxpby(done,rh(:,0:j),-beta,uh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(done,rh(k),-beta,uh(k),desc_a,info)
|
||||
end do
|
||||
call psb_spmm(done,a,uh(j),dzero,uh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(uh(j+1),desc_a,info)
|
||||
|
||||
gamma(j) = psb_gedot(uh(j+1),rt0,desc_a,info)
|
||||
|
||||
if (gamma(j) == dzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown s2',gamma(j)
|
||||
exit iteration
|
||||
endif
|
||||
alpha = rho/gamma(j)
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bicg part: alpha=r/g ',alpha,rho,gamma(j)
|
||||
|
||||
do k=0,j
|
||||
! = call psb_geaxpby(-alpha,uh(:,1:j+1),done,rh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(-alpha,uh(k+1),done,rh(k),desc_a,info)
|
||||
end do
|
||||
call psb_geaxpby(alpha,uh(0),done,x,desc_a,info)
|
||||
call psb_spmm(done,a,rh(j),dzero,rh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(rh(j+1),desc_a,info)
|
||||
|
||||
enddo
|
||||
|
||||
do j=1, nl
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' mod g-s part: ',j, nl
|
||||
|
||||
do i=1, j-1
|
||||
taum(i,j) = psb_gedot(rh(i),rh(j),desc_a,info)
|
||||
taum(i,j) = taum(i,j)/sigma(i)
|
||||
call psb_geaxpby(-taum(i,j),rh(i),done,rh(j),desc_a,info)
|
||||
enddo
|
||||
sigma(j) = psb_gedot(rh(j),rh(j),desc_a,info)
|
||||
gamma1(j) = psb_gedot(rh(0),rh(j),desc_a,info)
|
||||
gamma1(j) = gamma1(j)/sigma(j)
|
||||
enddo
|
||||
|
||||
gamma(nl) = gamma1(nl)
|
||||
omega = gamma(nl)
|
||||
|
||||
do j=nl-1,1,-1
|
||||
gamma(j) = gamma1(j)
|
||||
do i=j+1,nl
|
||||
gamma(j) = gamma(j) - taum(j,i) * gamma(i)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
do j=1,nl-1
|
||||
gamma2(j) = gamma(j+1)
|
||||
do i=j+1,nl-1
|
||||
gamma2(j) = gamma2(j) + taum(j,i) * gamma(i+1)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
call psb_geaxpby(gamma(1),rh(0),done,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(nl),rh(nl),done,rh(0),desc_a,info)
|
||||
call psb_geaxpby(-gamma(nl),uh(nl),done,uh(0),desc_a,info)
|
||||
|
||||
do j=1, nl-1
|
||||
call psb_geaxpby(-gamma(j),uh(j),done,uh(0),desc_a,info)
|
||||
call psb_geaxpby(gamma2(j),rh(j),done,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(j),rh(j),done,rh(0),desc_a,info)
|
||||
enddo
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,rh(0),desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(uh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(rh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_dcgstabl_vect
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_dfcg.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Flexible Conjugate gradients C
|
||||
! C SIAM Journal on Scientific Computing 22(4), C
|
||||
! C pp. 1444-1460, 2000 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_dfcg.f90
|
||||
!
|
||||
! Subroutine: psb_dfcg
|
||||
! This subroutine implements the Flexible Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_dfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_dpk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
type(psb_d_vect_type) :: v, w, d , q, r
|
||||
real(psb_dpk_) :: alpha, beta, delta, gamma, theta
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: i, idx, nc2l, it, itx, istop_, itmax_, itrace_
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_), allocatable, target :: aux(:)
|
||||
real(psb_dpk_) :: vres(3)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='FCG'
|
||||
logical, parameter :: debug = .false.
|
||||
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dfcg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
|
||||
!Assemble w, v, d, q, r, u
|
||||
call psb_geasb(w, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(v, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(d, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(q, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(r, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,&
|
||||
& a,x,b,eps,desc_a,stopdat,info)
|
||||
itx = 0
|
||||
|
||||
restart: do
|
||||
if (itx>= itmax_) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on itmax '
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! r=b -Ax
|
||||
call psb_geaxpby(done,b,dzero,r, desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-done,a,x,done,r,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
|
||||
! Apply the preconditioner v=Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(done,a,v,dzero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
|
||||
|
||||
call psb_sum(ctxt, vres(1:2))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart AB',itx, alpha, beta
|
||||
end if
|
||||
if (beta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on beta=0 from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! d = v
|
||||
call psb_geaxpby(done, v, dzero, d, desc_a, info)
|
||||
! q = w
|
||||
call psb_geaxpby(done, w, dzero, q, desc_a, info)
|
||||
|
||||
! compute delta=beta
|
||||
! then
|
||||
! x = x + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
delta = beta
|
||||
theta = alpha/delta
|
||||
call psb_geaxpby(theta, d, done, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, done, r, desc_a, info)
|
||||
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart DT',itx, delta, theta
|
||||
end if
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from iteration'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! Apply the preconditioner v = Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(done,a,v,dzero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual'); goto 9999
|
||||
end if
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
vres(3) = psb_gedot(q, v, desc_a, info, global = .false.)
|
||||
|
||||
call psb_sum(ctxt, vres(1:3))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
gamma = vres(3)
|
||||
|
||||
! Compute d = v-(gamma/delta)*d
|
||||
! q = w-(gamma/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
theta= gamma/delta
|
||||
call psb_geaxpby(done, v, -theta, d, desc_a, info)
|
||||
call psb_geaxpby(done, w, -theta, q , desc_a, info)
|
||||
|
||||
! update delta
|
||||
delta = beta - (gamma*gamma)/delta
|
||||
|
||||
if (delta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on delta=0 from iteration'
|
||||
exit iteration
|
||||
end if
|
||||
! update u and r
|
||||
! u = u + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
theta= alpha/delta
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' iteration ',itx, alpha,beta,gamma,delta,theta
|
||||
end if
|
||||
call psb_geaxpby(theta, d, done, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, done, r, desc_a, info)
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx ,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
return
|
||||
9999 continue
|
||||
call psb_erractionrestore(err_act)
|
||||
if (err_act.eq.psb_act_abort_) then
|
||||
call psb_error()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_dfcg_vect
|
||||
@@ -0,0 +1,370 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_dgcr.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Aggregation-based algebraic multigrid method C
|
||||
! C SIAM Journal on Scientific Computing 34, C
|
||||
! C pp. A2288-A2316, 2012 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_dgcr.f90
|
||||
!
|
||||
! Subroutine: psb_dgcr
|
||||
! This subroutine implements the GCR method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_dgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace, irst, istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
|
||||
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_dpk_), allocatable :: alpha(:), h(:,:)
|
||||
type(psb_d_vect_type), allocatable :: z(:), c(:), c_scale(:)
|
||||
type(psb_d_vect_type) :: r
|
||||
|
||||
real(psb_dpk_) :: r_norm, b_norm, a_norm, derr
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: i, j, it, itx, istop_, itmax_, itrace_, nl, m, nrst
|
||||
real(psb_dpk_) :: hjj
|
||||
real(psb_dpk_), allocatable, target :: aux(:)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='GCR'
|
||||
info = psb_success_
|
||||
name = 'psb_dgcr'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c_scale(nl+1),c(nl+1),z(nl+1), alpha(nl+1), stat=info)
|
||||
|
||||
h = dzero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_geasb(r, desc_a,info, scratch=.true.,mold=x%v)
|
||||
|
||||
do i =1,nl+1
|
||||
call psb_geasb(c(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(z(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(c_scale(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
end do
|
||||
|
||||
itx = 0
|
||||
|
||||
nrst = -1
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
restart: do
|
||||
if (itx>= itmax_) exit restart
|
||||
h = dzero
|
||||
|
||||
it = 0
|
||||
! compute r0 = b-ax0
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_geaxpby(done, b, dzero, r, desc_a, info)
|
||||
call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
nrst = nrst + 1
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
it = it + 1
|
||||
j = it
|
||||
!Apply preconditioner
|
||||
call prec%apply(r,z(j),desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(done,a,z(j),dzero,c(1),desc_a,info,work=aux)
|
||||
do i =1, j - 1
|
||||
|
||||
h(i,j) = psb_gedot(c_scale(i), c(i), desc_a, info)
|
||||
|
||||
call psb_geaxpby(done, c(i), dzero, c(i+1), desc_a, info)
|
||||
call psb_geaxpby(-h(i,j), c_scale(i), done, c(i+1), desc_a, info)
|
||||
end do
|
||||
|
||||
h(j,j) = psb_norm2(c(j), desc_a, info)
|
||||
hjj = done/h(j,j)
|
||||
call psb_geaxpby(hjj, c(j), dzero, c_scale(j), desc_a, info)
|
||||
|
||||
alpha(j) = psb_gedot(c_scale(j), r, desc_a, info)
|
||||
|
||||
!Update residual
|
||||
call psb_geaxpby(done, r, dzero, r, desc_a, info)
|
||||
call psb_geaxpby(-alpha(j), c_scale(j), done, r, desc_a, info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (j >= irst) exit iteration
|
||||
|
||||
|
||||
end do iteration
|
||||
|
||||
m = j
|
||||
|
||||
!Compute solution
|
||||
|
||||
call dtrsm('l','u','n','n',m,1,done,h,size(h,1),alpha,size(alpha,1))
|
||||
|
||||
if (nrst == 0 ) then
|
||||
call x%set(dzero)
|
||||
endif
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), done, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
|
||||
|
||||
|
||||
end do restart
|
||||
m = j
|
||||
!Compute solution
|
||||
call dtrsm('l','u','n','n',m,1,done,h,size(h,1),alpha,size(alpha,1))
|
||||
call x%set(dzero)
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), done, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
iter = j
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(r,desc_a,info)
|
||||
|
||||
do j = 1,m
|
||||
if (info == psb_success_) call psb_gefree(z(j),desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(c_scale(j),desc_a,info)
|
||||
enddo
|
||||
|
||||
do i =1,nl+1
|
||||
if (info == psb_success_) call psb_gefree(c(i),desc_a,info)
|
||||
end do
|
||||
|
||||
if (info == psb_success_) deallocate(aux,h,c_scale,z,c,alpha,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
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()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_dgcr_vect
|
||||
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_krylov_mod.f90
|
||||
! Interfaces for Krylov subspace iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_dkrylov
|
||||
!
|
||||
! Front-end for the Krylov subspace iterations, realversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! methd - character The specific method; can take the values:
|
||||
! CG
|
||||
! FCG
|
||||
! CGS
|
||||
! BICG
|
||||
! BICGSTAB
|
||||
! BICGSTABL
|
||||
! RGMRES
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_dkrylov_vect(method,a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop,cond)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod,only : psb_dprec_type
|
||||
use psb_linsolve_mod, psb_protect_name => psb_dkrylov_vect
|
||||
|
||||
character(len=*) :: method
|
||||
Type(psb_dspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err,cond
|
||||
|
||||
|
||||
abstract interface
|
||||
subroutine psb_dkryl_vect(a,prec,b,x,eps,&
|
||||
& desc_a,info,itmax,iter,err,itrace,istop)
|
||||
import :: psb_ipk_, psb_dpk_, psb_desc_type, &
|
||||
& psb_dspmat_type, psb_dprec_type, psb_d_vect_type
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), intent(in) :: eps
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_dpk_), optional, intent(out) :: err
|
||||
end subroutine psb_dkryl_vect
|
||||
Subroutine psb_dkryl_rest_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,irst,istop)
|
||||
import :: psb_ipk_, psb_dpk_, psb_desc_type, &
|
||||
& psb_dspmat_type, psb_dprec_type, psb_d_vect_type
|
||||
Type(psb_dspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
end subroutine psb_dkryl_rest_vect
|
||||
Subroutine psb_dkryl_cond_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,istop,cond)
|
||||
import :: psb_ipk_, psb_dpk_, psb_desc_type, &
|
||||
& psb_dspmat_type, psb_dprec_type, psb_d_vect_type
|
||||
Type(psb_dspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err, cond
|
||||
end subroutine psb_dkryl_cond_vect
|
||||
end interface
|
||||
|
||||
procedure(psb_dkryl_vect) :: psb_dbicg_vect, psb_dcgstab_vect,&
|
||||
& psb_dcgs_vect
|
||||
procedure(psb_dkryl_rest_vect) :: psb_drgmres_vect, psb_dcgstabl_vect, psb_dgcr_vect
|
||||
procedure(psb_dkryl_cond_vect) :: psb_dcg_vect, psb_dfcg_vect
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act, itrace_
|
||||
character(len=20) :: name
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_krylov'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
! Default return for COND
|
||||
if (present(cond)) cond = dzero
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
select case(psb_toupper(method))
|
||||
case('CG')
|
||||
call psb_dcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('FCG')
|
||||
call psb_dfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('GCR')
|
||||
call psb_dgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('CGS')
|
||||
call psb_dcgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICG')
|
||||
call psb_dbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICGSTAB')
|
||||
call psb_dcgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('RGMRES','GMRES')
|
||||
call psb_drgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case('BICGSTABL')
|
||||
call psb_dcgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case default
|
||||
if (me == 0) write(psb_err_unit,*) trim(name),&
|
||||
& ': Warning: Unknown method ',method,&
|
||||
& ', defaulting to BiCGSTAB'
|
||||
call psb_dcgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
end select
|
||||
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(method))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_dkrylov_vect
|
||||
|
||||
@@ -0,0 +1,502 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Contributions to this routine:
|
||||
! Daniela di Serafino Second University of Naples
|
||||
! Pasqua D'Ambra ICAR-CNR
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_drgmres.f90
|
||||
!
|
||||
! Subroutine: psb_drgmres
|
||||
! This subroutine implements the restarted GMRES method with right
|
||||
! preconditioning.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_drgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_dspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_dpk_), allocatable :: aux(:)
|
||||
real(psb_dpk_), allocatable :: c(:), s(:), h(:,:), rs(:), rst(:)
|
||||
type(psb_d_vect_type), allocatable :: v(:)
|
||||
type(psb_d_vect_type) :: w, w1, xt
|
||||
real(psb_dpk_) :: tmp
|
||||
real(psb_dpk_) :: scal, gm, rti, rti1
|
||||
integer(psb_ipk_) ::litmax, naux, it, k, itrace_,&
|
||||
& n_row, n_col, nl
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., use_srot=.true.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_, err_act
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
Real(psb_dpk_) :: rni, xni, bni, ani,bn2, dt, r0n2
|
||||
real(psb_dpk_) :: errnum, errden, deps, derr
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RGMRES'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dgmres'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
litmax = itmax
|
||||
else
|
||||
litmax = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c(nl+1),s(nl+1),rs(nl+1), rst(nl+1),stat=info)
|
||||
|
||||
if (info == psb_success_) call psb_geall(v,desc_a,info,n=nl+1)
|
||||
if (info == psb_success_) call psb_geall(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(xt,desc_a,info)
|
||||
if (info == psb_success_) call psb_geasb(v,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w1,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(xt,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Size of V,W,W1 ',v(1)%get_nrows(),size(v),&
|
||||
& w%get_nrows(),w1%get_nrows()
|
||||
|
||||
|
||||
if (istop_ == 1) then
|
||||
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)
|
||||
else if (istop_ == 3) then
|
||||
call psb_geaxpby(done,b,dzero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-done,a,x,done,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
r0n2 = psb_genrm2(v(1),desc_a,info)
|
||||
endif
|
||||
errnum = dzero
|
||||
errden = done
|
||||
deps = eps
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if ((itrace_ > 0).and.(me == 0)) call log_header(methdname)
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
|
||||
! compute r0 = b-ax0
|
||||
! check convergence
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' restart: ',itx,it
|
||||
it = 0
|
||||
call psb_geaxpby(done,b,dzero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-done,a,x,done,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rs(1) = psb_genrm2(v(1),desc_a,info)
|
||||
rs(2:) = dzero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
scal=done/rs(1) ! rs(1) MIGHT BE VERY SMALL - USE DSCAL TO DEAL WITH IT?
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows(),rs(1),scal
|
||||
|
||||
!
|
||||
! check convergence
|
||||
!
|
||||
if (istop_ == 1) then
|
||||
rni = psb_geamax(v(1),desc_a,info)
|
||||
xni = psb_geamax(x,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
else if (istop_ == 2) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (errnum <= eps*errden) exit restart
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
call v(1)%scal(scal) !v(1) = v(1) * scal
|
||||
|
||||
if (itx >= litmax) exit restart
|
||||
|
||||
!
|
||||
! inner iterations
|
||||
!
|
||||
|
||||
inner: Do i=1,nl
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(v(i),w1,desc_a,info)
|
||||
call psb_spmm(done,a,w1,dzero,w,desc_a,info,work=aux)
|
||||
!
|
||||
|
||||
do k = 1, i
|
||||
h(k,i) = psb_gedot(v(k),w,desc_a,info)
|
||||
call psb_geaxpby(-h(k,i),v(k),done,w,desc_a,info)
|
||||
end do
|
||||
h(i+1,i) = psb_genrm2(w,desc_a,info)
|
||||
scal=done/h(i+1,i)
|
||||
call psb_geaxpby(scal,w,dzero,v(i+1),desc_a,info)
|
||||
do k=2,i
|
||||
call drot(1,h(k-1,i),1,h(k,i),1,real(c(k-1),kind=psb_dpk_),s(k-1))
|
||||
enddo
|
||||
|
||||
|
||||
rti = h(i,i)
|
||||
rti1 = h(i+1,i)
|
||||
call drotg(rti,rti1,tmp,s(i))
|
||||
c(i) = cmplx(tmp,dzero)
|
||||
call drot(1,h(i,i),1,h(i+1,i),1,real(c(i),kind=psb_dpk_),s(i))
|
||||
h(i+1,i) = dzero
|
||||
call drot(1,rs(i),1,rs(i+1),1,real(c(i),kind=psb_dpk_),s(i))
|
||||
|
||||
if (istop_ == 1) then
|
||||
!
|
||||
! build x and then compute the residual and its infinity norm
|
||||
!
|
||||
rst = rs
|
||||
call w1%set(dzero)
|
||||
call dtrsm('l','u','n','n',i,1,done,h,size(h,1),rst,size(rst,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rst(1:i)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rst(k),v(k),done,xt,desc_a,info)
|
||||
end do
|
||||
call prec%apply(xt,desc_a,info)
|
||||
call psb_geaxpby(done,x,done,xt,desc_a,info)
|
||||
call psb_geaxpby(done,b,dzero,w1,desc_a,info)
|
||||
call psb_spmm(-done,a,xt,done,w1,desc_a,info,work=aux)
|
||||
rni = psb_geamax(w1,desc_a,info)
|
||||
xni = psb_geamax(xt,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
!
|
||||
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
|
||||
if (errnum <= eps*errden) then
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(done,xt,dzero,x,desc_a,info)
|
||||
! = x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call dtrsm('l','u','n','n',i,1,done,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:i)
|
||||
call w1%set(dzero)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rs(k),v(k),done,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(done,w,done,x,desc_a,info)
|
||||
end if
|
||||
|
||||
exit restart
|
||||
|
||||
end if
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
end do inner
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(done,xt,dzero,x,desc_a,info)! x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call dtrsm('l','u','n','n',nl,1,done,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:nl)
|
||||
call w1%set(dzero)
|
||||
do k=1, nl
|
||||
call psb_geaxpby(rs(k),v(k),done,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(done,w,done,x,desc_a,info)
|
||||
end if
|
||||
|
||||
end do restart
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,ione,errnum,errden,deps)
|
||||
|
||||
call log_end(methdname,me,itx,itrace_,errnum,errden,deps,err=derr,iter=iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
|
||||
if (info == psb_success_) call psb_gefree(v,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(xt,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,h,c,s,rs,rst, stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_drgmres_vect
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_richardson_mod.f90
|
||||
! Interfaces for Richardson iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_drichardson
|
||||
!
|
||||
! Front-end for the Richardson iterations, realversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_dspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_dprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_drichardson_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_linsolve_conv_mod
|
||||
use psb_linsolve_mod, psb_protect_name => psb_drichardson_vect
|
||||
|
||||
Type(psb_dspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_dprec_type), intent(inout) :: prec
|
||||
type(psb_d_vect_type), Intent(inout) :: b
|
||||
type(psb_d_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act
|
||||
real(psb_dpk_), allocatable, target :: aux(:)
|
||||
type(psb_d_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_d_vect_type), pointer :: q, p, r, z, w
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RICHARDSON'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_drichardson'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
loop: do itx=1,itmax_
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
call psb_geaxpby(done,z,done,x,desc_a,info)
|
||||
call psb_geaxpby(done,b,dzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-done,a,x,done,r,desc_a,info,work=aux)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit loop
|
||||
end do loop
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(methdname))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_drichardson_vect
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
!
|
||||
! File: psb_sbicg.f90
|
||||
!
|
||||
! Subroutine: psb_sbicg
|
||||
! This subroutine implements the BiCG method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
|
||||
subroutine psb_sbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_spk_), optional, intent(out) :: err
|
||||
! !$ local data
|
||||
real(psb_spk_), allocatable, target :: aux(:)
|
||||
type(psb_s_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_s_vect_type), pointer :: ww, q, r, p,&
|
||||
& zt, pt, z, rt, qt
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, istop_, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
logical, parameter :: exchange=.true., noexchange=.false.
|
||||
integer(psb_ipk_), parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_spk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name,ch_err
|
||||
character(len=*), parameter :: methdname='BiCG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_sbicg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! istop_ = 1: normwise backward error, infinity norm
|
||||
! istop_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
|
||||
allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=9_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
ch_err='psb_asb'
|
||||
err=info
|
||||
call psb_errpush(info,name,a_err=ch_err)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
pt => wwrk(6)
|
||||
z => wwrk(7)
|
||||
zt => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
itx = 0
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: do
|
||||
! !$
|
||||
! !$ r0 = b-ax0
|
||||
! !$
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(sone,b,szero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),' Done spmm',info
|
||||
if (info == psb_success_) call psb_geaxpby(sone,r,szero,rt,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = szero
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call prec%apply(rt,zt,desc_a,info,trans='c',work=aux)
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,z,desc_a,info)
|
||||
if (rho == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(sone,z,szero,p,desc_a,info)
|
||||
call psb_geaxpby(sone,zt,szero,pt,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(sone,z,beta,p,desc_a,info)
|
||||
call psb_geaxpby(sone,zt,beta,pt,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(sone,a,p,szero,q,desc_a,info,&
|
||||
& work=aux)
|
||||
call psb_spmm(sone,a,pt,szero,qt,desc_a,info,&
|
||||
& work=aux,trans='c')
|
||||
|
||||
sigma = psb_gedot(pt,q,desc_a,info)
|
||||
if (sigma == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,sone,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,sone,r,desc_a,info)
|
||||
call psb_geaxpby(-alpha,qt,sone,rt,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_sbicg_vect
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_scg.f90
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_scg.f90
|
||||
!
|
||||
! Subroutine: psb_scg
|
||||
! This subroutine implements the Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_scg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
real(psb_spk_), allocatable, target :: aux(:),td(:),tu(:),eig(:),ewrk(:)
|
||||
integer(psb_mpk_), allocatable :: ibl(:), ispl(:), iwrk(:)
|
||||
type(psb_s_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_s_vect_type), pointer :: q, p, r, z, w
|
||||
real(psb_spk_) :: alpha, beta, rho, rho_old, sigma,alpha_old,beta_old
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,err_act, ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
logical :: do_cond
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_scg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
do_cond=present(cond)
|
||||
if (do_cond) then
|
||||
istebz = 0
|
||||
allocate(td(itmax_),tu(itmax_), eig(itmax_),&
|
||||
& ibl(itmax_),ispl(itmax_),iwrk(3*itmax_),ewrk(4*itmax_),&
|
||||
& stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
end if
|
||||
itx=0
|
||||
alpha = szero
|
||||
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-Ax0
|
||||
! =
|
||||
if (itx>= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(sone,b,szero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = szero
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
rho_old = rho
|
||||
rho = psb_gedot(r,z,desc_a,info)
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(sone,z,szero,p,desc_a,info)
|
||||
else
|
||||
if (rho_old == szero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown rho'
|
||||
exit iteration
|
||||
endif
|
||||
beta = rho/rho_old
|
||||
call psb_geaxpby(sone,z,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(sone,a,p,szero,q,desc_a,info,work=aux)
|
||||
sigma = psb_gedot(p,q,desc_a,info)
|
||||
if (sigma == szero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown sigma'
|
||||
exit iteration
|
||||
endif
|
||||
alpha_old = alpha
|
||||
alpha = rho/sigma
|
||||
|
||||
if (do_cond) then
|
||||
istebz = istebz + 1
|
||||
if (istebz == 1) then
|
||||
td(istebz) = sone/alpha
|
||||
else
|
||||
td(istebz) = sone/alpha + beta/alpha_old
|
||||
tu(istebz-1) = sqrt(beta)/alpha_old
|
||||
end if
|
||||
end if
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,sone,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,sone,r,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
if (do_cond) then
|
||||
if (me == psb_root_) then
|
||||
#if defined(HAVE_LAPACK)
|
||||
call sstebz('A','E',istebz,szero,szero,0,0,-sone,td,tu,&
|
||||
& ieg,nspl,eig,ibl,ispl,ewrk,iwrk,info)
|
||||
if (info < 0) then
|
||||
call psb_errpush(psb_err_from_subroutine_ai_,name,&
|
||||
& a_err='sstebz',i_err=(/info/))
|
||||
info=psb_err_from_subroutine_ai_
|
||||
goto 9999
|
||||
end if
|
||||
cond = eig(ieg)/eig(1)
|
||||
#else
|
||||
cond = szero
|
||||
#endif
|
||||
info=psb_success_
|
||||
end if
|
||||
call psb_bcast(ctxt,cond)
|
||||
end if
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_scg_vect
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_scgs.f90
|
||||
!
|
||||
! Subroutine: psb_scgs
|
||||
! Implements the Conjugate Gradient Squared method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_scgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_spk_), allocatable, target :: aux(:)
|
||||
type(psb_s_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_s_vect_type), pointer :: ww, q, r, p, v,&
|
||||
& s, z, f, rt, qt, uv
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col,istop_, itx, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
real(psb_spk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CGS'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_scgs'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
Allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=11_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) Then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
v => wwrk(6)
|
||||
uv => wwrk(7)
|
||||
z => wwrk(8)
|
||||
f => wwrk(9)
|
||||
s => wwrk(10)
|
||||
ww => wwrk(11)
|
||||
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(sone,b,szero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_geaxpby(sone,r,szero,rt,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
rho = szero
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,r,desc_a,info)
|
||||
|
||||
if (rho == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(sone,r,szero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(sone,r,szero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(sone,r,szero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(beta,q,sone,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(sone,q,beta,p,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(sone,uv,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
if (info == psb_success_) call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(sone,a,f,szero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='First loop part ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(rt,v,desc_a,info)
|
||||
if (sigma == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(sone,uv,szero,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,v,sone,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(sone,uv,szero,s,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(sone,q,sone,s,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call prec%apply(s,z,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(alpha,z,sone,x,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(sone,a,z,szero,qt,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,qt,sone,r,desc_a,info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X update ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_scgs_vect
|
||||
@@ -0,0 +1,393 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_scgstab.f90
|
||||
!
|
||||
! Subroutine: psb_scgstab
|
||||
! This subroutine implements the BiCG Stabilized method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_scgstab_vect(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
class(psb_sprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = Local data
|
||||
real(psb_spk_), allocatable, target :: aux(:),wwrk(:,:)
|
||||
type(psb_s_vect_type) :: q, r, p, v, s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it,itrace_,&
|
||||
& n_row, n_col
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., debug1 = .False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, err_act, i
|
||||
integer(psb_ipk_) :: istop_
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
real(psb_spk_) :: alpha, beta, rho, rho_old, sigma, omega, tau
|
||||
type(psb_itconv_type) :: stopdat
|
||||
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_scgstab'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
! = if (.not.same_type_as(x,b)) then
|
||||
! = write(0,*) 'Warning: different dynamic types for X and B '
|
||||
! = end if
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
naux=6*n_col
|
||||
if (info == psb_success_) allocate(aux(naux),stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
|
||||
call psb_geasb(q,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(r,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(p,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(v,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(s,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(t,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(z,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(f,desc_a,info,mold=x%v,scratch=.true.)
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(sone,b,szero,r,desc_a,info)
|
||||
|
||||
call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
call psb_geaxpby(sone,r,szero,q,desc_a,info)
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='Init residual chk')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
rho = szero
|
||||
|
||||
iteration: Do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(q,r,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call r%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rho: ',rho
|
||||
|
||||
if (rho == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown R',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(sone,r,szero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)*(alpha/omega)
|
||||
call psb_geaxpby(-omega,v,sone,p,desc_a,info)
|
||||
call psb_geaxpby(sone,r,beta,p,desc_a,info)
|
||||
End If
|
||||
|
||||
call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(sone,a,f,szero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
|
||||
sigma = psb_gedot(q,v,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call v%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Sigma: ',sigma
|
||||
|
||||
if (sigma == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
call psb_geaxpby(sone,r,szero,s,desc_a,info)
|
||||
call psb_geaxpby(-alpha,v,sone,s,desc_a,info)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' alpha: ',alpha
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='psb_geaxpby')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call prec%apply(s,z,desc_a,info,work=aux)
|
||||
Call psb_spmm(sone,a,z,szero,t,desc_a,info,work=aux)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='precaply/spmm')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(t,t,desc_a,info)
|
||||
if (sigma == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S2', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
tau = psb_gedot(t,s,desc_a,info)
|
||||
omega = tau/sigma
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call t%sync()
|
||||
call s%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' sigma, tau, omega: ',sigma, tau, omega
|
||||
|
||||
if (omega == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown O',omega
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
call psb_geaxpby(alpha,f,sone,x,desc_a,info)
|
||||
call psb_geaxpby(omega,z,sone,x,desc_a,info)
|
||||
call psb_geaxpby(sone,s,szero,r,desc_a,info)
|
||||
call psb_geaxpby(-omega,t,sone,r,desc_a,info)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X/R update ')
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
deallocate(aux,stat=info)
|
||||
|
||||
call x%sync()
|
||||
call psb_gefree(q,desc_a,info)
|
||||
call psb_gefree(r,desc_a,info)
|
||||
call psb_gefree(p,desc_a,info)
|
||||
call psb_gefree(v,desc_a,info)
|
||||
call psb_gefree(s,desc_a,info)
|
||||
call psb_gefree(t,desc_a,info)
|
||||
call psb_gefree(z,desc_a,info)
|
||||
call psb_gefree(f,desc_a,info)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_scgstab_vect
|
||||
@@ -0,0 +1,421 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_scgstabl.f90
|
||||
!
|
||||
! Subroutine: psb_scgstabl
|
||||
! Implements the BICGSTAB(L) method
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration
|
||||
! is stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter L
|
||||
!
|
||||
!
|
||||
!
|
||||
Subroutine psb_scgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
class(psb_sprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_spk_), allocatable, target :: aux(:), gamma(:),&
|
||||
& gamma1(:), gamma2(:), taum(:,:), sigma(:)
|
||||
type(psb_s_vect_type), allocatable, target :: wwrk(:),uh(:), rh(:)
|
||||
type(psb_s_vect_type), Pointer :: ww, q, r, rt0, p, v, &
|
||||
& s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, nl, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_,j, k
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_spk_) :: alpha, beta, rho, rho_old, rni, xni, bni, ani,bn2,&
|
||||
& omega
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab(L)'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_scgstabl'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& 'present: irst: ',irst,nl
|
||||
else
|
||||
nl = 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),gamma(0:nl),gamma1(nl),&
|
||||
&gamma2(nl),taum(nl,nl),sigma(nl), stat=info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=10_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geall(uh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geall(rh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(uh,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(rh,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
r => wwrk(2)
|
||||
p => wwrk(3)
|
||||
v => wwrk(4)
|
||||
f => wwrk(5)
|
||||
s => wwrk(6)
|
||||
t => wwrk(7)
|
||||
z => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
rt0 => wwrk(10)
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),' restart: ',itx,it
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(sone,b,szero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call prec%apply(r,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(sone,r,szero,rt0,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(sone,r,szero,rh(0),desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(szero,r,szero,uh(0),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = sone
|
||||
alpha = szero
|
||||
omega = sone
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows()
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + nl
|
||||
itx = itx + nl
|
||||
rho = -omega*rho
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration: ',itx, rho
|
||||
|
||||
do j = 0, nl -1
|
||||
If (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'bicg part: ',j, nl
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rh(j),rt0,desc_a,info)
|
||||
if (rho == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
beta = alpha*rho/rho_old
|
||||
rho_old = rho
|
||||
do k=0, j
|
||||
! = call psb_geaxpby(sone,rh(:,0:j),-beta,uh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(sone,rh(k),-beta,uh(k),desc_a,info)
|
||||
end do
|
||||
call psb_spmm(sone,a,uh(j),szero,uh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(uh(j+1),desc_a,info)
|
||||
|
||||
gamma(j) = psb_gedot(uh(j+1),rt0,desc_a,info)
|
||||
|
||||
if (gamma(j) == szero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown s2',gamma(j)
|
||||
exit iteration
|
||||
endif
|
||||
alpha = rho/gamma(j)
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bicg part: alpha=r/g ',alpha,rho,gamma(j)
|
||||
|
||||
do k=0,j
|
||||
! = call psb_geaxpby(-alpha,uh(:,1:j+1),sone,rh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(-alpha,uh(k+1),sone,rh(k),desc_a,info)
|
||||
end do
|
||||
call psb_geaxpby(alpha,uh(0),sone,x,desc_a,info)
|
||||
call psb_spmm(sone,a,rh(j),szero,rh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(rh(j+1),desc_a,info)
|
||||
|
||||
enddo
|
||||
|
||||
do j=1, nl
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' mod g-s part: ',j, nl
|
||||
|
||||
do i=1, j-1
|
||||
taum(i,j) = psb_gedot(rh(i),rh(j),desc_a,info)
|
||||
taum(i,j) = taum(i,j)/sigma(i)
|
||||
call psb_geaxpby(-taum(i,j),rh(i),sone,rh(j),desc_a,info)
|
||||
enddo
|
||||
sigma(j) = psb_gedot(rh(j),rh(j),desc_a,info)
|
||||
gamma1(j) = psb_gedot(rh(0),rh(j),desc_a,info)
|
||||
gamma1(j) = gamma1(j)/sigma(j)
|
||||
enddo
|
||||
|
||||
gamma(nl) = gamma1(nl)
|
||||
omega = gamma(nl)
|
||||
|
||||
do j=nl-1,1,-1
|
||||
gamma(j) = gamma1(j)
|
||||
do i=j+1,nl
|
||||
gamma(j) = gamma(j) - taum(j,i) * gamma(i)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
do j=1,nl-1
|
||||
gamma2(j) = gamma(j+1)
|
||||
do i=j+1,nl-1
|
||||
gamma2(j) = gamma2(j) + taum(j,i) * gamma(i+1)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
call psb_geaxpby(gamma(1),rh(0),sone,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(nl),rh(nl),sone,rh(0),desc_a,info)
|
||||
call psb_geaxpby(-gamma(nl),uh(nl),sone,uh(0),desc_a,info)
|
||||
|
||||
do j=1, nl-1
|
||||
call psb_geaxpby(-gamma(j),uh(j),sone,uh(0),desc_a,info)
|
||||
call psb_geaxpby(gamma2(j),rh(j),sone,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(j),rh(j),sone,rh(0),desc_a,info)
|
||||
enddo
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,rh(0),desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(uh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(rh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_scgstabl_vect
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_sfcg.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Flexible Conjugate gradients C
|
||||
! C SIAM Journal on Scientific Computing 22(4), C
|
||||
! C pp. 1444-1460, 2000 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_sfcg.f90
|
||||
!
|
||||
! Subroutine: psb_sfcg
|
||||
! This subroutine implements the Flexible Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_sfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_spk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
type(psb_s_vect_type) :: v, w, d , q, r
|
||||
real(psb_spk_) :: alpha, beta, delta, gamma, theta
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: i, idx, nc2l, it, itx, istop_, itmax_, itrace_
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_spk_), allocatable, target :: aux(:)
|
||||
real(psb_spk_) :: vres(3)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='FCG'
|
||||
logical, parameter :: debug = .false.
|
||||
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_sfcg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
|
||||
!Assemble w, v, d, q, r, u
|
||||
call psb_geasb(w, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(v, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(d, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(q, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(r, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,&
|
||||
& a,x,b,eps,desc_a,stopdat,info)
|
||||
itx = 0
|
||||
|
||||
restart: do
|
||||
if (itx>= itmax_) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on itmax '
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! r=b -Ax
|
||||
call psb_geaxpby(sone,b,szero,r, desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-sone,a,x,sone,r,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
|
||||
! Apply the preconditioner v=Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(sone,a,v,szero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
|
||||
|
||||
call psb_sum(ctxt, vres(1:2))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart AB',itx, alpha, beta
|
||||
end if
|
||||
if (beta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on beta=0 from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! d = v
|
||||
call psb_geaxpby(sone, v, szero, d, desc_a, info)
|
||||
! q = w
|
||||
call psb_geaxpby(sone, w, szero, q, desc_a, info)
|
||||
|
||||
! compute delta=beta
|
||||
! then
|
||||
! x = x + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
delta = beta
|
||||
theta = alpha/delta
|
||||
call psb_geaxpby(theta, d, sone, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, sone, r, desc_a, info)
|
||||
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart DT',itx, delta, theta
|
||||
end if
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from iteration'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! Apply the preconditioner v = Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(sone,a,v,szero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual'); goto 9999
|
||||
end if
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
vres(3) = psb_gedot(q, v, desc_a, info, global = .false.)
|
||||
|
||||
call psb_sum(ctxt, vres(1:3))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
gamma = vres(3)
|
||||
|
||||
! Compute d = v-(gamma/delta)*d
|
||||
! q = w-(gamma/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
theta= gamma/delta
|
||||
call psb_geaxpby(sone, v, -theta, d, desc_a, info)
|
||||
call psb_geaxpby(sone, w, -theta, q , desc_a, info)
|
||||
|
||||
! update delta
|
||||
delta = beta - (gamma*gamma)/delta
|
||||
|
||||
if (delta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on delta=0 from iteration'
|
||||
exit iteration
|
||||
end if
|
||||
! update u and r
|
||||
! u = u + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
theta= alpha/delta
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' iteration ',itx, alpha,beta,gamma,delta,theta
|
||||
end if
|
||||
call psb_geaxpby(theta, d, sone, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, sone, r, desc_a, info)
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx ,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
return
|
||||
9999 continue
|
||||
call psb_erractionrestore(err_act)
|
||||
if (err_act.eq.psb_act_abort_) then
|
||||
call psb_error()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_sfcg_vect
|
||||
@@ -0,0 +1,370 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_sgcr.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Aggregation-based algebraic multigrid method C
|
||||
! C SIAM Journal on Scientific Computing 34, C
|
||||
! C pp. A2288-A2316, 2012 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_sgcr.f90
|
||||
!
|
||||
! Subroutine: psb_sgcr
|
||||
! This subroutine implements the GCR method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_sgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace, irst, istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
|
||||
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_spk_), allocatable :: alpha(:), h(:,:)
|
||||
type(psb_s_vect_type), allocatable :: z(:), c(:), c_scale(:)
|
||||
type(psb_s_vect_type) :: r
|
||||
|
||||
real(psb_dpk_) :: r_norm, b_norm, a_norm, derr
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: i, j, it, itx, istop_, itmax_, itrace_, nl, m, nrst
|
||||
real(psb_spk_) :: hjj
|
||||
real(psb_spk_), allocatable, target :: aux(:)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='GCR'
|
||||
info = psb_success_
|
||||
name = 'psb_sgcr'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c_scale(nl+1),c(nl+1),z(nl+1), alpha(nl+1), stat=info)
|
||||
|
||||
h = szero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_geasb(r, desc_a,info, scratch=.true.,mold=x%v)
|
||||
|
||||
do i =1,nl+1
|
||||
call psb_geasb(c(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(z(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(c_scale(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
end do
|
||||
|
||||
itx = 0
|
||||
|
||||
nrst = -1
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
restart: do
|
||||
if (itx>= itmax_) exit restart
|
||||
h = szero
|
||||
|
||||
it = 0
|
||||
! compute r0 = b-ax0
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_geaxpby(sone, b, szero, r, desc_a, info)
|
||||
call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
nrst = nrst + 1
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
it = it + 1
|
||||
j = it
|
||||
!Apply preconditioner
|
||||
call prec%apply(r,z(j),desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(sone,a,z(j),szero,c(1),desc_a,info,work=aux)
|
||||
do i =1, j - 1
|
||||
|
||||
h(i,j) = psb_gedot(c_scale(i), c(i), desc_a, info)
|
||||
|
||||
call psb_geaxpby(sone, c(i), szero, c(i+1), desc_a, info)
|
||||
call psb_geaxpby(-h(i,j), c_scale(i), sone, c(i+1), desc_a, info)
|
||||
end do
|
||||
|
||||
h(j,j) = psb_norm2(c(j), desc_a, info)
|
||||
hjj = sone/h(j,j)
|
||||
call psb_geaxpby(hjj, c(j), szero, c_scale(j), desc_a, info)
|
||||
|
||||
alpha(j) = psb_gedot(c_scale(j), r, desc_a, info)
|
||||
|
||||
!Update residual
|
||||
call psb_geaxpby(sone, r, szero, r, desc_a, info)
|
||||
call psb_geaxpby(-alpha(j), c_scale(j), sone, r, desc_a, info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (j >= irst) exit iteration
|
||||
|
||||
|
||||
end do iteration
|
||||
|
||||
m = j
|
||||
|
||||
!Compute solution
|
||||
|
||||
call strsm('l','u','n','n',m,1,sone,h,size(h,1),alpha,size(alpha,1))
|
||||
|
||||
if (nrst == 0 ) then
|
||||
call x%set(szero)
|
||||
endif
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), sone, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
|
||||
|
||||
|
||||
end do restart
|
||||
m = j
|
||||
!Compute solution
|
||||
call strsm('l','u','n','n',m,1,sone,h,size(h,1),alpha,size(alpha,1))
|
||||
call x%set(szero)
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), sone, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
iter = j
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(r,desc_a,info)
|
||||
|
||||
do j = 1,m
|
||||
if (info == psb_success_) call psb_gefree(z(j),desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(c_scale(j),desc_a,info)
|
||||
enddo
|
||||
|
||||
do i =1,nl+1
|
||||
if (info == psb_success_) call psb_gefree(c(i),desc_a,info)
|
||||
end do
|
||||
|
||||
if (info == psb_success_) deallocate(aux,h,c_scale,z,c,alpha,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
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()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_sgcr_vect
|
||||
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_krylov_mod.f90
|
||||
! Interfaces for Krylov subspace iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_skrylov
|
||||
!
|
||||
! Front-end for the Krylov subspace iterations, realversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! methd - character The specific method; can take the values:
|
||||
! CG
|
||||
! FCG
|
||||
! CGS
|
||||
! BICG
|
||||
! BICGSTAB
|
||||
! BICGSTABL
|
||||
! RGMRES
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_skrylov_vect(method,a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop,cond)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod,only : psb_sprec_type
|
||||
use psb_linsolve_mod, psb_protect_name => psb_skrylov_vect
|
||||
|
||||
character(len=*) :: method
|
||||
Type(psb_sspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err,cond
|
||||
|
||||
|
||||
abstract interface
|
||||
subroutine psb_skryl_vect(a,prec,b,x,eps,&
|
||||
& desc_a,info,itmax,iter,err,itrace,istop)
|
||||
import :: psb_ipk_, psb_spk_, psb_desc_type, &
|
||||
& psb_sspmat_type, psb_sprec_type, psb_s_vect_type
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
real(psb_spk_), intent(in) :: eps
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_spk_), optional, intent(out) :: err
|
||||
end subroutine psb_skryl_vect
|
||||
Subroutine psb_skryl_rest_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,irst,istop)
|
||||
import :: psb_ipk_, psb_spk_, psb_desc_type, &
|
||||
& psb_sspmat_type, psb_sprec_type, psb_s_vect_type
|
||||
Type(psb_sspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
end subroutine psb_skryl_rest_vect
|
||||
Subroutine psb_skryl_cond_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,istop,cond)
|
||||
import :: psb_ipk_, psb_spk_, psb_desc_type, &
|
||||
& psb_sspmat_type, psb_sprec_type, psb_s_vect_type
|
||||
Type(psb_sspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err, cond
|
||||
end subroutine psb_skryl_cond_vect
|
||||
end interface
|
||||
|
||||
procedure(psb_skryl_vect) :: psb_sbicg_vect, psb_scgstab_vect,&
|
||||
& psb_scgs_vect
|
||||
procedure(psb_skryl_rest_vect) :: psb_srgmres_vect, psb_scgstabl_vect, psb_sgcr_vect
|
||||
procedure(psb_skryl_cond_vect) :: psb_scg_vect, psb_sfcg_vect
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act, itrace_
|
||||
character(len=20) :: name
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_krylov'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
! Default return for COND
|
||||
if (present(cond)) cond = szero
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
select case(psb_toupper(method))
|
||||
case('CG')
|
||||
call psb_scg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('FCG')
|
||||
call psb_sfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('GCR')
|
||||
call psb_sgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('CGS')
|
||||
call psb_scgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICG')
|
||||
call psb_sbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICGSTAB')
|
||||
call psb_scgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('RGMRES','GMRES')
|
||||
call psb_srgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case('BICGSTABL')
|
||||
call psb_scgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case default
|
||||
if (me == 0) write(psb_err_unit,*) trim(name),&
|
||||
& ': Warning: Unknown method ',method,&
|
||||
& ', defaulting to BiCGSTAB'
|
||||
call psb_scgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
end select
|
||||
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(method))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_skrylov_vect
|
||||
|
||||
@@ -0,0 +1,502 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Contributions to this routine:
|
||||
! Daniela di Serafino Second University of Naples
|
||||
! Pasqua D'Ambra ICAR-CNR
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_srgmres.f90
|
||||
!
|
||||
! Subroutine: psb_srgmres
|
||||
! This subroutine implements the restarted GMRES method with right
|
||||
! preconditioning.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_srgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_sspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
real(psb_spk_), allocatable :: aux(:)
|
||||
real(psb_spk_), allocatable :: c(:), s(:), h(:,:), rs(:), rst(:)
|
||||
type(psb_s_vect_type), allocatable :: v(:)
|
||||
type(psb_s_vect_type) :: w, w1, xt
|
||||
real(psb_spk_) :: tmp
|
||||
real(psb_spk_) :: scal, gm, rti, rti1
|
||||
integer(psb_ipk_) ::litmax, naux, it, k, itrace_,&
|
||||
& n_row, n_col, nl
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., use_srot=.true.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_, err_act
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
Real(psb_spk_) :: rni, xni, bni, ani,bn2, dt, r0n2
|
||||
real(psb_dpk_) :: errnum, errden, deps, derr
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RGMRES'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_sgmres'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
litmax = itmax
|
||||
else
|
||||
litmax = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c(nl+1),s(nl+1),rs(nl+1), rst(nl+1),stat=info)
|
||||
|
||||
if (info == psb_success_) call psb_geall(v,desc_a,info,n=nl+1)
|
||||
if (info == psb_success_) call psb_geall(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(xt,desc_a,info)
|
||||
if (info == psb_success_) call psb_geasb(v,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w1,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(xt,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Size of V,W,W1 ',v(1)%get_nrows(),size(v),&
|
||||
& w%get_nrows(),w1%get_nrows()
|
||||
|
||||
|
||||
if (istop_ == 1) then
|
||||
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)
|
||||
else if (istop_ == 3) then
|
||||
call psb_geaxpby(sone,b,szero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-sone,a,x,sone,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
r0n2 = psb_genrm2(v(1),desc_a,info)
|
||||
endif
|
||||
errnum = szero
|
||||
errden = sone
|
||||
deps = eps
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if ((itrace_ > 0).and.(me == 0)) call log_header(methdname)
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
|
||||
! compute r0 = b-ax0
|
||||
! check convergence
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' restart: ',itx,it
|
||||
it = 0
|
||||
call psb_geaxpby(sone,b,szero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-sone,a,x,sone,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rs(1) = psb_genrm2(v(1),desc_a,info)
|
||||
rs(2:) = szero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
scal=sone/rs(1) ! rs(1) MIGHT BE VERY SMALL - USE DSCAL TO DEAL WITH IT?
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows(),rs(1),scal
|
||||
|
||||
!
|
||||
! check convergence
|
||||
!
|
||||
if (istop_ == 1) then
|
||||
rni = psb_geamax(v(1),desc_a,info)
|
||||
xni = psb_geamax(x,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
else if (istop_ == 2) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (errnum <= eps*errden) exit restart
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
call v(1)%scal(scal) !v(1) = v(1) * scal
|
||||
|
||||
if (itx >= litmax) exit restart
|
||||
|
||||
!
|
||||
! inner iterations
|
||||
!
|
||||
|
||||
inner: Do i=1,nl
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(v(i),w1,desc_a,info)
|
||||
call psb_spmm(sone,a,w1,szero,w,desc_a,info,work=aux)
|
||||
!
|
||||
|
||||
do k = 1, i
|
||||
h(k,i) = psb_gedot(v(k),w,desc_a,info)
|
||||
call psb_geaxpby(-h(k,i),v(k),sone,w,desc_a,info)
|
||||
end do
|
||||
h(i+1,i) = psb_genrm2(w,desc_a,info)
|
||||
scal=sone/h(i+1,i)
|
||||
call psb_geaxpby(scal,w,szero,v(i+1),desc_a,info)
|
||||
do k=2,i
|
||||
call srot(1,h(k-1,i),1,h(k,i),1,real(c(k-1),kind=psb_spk_),s(k-1))
|
||||
enddo
|
||||
|
||||
|
||||
rti = h(i,i)
|
||||
rti1 = h(i+1,i)
|
||||
call srotg(rti,rti1,tmp,s(i))
|
||||
c(i) = cmplx(tmp,szero)
|
||||
call srot(1,h(i,i),1,h(i+1,i),1,real(c(i),kind=psb_spk_),s(i))
|
||||
h(i+1,i) = szero
|
||||
call srot(1,rs(i),1,rs(i+1),1,real(c(i),kind=psb_spk_),s(i))
|
||||
|
||||
if (istop_ == 1) then
|
||||
!
|
||||
! build x and then compute the residual and its infinity norm
|
||||
!
|
||||
rst = rs
|
||||
call w1%set(szero)
|
||||
call strsm('l','u','n','n',i,1,sone,h,size(h,1),rst,size(rst,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rst(1:i)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rst(k),v(k),sone,xt,desc_a,info)
|
||||
end do
|
||||
call prec%apply(xt,desc_a,info)
|
||||
call psb_geaxpby(sone,x,sone,xt,desc_a,info)
|
||||
call psb_geaxpby(sone,b,szero,w1,desc_a,info)
|
||||
call psb_spmm(-sone,a,xt,sone,w1,desc_a,info,work=aux)
|
||||
rni = psb_geamax(w1,desc_a,info)
|
||||
xni = psb_geamax(xt,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
!
|
||||
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
|
||||
if (errnum <= eps*errden) then
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(sone,xt,szero,x,desc_a,info)
|
||||
! = x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call strsm('l','u','n','n',i,1,sone,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:i)
|
||||
call w1%set(szero)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rs(k),v(k),sone,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(sone,w,sone,x,desc_a,info)
|
||||
end if
|
||||
|
||||
exit restart
|
||||
|
||||
end if
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
end do inner
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(sone,xt,szero,x,desc_a,info)! x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call strsm('l','u','n','n',nl,1,sone,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:nl)
|
||||
call w1%set(szero)
|
||||
do k=1, nl
|
||||
call psb_geaxpby(rs(k),v(k),sone,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(sone,w,sone,x,desc_a,info)
|
||||
end if
|
||||
|
||||
end do restart
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,ione,errnum,errden,deps)
|
||||
|
||||
call log_end(methdname,me,itx,itrace_,errnum,errden,deps,err=derr,iter=iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
|
||||
if (info == psb_success_) call psb_gefree(v,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(xt,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,h,c,s,rs,rst, stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_srgmres_vect
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_richardson_mod.f90
|
||||
! Interfaces for Richardson iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_srichardson
|
||||
!
|
||||
! Front-end for the Richardson iterations, realversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_sspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_sprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_srichardson_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_s_linsolve_conv_mod
|
||||
use psb_linsolve_mod, psb_protect_name => psb_srichardson_vect
|
||||
|
||||
Type(psb_sspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_sprec_type), intent(inout) :: prec
|
||||
type(psb_s_vect_type), Intent(inout) :: b
|
||||
type(psb_s_vect_type), Intent(inout) :: x
|
||||
Real(psb_spk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_spk_), Optional, Intent(out) :: err
|
||||
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act
|
||||
real(psb_spk_), allocatable, target :: aux(:)
|
||||
type(psb_s_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_s_vect_type), pointer :: q, p, r, z, w
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RICHARDSON'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_srichardson'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
call psb_geaxpby(sone,b,szero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
loop: do itx=1,itmax_
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
call psb_geaxpby(sone,z,sone,x,desc_a,info)
|
||||
call psb_geaxpby(sone,b,szero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-sone,a,x,sone,r,desc_a,info,work=aux)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit loop
|
||||
end do loop
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(methdname))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_srichardson_vect
|
||||
|
||||
@@ -0,0 +1,335 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
!
|
||||
! File: psb_zbicg.f90
|
||||
!
|
||||
! Subroutine: psb_zbicg
|
||||
! This subroutine implements the BiCG method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_type) Input: preconditioner
|
||||
! b(:) - complex Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - complex 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(psb_desc_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. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
|
||||
subroutine psb_zbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_dpk_), optional, intent(out) :: err
|
||||
! !$ local data
|
||||
complex(psb_dpk_), allocatable, target :: aux(:)
|
||||
type(psb_z_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_z_vect_type), pointer :: ww, q, r, p,&
|
||||
& zt, pt, z, rt, qt
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, istop_, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
logical, parameter :: exchange=.true., noexchange=.false.
|
||||
integer(psb_ipk_), parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
complex(psb_dpk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name,ch_err
|
||||
character(len=*), parameter :: methdname='BiCG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zbicg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! istop_ = 1: normwise backward error, infinity norm
|
||||
! istop_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
|
||||
allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=9_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
ch_err='psb_asb'
|
||||
err=info
|
||||
call psb_errpush(info,name,a_err=ch_err)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
pt => wwrk(6)
|
||||
z => wwrk(7)
|
||||
zt => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
itx = 0
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: do
|
||||
! !$
|
||||
! !$ r0 = b-ax0
|
||||
! !$
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(zone,b,zzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),' Done spmm',info
|
||||
if (info == psb_success_) call psb_geaxpby(zone,r,zzero,rt,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = zzero
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call prec%apply(rt,zt,desc_a,info,trans='c',work=aux)
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,z,desc_a,info)
|
||||
if (rho == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(zone,z,zzero,p,desc_a,info)
|
||||
call psb_geaxpby(zone,zt,zzero,pt,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(zone,z,beta,p,desc_a,info)
|
||||
call psb_geaxpby(zone,zt,beta,pt,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(zone,a,p,zzero,q,desc_a,info,&
|
||||
& work=aux)
|
||||
call psb_spmm(zone,a,pt,zzero,qt,desc_a,info,&
|
||||
& work=aux,trans='c')
|
||||
|
||||
sigma = psb_gedot(pt,q,desc_a,info)
|
||||
if (sigma == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,zone,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,zone,r,desc_a,info)
|
||||
call psb_geaxpby(-alpha,qt,zone,rt,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_zbicg_vect
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_zcg.f90
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_zcg.f90
|
||||
!
|
||||
! Subroutine: psb_zcg
|
||||
! This subroutine implements the Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_type) Input: preconditioner
|
||||
! b(:) - complex Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - complex 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_zcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
complex(psb_dpk_), allocatable, target :: aux(:),td(:),tu(:),eig(:),ewrk(:)
|
||||
integer(psb_mpk_), allocatable :: ibl(:), ispl(:), iwrk(:)
|
||||
type(psb_z_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_z_vect_type), pointer :: q, p, r, z, w
|
||||
complex(psb_dpk_) :: alpha, beta, rho, rho_old, sigma,alpha_old,beta_old
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,err_act, ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
logical :: do_cond
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CG'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zcg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
do_cond=present(cond)
|
||||
if (do_cond) then
|
||||
istebz = 0
|
||||
end if
|
||||
itx=0
|
||||
alpha = zzero
|
||||
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-Ax0
|
||||
! =
|
||||
if (itx>= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(zone,b,zzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = zzero
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
rho_old = rho
|
||||
rho = psb_gedot(r,z,desc_a,info)
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(zone,z,zzero,p,desc_a,info)
|
||||
else
|
||||
if (rho_old == zzero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown rho'
|
||||
exit iteration
|
||||
endif
|
||||
beta = rho/rho_old
|
||||
call psb_geaxpby(zone,z,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
call psb_spmm(zone,a,p,zzero,q,desc_a,info,work=aux)
|
||||
sigma = psb_gedot(p,q,desc_a,info)
|
||||
if (sigma == zzero) then
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ': CG Iteration breakdown sigma'
|
||||
exit iteration
|
||||
endif
|
||||
alpha_old = alpha
|
||||
alpha = rho/sigma
|
||||
|
||||
|
||||
|
||||
call psb_geaxpby(alpha,p,zone,x,desc_a,info)
|
||||
call psb_geaxpby(-alpha,q,zone,r,desc_a,info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
if (do_cond) then
|
||||
cond = dzero
|
||||
end if
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_zcg_vect
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_zcgs.f90
|
||||
!
|
||||
! Subroutine: psb_zcgs
|
||||
! Implements the Conjugate Gradient Squared method.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_zcgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_dpk_), allocatable, target :: aux(:)
|
||||
type(psb_z_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_z_vect_type), pointer :: ww, q, r, p, v,&
|
||||
& s, z, f, rt, qt, uv
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col,istop_, itx, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
complex(psb_dpk_) :: alpha, beta, rho, rho_old, sigma
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='CGS'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zcgs'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
Allocate(aux(naux),stat=info)
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=11_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) Then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
q => wwrk(1)
|
||||
qt => wwrk(2)
|
||||
r => wwrk(3)
|
||||
rt => wwrk(4)
|
||||
p => wwrk(5)
|
||||
v => wwrk(6)
|
||||
uv => wwrk(7)
|
||||
z => wwrk(8)
|
||||
f => wwrk(9)
|
||||
s => wwrk(10)
|
||||
ww => wwrk(11)
|
||||
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (itx >= itmax_) exit restart
|
||||
it = 0
|
||||
call psb_geaxpby(zone,b,zzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_geaxpby(zone,r,zzero,rt,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
rho = zzero
|
||||
|
||||
iteration: do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rt,r,desc_a,info)
|
||||
|
||||
if (rho == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(zone,r,zzero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(zone,r,zzero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)
|
||||
call psb_geaxpby(zone,r,zzero,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(beta,q,zone,uv,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(zone,q,beta,p,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(zone,uv,beta,p,desc_a,info)
|
||||
end if
|
||||
|
||||
if (info == psb_success_) call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(zone,a,f,zzero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='First loop part ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(rt,v,desc_a,info)
|
||||
if (sigma == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration breakdown s1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(zone,uv,zzero,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,v,zone,q,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(zone,uv,zzero,s,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(zone,q,zone,s,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call prec%apply(s,z,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(alpha,z,zone,x,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_spmm(zone,a,z,zzero,qt,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(-alpha,qt,zone,r,desc_a,info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X update ')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_zcgs_vect
|
||||
@@ -0,0 +1,393 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_zcgstab.f90
|
||||
!
|
||||
! Subroutine: psb_zcgstab
|
||||
! This subroutine implements the BiCG Stabilized method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
Subroutine psb_zcgstab_vect(a,prec,b,x,eps,desc_a,info,itmax,iter,err,itrace,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
class(psb_zprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = Local data
|
||||
complex(psb_dpk_), allocatable, target :: aux(:),wwrk(:,:)
|
||||
type(psb_z_vect_type) :: q, r, p, v, s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it,itrace_,&
|
||||
& n_row, n_col
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., debug1 = .False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, err_act, i
|
||||
integer(psb_ipk_) :: istop_
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
real(psb_dpk_) :: derr
|
||||
complex(psb_dpk_) :: alpha, beta, rho, rho_old, sigma, omega, tau
|
||||
type(psb_itconv_type) :: stopdat
|
||||
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zcgstab'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
ctxt = desc_a%get_context()
|
||||
call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
If (Present(istop)) Then
|
||||
istop_ = istop
|
||||
Else
|
||||
istop_ = 2
|
||||
Endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b|| norm 2
|
||||
!
|
||||
! = if (.not.same_type_as(x,b)) then
|
||||
! = write(0,*) 'Warning: different dynamic types for X and B '
|
||||
! = end if
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
naux=6*n_col
|
||||
if (info == psb_success_) allocate(aux(naux),stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
|
||||
call psb_geasb(q,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(r,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(p,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(v,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(s,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(t,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(z,desc_a,info,mold=x%v,scratch=.true.)
|
||||
call psb_geasb(f,desc_a,info,mold=x%v,scratch=.true.)
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
If (Present(itmax)) Then
|
||||
itmax_ = itmax
|
||||
Else
|
||||
itmax_ = 1000
|
||||
Endif
|
||||
|
||||
If (Present(itrace)) Then
|
||||
itrace_ = itrace
|
||||
Else
|
||||
itrace_ = 0
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
restart: Do
|
||||
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(zone,b,zzero,r,desc_a,info)
|
||||
|
||||
call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
call psb_geaxpby(zone,r,zzero,q,desc_a,info)
|
||||
|
||||
! Perhaps we already satisfy the convergence criterion...
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='Init residual chk')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
rho = zzero
|
||||
|
||||
iteration: Do
|
||||
it = it + 1
|
||||
itx = itx + 1
|
||||
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration: ',itx
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(q,r,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call r%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rho: ',rho
|
||||
|
||||
if (rho == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown R',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
if (it == 1) then
|
||||
call psb_geaxpby(zone,r,zzero,p,desc_a,info)
|
||||
else
|
||||
beta = (rho/rho_old)*(alpha/omega)
|
||||
call psb_geaxpby(-omega,v,zone,p,desc_a,info)
|
||||
call psb_geaxpby(zone,r,beta,p,desc_a,info)
|
||||
End If
|
||||
|
||||
call prec%apply(p,f,desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(zone,a,f,zzero,v,desc_a,info,&
|
||||
& work=aux)
|
||||
|
||||
|
||||
sigma = psb_gedot(q,v,desc_a,info)
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call q%sync()
|
||||
call v%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Sigma: ',sigma
|
||||
|
||||
if (sigma == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S1', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
alpha = rho/sigma
|
||||
call psb_geaxpby(zone,r,zzero,s,desc_a,info)
|
||||
call psb_geaxpby(-alpha,v,zone,s,desc_a,info)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' alpha: ',alpha
|
||||
|
||||
|
||||
if (psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='psb_geaxpby')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call prec%apply(s,z,desc_a,info,work=aux)
|
||||
Call psb_spmm(zone,a,z,zzero,t,desc_a,info,work=aux)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='precaply/spmm')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
sigma = psb_gedot(t,t,desc_a,info)
|
||||
if (sigma == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown S2', sigma
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
tau = psb_gedot(t,s,desc_a,info)
|
||||
omega = tau/sigma
|
||||
|
||||
if (debug_level >= psb_debug_ext_) then
|
||||
call t%sync()
|
||||
call s%sync()
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' sigma, tau, omega: ',sigma, tau, omega
|
||||
|
||||
if (omega == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Iteration breakdown O',omega
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
call psb_geaxpby(alpha,f,zone,x,desc_a,info)
|
||||
call psb_geaxpby(omega,z,zone,x,desc_a,info)
|
||||
call psb_geaxpby(zone,s,zzero,r,desc_a,info)
|
||||
call psb_geaxpby(-omega,t,zone,r,desc_a,info)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (psb_errstatus_fatal()) Then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='X/R update ')
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
deallocate(aux,stat=info)
|
||||
|
||||
call x%sync()
|
||||
call psb_gefree(q,desc_a,info)
|
||||
call psb_gefree(r,desc_a,info)
|
||||
call psb_gefree(p,desc_a,info)
|
||||
call psb_gefree(v,desc_a,info)
|
||||
call psb_gefree(s,desc_a,info)
|
||||
call psb_gefree(t,desc_a,info)
|
||||
call psb_gefree(z,desc_a,info)
|
||||
call psb_gefree(f,desc_a,info)
|
||||
|
||||
if(psb_errstatus_fatal()) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_zcgstab_vect
|
||||
@@ -0,0 +1,421 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_zcgstabl.f90
|
||||
!
|
||||
! Subroutine: psb_zcgstabl
|
||||
! Implements the BICGSTAB(L) method
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_type) Input: preconditioner
|
||||
! b(:) - complex Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - complex 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration
|
||||
! is stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter L
|
||||
!
|
||||
!
|
||||
!
|
||||
Subroutine psb_zcgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
class(psb_zprec_type), Intent(inout) :: prec
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_dpk_), allocatable, target :: aux(:), gamma(:),&
|
||||
& gamma1(:), gamma2(:), taum(:,:), sigma(:)
|
||||
type(psb_z_vect_type), allocatable, target :: wwrk(:),uh(:), rh(:)
|
||||
type(psb_z_vect_type), Pointer :: ww, q, r, rt0, p, v, &
|
||||
& s, t, z, f
|
||||
|
||||
integer(psb_ipk_) :: itmax_, naux, it, itrace_,&
|
||||
& n_row, n_col, nl, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_,j, k
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
complex(psb_dpk_) :: alpha, beta, rho, rho_old, rni, xni, bni, ani,bn2,&
|
||||
& omega
|
||||
real(psb_dpk_) :: derr
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BiCGStab(L)'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zcgstabl'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& 'present: irst: ',irst,nl
|
||||
else
|
||||
nl = 1
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_) call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),gamma(0:nl),gamma1(nl),&
|
||||
&gamma2(nl),taum(nl,nl),sigma(nl), stat=info)
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_alloc_dealloc_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (info == psb_success_) Call psb_geall(wwrk,desc_a,info,n=10_psb_ipk_)
|
||||
if (info == psb_success_) Call psb_geall(uh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geall(rh,desc_a,info,n=nl+1,lb=izero)
|
||||
if (info == psb_success_) Call psb_geasb(wwrk,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(uh,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) Call psb_geasb(rh,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
q => wwrk(1)
|
||||
r => wwrk(2)
|
||||
p => wwrk(3)
|
||||
v => wwrk(4)
|
||||
f => wwrk(5)
|
||||
s => wwrk(6)
|
||||
t => wwrk(7)
|
||||
z => wwrk(8)
|
||||
ww => wwrk(9)
|
||||
rt0 => wwrk(10)
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
! =
|
||||
! = r0 = b-ax0
|
||||
! =
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),' restart: ',itx,it
|
||||
if (itx >= itmax_) exit restart
|
||||
|
||||
it = 0
|
||||
call psb_geaxpby(zone,b,zzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
|
||||
if (info == psb_success_) call prec%apply(r,desc_a,info)
|
||||
|
||||
if (info == psb_success_) call psb_geaxpby(zone,r,zzero,rt0,desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(zone,r,zzero,rh(0),desc_a,info)
|
||||
if (info == psb_success_) call psb_geaxpby(zzero,r,zzero,uh(0),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rho = zone
|
||||
alpha = zzero
|
||||
omega = zone
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows()
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
iteration: do
|
||||
it = it + nl
|
||||
itx = itx + nl
|
||||
rho = -omega*rho
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' iteration: ',itx, rho
|
||||
|
||||
do j = 0, nl -1
|
||||
If (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),'bicg part: ',j, nl
|
||||
|
||||
rho_old = rho
|
||||
rho = psb_gedot(rh(j),rt0,desc_a,info)
|
||||
if (rho == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown r',rho
|
||||
exit iteration
|
||||
endif
|
||||
|
||||
beta = alpha*rho/rho_old
|
||||
rho_old = rho
|
||||
do k=0, j
|
||||
! = call psb_geaxpby(zone,rh(:,0:j),-beta,uh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(zone,rh(k),-beta,uh(k),desc_a,info)
|
||||
end do
|
||||
call psb_spmm(zone,a,uh(j),zzero,uh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(uh(j+1),desc_a,info)
|
||||
|
||||
gamma(j) = psb_gedot(uh(j+1),rt0,desc_a,info)
|
||||
|
||||
if (gamma(j) == zzero) then
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bi-cgstab iteration breakdown s2',gamma(j)
|
||||
exit iteration
|
||||
endif
|
||||
alpha = rho/gamma(j)
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' bicg part: alpha=r/g ',alpha,rho,gamma(j)
|
||||
|
||||
do k=0,j
|
||||
! = call psb_geaxpby(-alpha,uh(:,1:j+1),zone,rh(:,0:j),desc_a,info)
|
||||
call psb_geaxpby(-alpha,uh(k+1),zone,rh(k),desc_a,info)
|
||||
end do
|
||||
call psb_geaxpby(alpha,uh(0),zone,x,desc_a,info)
|
||||
call psb_spmm(zone,a,rh(j),zzero,rh(j+1),desc_a,info,work=aux)
|
||||
|
||||
call prec%apply(rh(j+1),desc_a,info)
|
||||
|
||||
enddo
|
||||
|
||||
do j=1, nl
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' mod g-s part: ',j, nl
|
||||
|
||||
do i=1, j-1
|
||||
taum(i,j) = psb_gedot(rh(i),rh(j),desc_a,info)
|
||||
taum(i,j) = taum(i,j)/sigma(i)
|
||||
call psb_geaxpby(-taum(i,j),rh(i),zone,rh(j),desc_a,info)
|
||||
enddo
|
||||
sigma(j) = psb_gedot(rh(j),rh(j),desc_a,info)
|
||||
gamma1(j) = psb_gedot(rh(0),rh(j),desc_a,info)
|
||||
gamma1(j) = gamma1(j)/sigma(j)
|
||||
enddo
|
||||
|
||||
gamma(nl) = gamma1(nl)
|
||||
omega = gamma(nl)
|
||||
|
||||
do j=nl-1,1,-1
|
||||
gamma(j) = gamma1(j)
|
||||
do i=j+1,nl
|
||||
gamma(j) = gamma(j) - taum(j,i) * gamma(i)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
do j=1,nl-1
|
||||
gamma2(j) = gamma(j+1)
|
||||
do i=j+1,nl-1
|
||||
gamma2(j) = gamma2(j) + taum(j,i) * gamma(i+1)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
call psb_geaxpby(gamma(1),rh(0),zone,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(nl),rh(nl),zone,rh(0),desc_a,info)
|
||||
call psb_geaxpby(-gamma(nl),uh(nl),zone,uh(0),desc_a,info)
|
||||
|
||||
do j=1, nl-1
|
||||
call psb_geaxpby(-gamma(j),uh(j),zone,uh(0),desc_a,info)
|
||||
call psb_geaxpby(gamma2(j),rh(j),zone,x,desc_a,info)
|
||||
call psb_geaxpby(-gamma1(j),rh(j),zone,rh(0),desc_a,info)
|
||||
enddo
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,rh(0),desc_a,stopdat,info)) exit restart
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(uh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(rh,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
End Subroutine psb_zcgstabl_vect
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_zfcg.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Flexible Conjugate gradients C
|
||||
! C SIAM Journal on Scientific Computing 22(4), C
|
||||
! C pp. 1444-1460, 2000 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_zfcg.f90
|
||||
!
|
||||
! Subroutine: psb_zfcg
|
||||
! This subroutine implements the Flexible Conjugate Gradient method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
!
|
||||
subroutine psb_zfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop,cond)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_dpk_), Optional, Intent(out) :: err,cond
|
||||
! = Local data
|
||||
type(psb_z_vect_type) :: v, w, d , q, r
|
||||
complex(psb_dpk_) :: alpha, beta, delta, gamma, theta
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: i, idx, nc2l, it, itx, istop_, itmax_, itrace_
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
complex(psb_dpk_), allocatable, target :: aux(:)
|
||||
complex(psb_dpk_) :: vres(3)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='FCG'
|
||||
logical, parameter :: debug = .false.
|
||||
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zfcg'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
|
||||
!Assemble w, v, d, q, r, u
|
||||
call psb_geasb(w, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(v, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(d, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(q, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
call psb_geasb(r, desc_a,info,&
|
||||
& scratch=.true.,mold=x%v)
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,&
|
||||
& a,x,b,eps,desc_a,stopdat,info)
|
||||
itx = 0
|
||||
|
||||
restart: do
|
||||
if (itx>= itmax_) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on itmax '
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! r=b -Ax
|
||||
call psb_geaxpby(zone,b,zzero,r, desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-zone,a,x,zone,r,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
|
||||
! Apply the preconditioner v=Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(zone,a,v,zzero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
|
||||
|
||||
call psb_sum(ctxt, vres(1:2))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart AB',itx, alpha, beta
|
||||
end if
|
||||
if (beta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on beta=0 from restart'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! d = v
|
||||
call psb_geaxpby(zone, v, zzero, d, desc_a, info)
|
||||
! q = w
|
||||
call psb_geaxpby(zone, w, zzero, q, desc_a, info)
|
||||
|
||||
! compute delta=beta
|
||||
! then
|
||||
! x = x + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
delta = beta
|
||||
theta = alpha/delta
|
||||
call psb_geaxpby(theta, d, zone, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, zone, r, desc_a, info)
|
||||
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' restart DT',itx, delta, theta
|
||||
end if
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on convergence from iteration'
|
||||
exit restart
|
||||
end if
|
||||
|
||||
! Apply the preconditioner v = Pr
|
||||
! Compute w = Av
|
||||
call prec%apply(r,v,desc_a,info,work=aux)
|
||||
if (info == psb_success_) call psb_spmm(zone,a,v,zzero,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_internal_error_,name,&
|
||||
& a_err='Error during residual'); goto 9999
|
||||
end if
|
||||
|
||||
vres(1) = psb_gedot(r, v, desc_a, info, global = .false.)
|
||||
vres(2) = psb_gedot(w, v, desc_a, info, global = .false.)
|
||||
vres(3) = psb_gedot(q, v, desc_a, info, global = .false.)
|
||||
|
||||
call psb_sum(ctxt, vres(1:3))
|
||||
|
||||
alpha = vres(1)
|
||||
beta = vres(2)
|
||||
gamma = vres(3)
|
||||
|
||||
! Compute d = v-(gamma/delta)*d
|
||||
! q = w-(gamma/delta)*q
|
||||
! DELTA==0 here would have been caught earlier
|
||||
theta= gamma/delta
|
||||
call psb_geaxpby(zone, v, -theta, d, desc_a, info)
|
||||
call psb_geaxpby(zone, w, -theta, q , desc_a, info)
|
||||
|
||||
! update delta
|
||||
delta = beta - (gamma*gamma)/delta
|
||||
|
||||
if (delta == dzero) then
|
||||
if (debug.and.(me==0)) write(0,*) name,' Exit on delta=0 from iteration'
|
||||
exit iteration
|
||||
end if
|
||||
! update u and r
|
||||
! u = u + (alpha/delta)*d
|
||||
! r = r - (alpha/delta)*q
|
||||
theta= alpha/delta
|
||||
if (debug.and.(me==0)) then
|
||||
write(0,*) name,' iteration ',itx, alpha,beta,gamma,delta,theta
|
||||
end if
|
||||
call psb_geaxpby(theta, d, zone, x, desc_a, info)
|
||||
call psb_geaxpby(-theta, q, zone, r, desc_a, info)
|
||||
|
||||
end do iteration
|
||||
end do restart
|
||||
|
||||
|
||||
call psb_end_conv(methdname,itx ,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
return
|
||||
9999 continue
|
||||
call psb_erractionrestore(err_act)
|
||||
if (err_act.eq.psb_act_abort_) then
|
||||
call psb_error()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_zfcg_vect
|
||||
@@ -0,0 +1,370 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! File: psb_zgcr.f90
|
||||
!!
|
||||
!! Contributors: Ambra Abdullahi (UNITOV) and Pasqua D’Ambra (IAC-CNR)
|
||||
!!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993
|
||||
! C C
|
||||
! C [4] Notay, Yvan C
|
||||
! C Aggregation-based algebraic multigrid method C
|
||||
! C SIAM Journal on Scientific Computing 34, C
|
||||
! C pp. A2288-A2316, 2012 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_zgcr.f90
|
||||
!
|
||||
! Subroutine: psb_zgcr
|
||||
! This subroutine implements the GCR method.
|
||||
!
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_type) Input: preconditioner
|
||||
! b(:) - real Input: vector containing the
|
||||
! right hand side B
|
||||
! x(:) - real 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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
!
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_zgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace, irst, istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
|
||||
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_dpk_), allocatable :: alpha(:), h(:,:)
|
||||
type(psb_z_vect_type), allocatable :: z(:), c(:), c_scale(:)
|
||||
type(psb_z_vect_type) :: r
|
||||
|
||||
real(psb_dpk_) :: r_norm, b_norm, a_norm, derr
|
||||
integer(psb_ipk_) :: n_col, naux, err_act
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
integer(psb_ipk_) :: i, j, it, itx, istop_, itmax_, itrace_, nl, m, nrst
|
||||
complex(psb_dpk_) :: hjj
|
||||
complex(psb_dpk_), allocatable, target :: aux(:)
|
||||
character(len=20) :: name
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=*), parameter :: methdname='GCR'
|
||||
info = psb_success_
|
||||
name = 'psb_zgcr'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c_scale(nl+1),c(nl+1),z(nl+1), alpha(nl+1), stat=info)
|
||||
|
||||
h = zzero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_geasb(r, desc_a,info, scratch=.true.,mold=x%v)
|
||||
|
||||
do i =1,nl+1
|
||||
call psb_geasb(c(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(z(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
call psb_geasb(c_scale(i), desc_a,info, scratch=.true.,mold=x%v)
|
||||
end do
|
||||
|
||||
itx = 0
|
||||
|
||||
nrst = -1
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
restart: do
|
||||
if (itx>= itmax_) exit restart
|
||||
h = zzero
|
||||
|
||||
it = 0
|
||||
! compute r0 = b-ax0
|
||||
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_geaxpby(zone, b, zzero, r, desc_a, info)
|
||||
call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
nrst = nrst + 1
|
||||
|
||||
iteration: do
|
||||
|
||||
itx = itx + 1
|
||||
it = it + 1
|
||||
j = it
|
||||
!Apply preconditioner
|
||||
call prec%apply(r,z(j),desc_a,info,work=aux)
|
||||
|
||||
call psb_spmm(zone,a,z(j),zzero,c(1),desc_a,info,work=aux)
|
||||
do i =1, j - 1
|
||||
|
||||
h(i,j) = psb_gedot(c_scale(i), c(i), desc_a, info)
|
||||
|
||||
call psb_geaxpby(zone, c(i), zzero, c(i+1), desc_a, info)
|
||||
call psb_geaxpby(-h(i,j), c_scale(i), zone, c(i+1), desc_a, info)
|
||||
end do
|
||||
|
||||
h(j,j) = psb_norm2(c(j), desc_a, info)
|
||||
hjj = zone/h(j,j)
|
||||
call psb_geaxpby(hjj, c(j), zzero, c_scale(j), desc_a, info)
|
||||
|
||||
alpha(j) = psb_gedot(c_scale(j), r, desc_a, info)
|
||||
|
||||
!Update residual
|
||||
call psb_geaxpby(zone, r, zzero, r, desc_a, info)
|
||||
call psb_geaxpby(-alpha(j), c_scale(j), zone, r, desc_a, info)
|
||||
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit restart
|
||||
|
||||
if (j >= irst) exit iteration
|
||||
|
||||
|
||||
end do iteration
|
||||
|
||||
m = j
|
||||
|
||||
!Compute solution
|
||||
|
||||
call ztrsm('l','u','n','n',m,1,zone,h,size(h,1),alpha,size(alpha,1))
|
||||
|
||||
if (nrst == 0 ) then
|
||||
call x%set(zzero)
|
||||
endif
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), zone, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
|
||||
|
||||
|
||||
end do restart
|
||||
m = j
|
||||
!Compute solution
|
||||
call ztrsm('l','u','n','n',m,1,zone,h,size(h,1),alpha,size(alpha,1))
|
||||
call x%set(zzero)
|
||||
do i=1,m
|
||||
call psb_geaxpby(alpha(i), z(i), zone, x, desc_a, info)
|
||||
enddo
|
||||
|
||||
iter = j
|
||||
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(r,desc_a,info)
|
||||
|
||||
do j = 1,m
|
||||
if (info == psb_success_) call psb_gefree(z(j),desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(c_scale(j),desc_a,info)
|
||||
enddo
|
||||
|
||||
do i =1,nl+1
|
||||
if (info == psb_success_) call psb_gefree(c(i),desc_a,info)
|
||||
end do
|
||||
|
||||
if (info == psb_success_) deallocate(aux,h,c_scale,z,c,alpha,stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
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()
|
||||
return
|
||||
end if
|
||||
|
||||
return
|
||||
end subroutine psb_zgcr_vect
|
||||
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_krylov_mod.f90
|
||||
! Interfaces for Krylov subspace iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_zkrylov
|
||||
!
|
||||
! Front-end for the Krylov subspace iterations, complexversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! methd - character The specific method; can take the values:
|
||||
! CG
|
||||
! FCG
|
||||
! CGS
|
||||
! BICG
|
||||
! BICGSTAB
|
||||
! BICGSTABL
|
||||
! RGMRES
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_zkrylov_vect(method,a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop,cond)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod,only : psb_zprec_type
|
||||
use psb_linsolve_mod, psb_protect_name => psb_zkrylov_vect
|
||||
|
||||
character(len=*) :: method
|
||||
Type(psb_zspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err,cond
|
||||
|
||||
|
||||
abstract interface
|
||||
subroutine psb_zkryl_vect(a,prec,b,x,eps,&
|
||||
& desc_a,info,itmax,iter,err,itrace,istop)
|
||||
import :: psb_ipk_, psb_dpk_, psb_desc_type, &
|
||||
& psb_zspmat_type, psb_zprec_type, psb_z_vect_type
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
real(psb_dpk_), intent(in) :: eps
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), optional, intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), optional, intent(out) :: iter
|
||||
real(psb_dpk_), optional, intent(out) :: err
|
||||
end subroutine psb_zkryl_vect
|
||||
Subroutine psb_zkryl_rest_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,irst,istop)
|
||||
import :: psb_ipk_, psb_dpk_, psb_desc_type, &
|
||||
& psb_zspmat_type, psb_zprec_type, psb_z_vect_type
|
||||
Type(psb_zspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
end subroutine psb_zkryl_rest_vect
|
||||
Subroutine psb_zkryl_cond_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err, itrace,istop,cond)
|
||||
import :: psb_ipk_, psb_dpk_, psb_desc_type, &
|
||||
& psb_zspmat_type, psb_zprec_type, psb_z_vect_type
|
||||
Type(psb_zspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err, cond
|
||||
end subroutine psb_zkryl_cond_vect
|
||||
end interface
|
||||
|
||||
procedure(psb_zkryl_vect) :: psb_zbicg_vect, psb_zcgstab_vect,&
|
||||
& psb_zcgs_vect
|
||||
procedure(psb_zkryl_rest_vect) :: psb_zrgmres_vect, psb_zcgstabl_vect, psb_zgcr_vect
|
||||
procedure(psb_zkryl_cond_vect) :: psb_zcg_vect, psb_zfcg_vect
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act, itrace_
|
||||
character(len=20) :: name
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_krylov'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
! Default return for COND
|
||||
if (present(cond)) cond = dzero
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
select case(psb_toupper(method))
|
||||
case('CG')
|
||||
call psb_zcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('FCG')
|
||||
call psb_zfcg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop,cond=cond)
|
||||
case('GCR')
|
||||
call psb_zgcr_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('CGS')
|
||||
call psb_zcgs_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICG')
|
||||
call psb_zbicg_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('BICGSTAB')
|
||||
call psb_zcgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
case('RGMRES','GMRES')
|
||||
call psb_zrgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case('BICGSTABL')
|
||||
call psb_zcgstabl_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,irst=irst,istop=istop)
|
||||
case default
|
||||
if (me == 0) write(psb_err_unit,*) trim(name),&
|
||||
& ': Warning: Unknown method ',method,&
|
||||
& ', defaulting to BiCGSTAB'
|
||||
call psb_zcgstab_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
&itmax,iter,err,itrace=itrace_,istop=istop)
|
||||
end select
|
||||
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(method))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_zkrylov_vect
|
||||
|
||||
@@ -0,0 +1,502 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Contributions to this routine:
|
||||
! Daniela di Serafino Second University of Naples
|
||||
! Pasqua D'Ambra ICAR-CNR
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! C C
|
||||
! C References: C
|
||||
! C [1] Duff, I., Marrone, M., Radicati, G., and Vittoli, C. C
|
||||
! C Level 3 basic linear algebra subprograms for sparse C
|
||||
! C matrices: a user level interface C
|
||||
! C ACM Trans. Math. Softw., 23(3), 379-401, 1997. C
|
||||
! C C
|
||||
! C C
|
||||
! C [2] S. Filippone, M. Colajanni C
|
||||
! C PSBLAS: A library for parallel linear algebra C
|
||||
! C computation on sparse matrices C
|
||||
! C ACM Trans. on Math. Softw., 26(4), 527-550, Dec. 2000. C
|
||||
! C C
|
||||
! C [3] M. Arioli, I. Duff, M. Ruiz C
|
||||
! C Stopping criteria for iterative solvers C
|
||||
! C SIAM J. Matrix Anal. Appl., Vol. 13, pp. 138-144, 1992 C
|
||||
! C C
|
||||
! C C
|
||||
! C [4] R. Barrett et al C
|
||||
! C Templates for the solution of linear systems C
|
||||
! C SIAM, 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! C [5] G. Sleijpen, D. Fokkema C
|
||||
! C BICGSTAB(L) for linear equations involving unsymmetric C
|
||||
! C matrices with complex spectrum C
|
||||
! C Electronic Trans. on Numer. Analysis, Vol. 1, pp. 11-32, C
|
||||
! C Sep. 1993 C
|
||||
! C C
|
||||
! C C
|
||||
! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
! File: psb_zrgmres.f90
|
||||
!
|
||||
! Subroutine: psb_zrgmres
|
||||
! This subroutine implements the restarted GMRES method with right
|
||||
! preconditioning.
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_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(psb_desc_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.
|
||||
! performed.
|
||||
! err - real (optional) Output: error estimate on exit. If the
|
||||
! denominator of the estimate is exactly
|
||||
! 0, it is changed into 1.
|
||||
! 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|/(|a||x|+|b|); here the iteration is
|
||||
! stopped when |r| <= eps * (|a||x|+|b|)
|
||||
! 2: err = |r|/|b|; here the iteration is
|
||||
! stopped when |r| <= eps * |b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual.
|
||||
! irst - integer(optional) Input: restart parameter
|
||||
!
|
||||
|
||||
subroutine psb_zrgmres_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,irst,istop)
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod
|
||||
implicit none
|
||||
type(psb_zspmat_type), intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, irst,istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
! = local data
|
||||
complex(psb_dpk_), allocatable :: aux(:)
|
||||
complex(psb_dpk_), allocatable :: c(:), s(:), h(:,:), rs(:), rst(:)
|
||||
type(psb_z_vect_type), allocatable :: v(:)
|
||||
type(psb_z_vect_type) :: w, w1, xt
|
||||
real(psb_dpk_) :: tmp
|
||||
complex(psb_dpk_) :: scal, gm, rti, rti1
|
||||
integer(psb_ipk_) ::litmax, naux, it, k, itrace_,&
|
||||
& n_row, n_col, nl
|
||||
integer(psb_lpk_) :: mglob
|
||||
Logical, Parameter :: exchange=.True., noexchange=.False., use_srot=.true.
|
||||
integer(psb_ipk_), Parameter :: irmax = 8
|
||||
integer(psb_ipk_) :: itx, i, istop_, err_act
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me
|
||||
Real(psb_dpk_) :: rni, xni, bni, ani,bn2, dt, r0n2
|
||||
real(psb_dpk_) :: errnum, errden, deps, derr
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RGMRES'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zgmres'
|
||||
call psb_erractionsave(err_act)
|
||||
debug_unit = psb_get_debug_unit()
|
||||
debug_level = psb_get_debug_level()
|
||||
|
||||
ctxt = desc_a%get_context()
|
||||
Call psb_info(ctxt, me, np)
|
||||
if (debug_level >= psb_debug_ext_)&
|
||||
& write(debug_unit,*) me,' ',trim(name),': from psb_info',np
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
!
|
||||
! ISTOP_ = 1: Normwise backward error, infinity norm
|
||||
! ISTOP_ = 2: ||r||/||b||, 2-norm
|
||||
!
|
||||
|
||||
if ((istop_ < 1 ).or.(istop_ > 2 ) ) then
|
||||
info=psb_err_invalid_istop_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/istop_/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
if (present(itmax)) then
|
||||
litmax = itmax
|
||||
else
|
||||
litmax = 1000
|
||||
endif
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = 0
|
||||
end if
|
||||
|
||||
if (present(irst)) then
|
||||
nl = irst
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: irst: ',irst,nl
|
||||
else
|
||||
nl = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: irst: ',irst,nl
|
||||
endif
|
||||
if (nl <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nl/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X')
|
||||
goto 9999
|
||||
end if
|
||||
call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux),h(nl+1,nl+1),&
|
||||
&c(nl+1),s(nl+1),rs(nl+1), rst(nl+1),stat=info)
|
||||
|
||||
if (info == psb_success_) call psb_geall(v,desc_a,info,n=nl+1)
|
||||
if (info == psb_success_) call psb_geall(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_geall(xt,desc_a,info)
|
||||
if (info == psb_success_) call psb_geasb(v,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(w1,desc_a,info,mold=x%v)
|
||||
if (info == psb_success_) call psb_geasb(xt,desc_a,info,mold=x%v)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Size of V,W,W1 ',v(1)%get_nrows(),size(v),&
|
||||
& w%get_nrows(),w1%get_nrows()
|
||||
|
||||
|
||||
if (istop_ == 1) then
|
||||
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)
|
||||
else if (istop_ == 3) then
|
||||
call psb_geaxpby(zone,b,zzero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-zone,a,x,zone,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
r0n2 = psb_genrm2(v(1),desc_a,info)
|
||||
endif
|
||||
errnum = zzero
|
||||
errden = zone
|
||||
deps = eps
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
if ((itrace_ > 0).and.(me == 0)) call log_header(methdname)
|
||||
|
||||
itx = 0
|
||||
restart: do
|
||||
|
||||
! compute r0 = b-ax0
|
||||
! check convergence
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' restart: ',itx,it
|
||||
it = 0
|
||||
call psb_geaxpby(zone,b,zzero,v(1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_spmm(-zone,a,x,zone,v(1),desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
rs(1) = psb_genrm2(v(1),desc_a,info)
|
||||
rs(2:) = zzero
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
scal=zone/rs(1) ! rs(1) MIGHT BE VERY SMALL - USE DSCAL TO DEAL WITH IT?
|
||||
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' on entry to amax: b: ',b%get_nrows(),rs(1),scal
|
||||
|
||||
!
|
||||
! check convergence
|
||||
!
|
||||
if (istop_ == 1) then
|
||||
rni = psb_geamax(v(1),desc_a,info)
|
||||
xni = psb_geamax(x,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
else if (istop_ == 2) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
rni = psb_genrm2(v(1),desc_a,info)
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (errnum <= eps*errden) exit restart
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
call v(1)%scal(scal) !v(1) = v(1) * scal
|
||||
|
||||
if (itx >= litmax) exit restart
|
||||
|
||||
!
|
||||
! inner iterations
|
||||
!
|
||||
|
||||
inner: Do i=1,nl
|
||||
itx = itx + 1
|
||||
|
||||
call prec%apply(v(i),w1,desc_a,info)
|
||||
call psb_spmm(zone,a,w1,zzero,w,desc_a,info,work=aux)
|
||||
!
|
||||
|
||||
do k = 1, i
|
||||
h(k,i) = psb_gedot(v(k),w,desc_a,info)
|
||||
call psb_geaxpby(-h(k,i),v(k),zone,w,desc_a,info)
|
||||
end do
|
||||
h(i+1,i) = psb_genrm2(w,desc_a,info)
|
||||
scal=zone/h(i+1,i)
|
||||
call psb_geaxpby(scal,w,zzero,v(i+1),desc_a,info)
|
||||
do k=2,i
|
||||
call zrot(1,h(k-1,i),1,h(k,i),1,real(c(k-1),kind=psb_dpk_),s(k-1))
|
||||
enddo
|
||||
|
||||
|
||||
rti = h(i,i)
|
||||
rti1 = h(i+1,i)
|
||||
call zrotg(rti,rti1,tmp,s(i))
|
||||
c(i) = cmplx(tmp,dzero)
|
||||
call zrot(1,h(i,i),1,h(i+1,i),1,real(c(i),kind=psb_dpk_),s(i))
|
||||
h(i+1,i) = zzero
|
||||
call zrot(1,rs(i),1,rs(i+1),1,real(c(i),kind=psb_dpk_),s(i))
|
||||
|
||||
if (istop_ == 1) then
|
||||
!
|
||||
! build x and then compute the residual and its infinity norm
|
||||
!
|
||||
rst = rs
|
||||
call w1%set(zzero)
|
||||
call ztrsm('l','u','n','n',i,1,zone,h,size(h,1),rst,size(rst,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rst(1:i)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rst(k),v(k),zone,xt,desc_a,info)
|
||||
end do
|
||||
call prec%apply(xt,desc_a,info)
|
||||
call psb_geaxpby(zone,x,zone,xt,desc_a,info)
|
||||
call psb_geaxpby(zone,b,zzero,w1,desc_a,info)
|
||||
call psb_spmm(-zone,a,xt,zone,w1,desc_a,info,work=aux)
|
||||
rni = psb_geamax(w1,desc_a,info)
|
||||
xni = psb_geamax(xt,desc_a,info)
|
||||
errnum = rni
|
||||
errden = (ani*xni+bni)
|
||||
!
|
||||
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = bn2
|
||||
else if (istop_ == 3) then
|
||||
!
|
||||
! compute the residual 2-norm as byproduct of the solution
|
||||
! procedure of the least-squares problem
|
||||
!
|
||||
rni = abs(rs(i+1))
|
||||
errnum = rni
|
||||
errden = r0n2
|
||||
endif
|
||||
|
||||
if (errnum <= eps*errden) then
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(zone,xt,zzero,x,desc_a,info)
|
||||
! = x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call ztrsm('l','u','n','n',i,1,zone,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:i)
|
||||
call w1%set(zzero)
|
||||
do k=1, i
|
||||
call psb_geaxpby(rs(k),v(k),zone,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(zone,w,zone,x,desc_a,info)
|
||||
end if
|
||||
|
||||
exit restart
|
||||
|
||||
end if
|
||||
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,itrace_,errnum,errden,deps)
|
||||
|
||||
end do inner
|
||||
|
||||
if (istop_ == 1) then
|
||||
call psb_geaxpby(zone,xt,zzero,x,desc_a,info)! x = xt
|
||||
else if (istop_ == 2) then
|
||||
!
|
||||
! build x
|
||||
!
|
||||
call ztrsm('l','u','n','n',nl,1,zone,h,size(h,1),rs,size(rs,1))
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' Rebuild x-> RS:',rs(1:nl)
|
||||
call w1%set(zzero)
|
||||
do k=1, nl
|
||||
call psb_geaxpby(rs(k),v(k),zone,w1,desc_a,info)
|
||||
end do
|
||||
call prec%apply(w1,w,desc_a,info)
|
||||
call psb_geaxpby(zone,w,zone,x,desc_a,info)
|
||||
end if
|
||||
|
||||
end do restart
|
||||
if (itrace_ > 0) &
|
||||
& call log_conv(methdname,me,itx,ione,errnum,errden,deps)
|
||||
|
||||
call log_end(methdname,me,itx,itrace_,errnum,errden,deps,err=derr,iter=iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
|
||||
if (info == psb_success_) call psb_gefree(v,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w1,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(xt,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,h,c,s,rs,rst, stat=info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(err_act)
|
||||
return
|
||||
|
||||
end subroutine psb_zrgmres_vect
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! Salvatore Filippone
|
||||
! Alfredo Buttari
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions
|
||||
! are met:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 3. The name of the PSBLAS group or the names of its contributors may
|
||||
! not be used to endorse or promote products derived from this
|
||||
! software without specific written permission.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
! POSSIBILITY OF SUCH DAMAGE.
|
||||
!
|
||||
!
|
||||
!
|
||||
! File: psb_richardson_mod.f90
|
||||
! Interfaces for Richardson iterative methods.
|
||||
!
|
||||
!
|
||||
! Subroutine: psb_zrichardson
|
||||
!
|
||||
! Front-end for the Richardson iterations, complexversion
|
||||
!
|
||||
! Arguments:
|
||||
!
|
||||
! a - type(psb_zspmat_type) Input: sparse matrix containing A.
|
||||
! prec - class(psb_zprec_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(psb_desc_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|/(|a||x|+|b|)
|
||||
! 2: err = |r|/|b|
|
||||
! where r is the (preconditioned, recursive
|
||||
! estimate of) residual
|
||||
!
|
||||
Subroutine psb_zrichardson_vect(a,prec,b,x,eps,desc_a,info,&
|
||||
& itmax,iter,err,itrace,istop)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_z_linsolve_conv_mod
|
||||
use psb_linsolve_mod, psb_protect_name => psb_zrichardson_vect
|
||||
|
||||
Type(psb_zspmat_type), Intent(in) :: a
|
||||
Type(psb_desc_type), Intent(in) :: desc_a
|
||||
class(psb_zprec_type), intent(inout) :: prec
|
||||
type(psb_z_vect_type), Intent(inout) :: b
|
||||
type(psb_z_vect_type), Intent(inout) :: x
|
||||
Real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
Real(psb_dpk_), Optional, Intent(out) :: err
|
||||
|
||||
|
||||
logical :: do_alloc_wrk
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: me,np,err_act
|
||||
complex(psb_dpk_), allocatable, target :: aux(:)
|
||||
type(psb_z_vect_type), allocatable, target :: wwrk(:)
|
||||
type(psb_z_vect_type), pointer :: q, p, r, z, w
|
||||
real(psb_dpk_) :: derr
|
||||
integer(psb_ipk_) :: itmax_, istop_, naux, it, itx, itrace_,&
|
||||
& n_col, n_row,ieg,nspl, istebz
|
||||
integer(psb_lpk_) :: mglob
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
type(psb_itconv_type) :: stopdat
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='RICHARDSON'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_zrichardson'
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
|
||||
if (present(itrace)) then
|
||||
itrace_ = itrace
|
||||
else
|
||||
itrace_ = -1
|
||||
end if
|
||||
|
||||
if (present(istop)) then
|
||||
istop_ = istop
|
||||
else
|
||||
istop_ = 2
|
||||
endif
|
||||
if (present(itmax)) then
|
||||
itmax_ = itmax
|
||||
else
|
||||
itmax_ = 1000
|
||||
endif
|
||||
|
||||
do_alloc_wrk = .not.prec%is_allocated_wrk()
|
||||
if (do_alloc_wrk) call prec%allocate_wrk(info,vmold=x%v,desc=desc_a)
|
||||
|
||||
if (.not.allocated(b%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
if (.not.allocated(x%v)) then
|
||||
info = psb_err_invalid_vect_state_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
mglob = desc_a%get_global_rows()
|
||||
n_row = desc_a%get_local_rows()
|
||||
n_col = desc_a%get_local_cols()
|
||||
|
||||
call psb_chkvect(mglob,lone,x%get_nrows(),lone,lone,desc_a,info)
|
||||
if (info == psb_success_)&
|
||||
& call psb_chkvect(mglob,lone,b%get_nrows(),lone,lone,desc_a,info)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err='psb_chkvect on X/B')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
naux=4*n_col
|
||||
allocate(aux(naux), stat=info)
|
||||
if (info == psb_success_) call psb_geall(wwrk,desc_a,info,n=5_psb_ipk_)
|
||||
if (info == psb_success_) call psb_geasb(wwrk,desc_a,info,mold=x%v,scratch=.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
p => wwrk(1)
|
||||
q => wwrk(2)
|
||||
r => wwrk(3)
|
||||
z => wwrk(4)
|
||||
w => wwrk(5)
|
||||
|
||||
call psb_geaxpby(zone,b,zzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
|
||||
call psb_init_conv(methdname,istop_,itrace_,itmax_,a,x,b,eps,desc_a,stopdat,info)
|
||||
if (info /= psb_success_) Then
|
||||
call psb_errpush(psb_err_from_subroutine_non_,name)
|
||||
goto 9999
|
||||
End If
|
||||
|
||||
loop: do itx=1,itmax_
|
||||
call prec%apply(r,z,desc_a,info,work=aux)
|
||||
call psb_geaxpby(zone,z,zone,x,desc_a,info)
|
||||
call psb_geaxpby(zone,b,zzero,r,desc_a,info)
|
||||
if (info == psb_success_) call psb_spmm(-zone,a,x,zone,r,desc_a,info,work=aux)
|
||||
if (psb_check_conv(methdname,itx,x,r,desc_a,stopdat,info)) exit loop
|
||||
end do loop
|
||||
call psb_end_conv(methdname,itx,desc_a,stopdat,info,derr,iter)
|
||||
if (present(err)) err = derr
|
||||
|
||||
if (info == psb_success_) call psb_gefree(wwrk,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,stat=info)
|
||||
if ((info==psb_success_).and.do_alloc_wrk) call prec%free_wrk(info)
|
||||
|
||||
if(info /= psb_success_) then
|
||||
info = psb_err_from_subroutine_
|
||||
call psb_errpush(info,name,a_err=trim(methdname))
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
|
||||
end subroutine psb_zrichardson_vect
|
||||
|
||||
Reference in New Issue
Block a user