Done SERIAL
parent
8633e76cb0
commit
6987582c30
@ -0,0 +1,76 @@
|
||||
!
|
||||
! Subroutine: psb_dqrfact
|
||||
! Computes QR factorization of a multivector
|
||||
!
|
||||
! Arguments:
|
||||
! x - type(psb_d_multivect_type) The input multivector containing the entries of X
|
||||
! desc_a - type(psb_desc_type) The communication descriptor.
|
||||
! info - integer Return code
|
||||
!
|
||||
! Note: from a functional point of view, X is input, but here
|
||||
! it's declared INOUT because of the sync() methods.
|
||||
!
|
||||
function psb_dqrfact(x, desc_a, info) result(res)
|
||||
use psb_base_mod, psb_protect_name => psb_dqrfact
|
||||
implicit none
|
||||
real(psb_dpk_), allocatable :: res(:,:)
|
||||
type(psb_d_multivect_type), intent(inout) :: x
|
||||
type(psb_desc_type), intent(in) :: desc_a
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
|
||||
! locals
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me, err_act, iix, jjx
|
||||
integer(psb_lpk_) :: ix, ijx, x_m, x_n
|
||||
character(len=20) :: name, ch_err
|
||||
|
||||
name='psb_dgqrfact'
|
||||
if (psb_errstatus_fatal()) return
|
||||
info=psb_success_
|
||||
call psb_erractionsave(err_act)
|
||||
|
||||
ctxt=desc_a%get_context()
|
||||
|
||||
call psb_info(ctxt, me, np)
|
||||
if (np == -ione) then
|
||||
info = psb_err_context_error_
|
||||
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
|
||||
|
||||
ix = ione
|
||||
ijx = ione
|
||||
|
||||
x_m = x%get_nrows()
|
||||
x_n = x%get_ncols()
|
||||
|
||||
call psb_chkvect(x_m,x_n,x%get_nrows(),ix,ijx,desc_a,info,iix,jjx)
|
||||
if(info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_
|
||||
ch_err='psb_chkvect'
|
||||
call psb_errpush(info,name,a_err=ch_err)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
if (iix /= ione) then
|
||||
info=psb_err_ix_n1_iy_n1_unsupported_
|
||||
call psb_errpush(info,name)
|
||||
end if
|
||||
|
||||
if(desc_a%get_local_rows() > 0) then
|
||||
allocate(res(x_n,x_n))
|
||||
call x%qr_fact(res, info)
|
||||
end if
|
||||
|
||||
call psb_erractionrestore(err_act)
|
||||
return
|
||||
|
||||
9999 call psb_error_handler(ctxt,err_act)
|
||||
|
||||
return
|
||||
end function psb_dqrfact
|
@ -0,0 +1,383 @@
|
||||
! File: psb_dbgmres.f90
|
||||
!
|
||||
! Subroutine: psb_dbgmres
|
||||
! This subroutine implements the BGMRES 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
|
||||
! itrs - integer(optional) Input: iteration number parameter
|
||||
! 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_dbgmres_multivect(a, prec, b, x, eps, desc_a, info, itmax, iter, err, itrace, itrs, istop)
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_d_krylov_conv_mod
|
||||
use psb_krylov_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_multivect_type), Intent(inout) :: b
|
||||
type(psb_d_multivect_type), Intent(inout) :: x
|
||||
|
||||
real(psb_dpk_), Intent(in) :: eps
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
integer(psb_ipk_), Optional, Intent(in) :: itmax, itrace, itrs, istop
|
||||
integer(psb_ipk_), Optional, Intent(out) :: iter
|
||||
real(psb_dpk_), Optional, Intent(out) :: err
|
||||
|
||||
real(psb_dpk_), allocatable :: aux(:), h(:,:), beta(:,:)
|
||||
|
||||
type(psb_d_multivect_type), allocatable :: v(:)
|
||||
type(psb_d_multivect_type) :: v_tot, w
|
||||
|
||||
real(psb_dpk_) :: t1, t2
|
||||
|
||||
real(psb_dpk_) :: rti, rti1
|
||||
integer(psb_ipk_) :: litmax, naux, itrace_, n_row, n_col, nrep
|
||||
integer(psb_lpk_) :: mglob, m, n, n_add
|
||||
integer(psb_ipk_) :: n_
|
||||
|
||||
integer(psb_ipk_) :: i, j, istop_, err_act, idx_i, idx_j, idx
|
||||
integer(psb_ipk_) :: debug_level, debug_unit
|
||||
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: np, me, itx
|
||||
real(psb_dpk_) :: rni, xni, bni, ani, bn2, r0n2
|
||||
real(psb_dpk_) :: errnum, errden, deps, derr
|
||||
character(len=20) :: name
|
||||
character(len=*), parameter :: methdname='BGMRES'
|
||||
|
||||
info = psb_success_
|
||||
name = 'psb_dbgmres'
|
||||
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
|
||||
|
||||
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(itrs)) then
|
||||
nrep = itrs
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' present: itrs: ',itrs,nrep
|
||||
else
|
||||
nrep = 10
|
||||
if (debug_level >= psb_debug_ext_) &
|
||||
& write(debug_unit,*) me,' ',trim(name),&
|
||||
& ' not present: itrs: ',itrs,nrep
|
||||
endif
|
||||
if (nrep <=0 ) then
|
||||
info=psb_err_invalid_irst_
|
||||
err=info
|
||||
call psb_errpush(info,name,i_err=(/nrep/))
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
m = x%get_nrows()
|
||||
n = x%get_ncols()
|
||||
|
||||
call psb_chkvect(m,n,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(m,n,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((nrep+1)*n,nrep*n),stat=info)
|
||||
|
||||
n_ = n
|
||||
if (info == psb_success_) call psb_geall(v,desc_a,info,m=nrep+1,n=n_)
|
||||
if (info == psb_success_) call psb_geall(v_tot,desc_a,info,n=(nrep+1)*n_)
|
||||
if (info == psb_success_) call psb_geall(w,desc_a,info,n=n_)
|
||||
if (info == psb_success_) call psb_geasb(v,desc_a,info,mold=x%v,n=n_)
|
||||
if (info == psb_success_) call psb_geasb(v_tot,desc_a,info,mold=x%v,n=(nrep+1)*n_)
|
||||
if (info == psb_success_) call psb_geasb(w,desc_a,info,mold=x%v,n=n_)
|
||||
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 ',v(1)%get_nrows(),size(v),&
|
||||
& w%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)
|
||||
endif
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
errnum = dzero
|
||||
errden = done
|
||||
deps = eps
|
||||
itx = 0
|
||||
n_add = n-1
|
||||
|
||||
if ((itrace_ > 0).and.(me == psb_root_)) call log_header(methdname)
|
||||
|
||||
! BGMRES algorithm
|
||||
|
||||
! TODO inserire timer operazioni tra mlv
|
||||
|
||||
! STEP 1: Compute R(0) = B - A*X(0)
|
||||
|
||||
! Store B in V(1)
|
||||
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
|
||||
|
||||
! Store R(0) in V(1)
|
||||
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
|
||||
|
||||
! STEP 2: Compute QR_fact(R(0))
|
||||
beta = psb_geqrfact(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
|
||||
|
||||
! STEP 3: Outer loop
|
||||
outer: do j=1,nrep
|
||||
|
||||
itx = itx + 1
|
||||
|
||||
! Compute j index for H operations
|
||||
idx_j = (j-1)*n+1
|
||||
|
||||
! STEP 4: Compute W = AV(j)
|
||||
call psb_spmm(done,a,v(j),dzero,w,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 (itx >= litmax) exit outer
|
||||
|
||||
! STEP 5: Inner loop
|
||||
inner: do i=1,j
|
||||
|
||||
! Compute i index for H operations
|
||||
idx_i = (i-1)*n+1
|
||||
|
||||
! STEP 6: Compute H(i,j) = V(i)_T*W
|
||||
h(idx_i:idx_i+n_add,idx_j:idx_j+n_add) = psb_gedot(v(i),w,desc_a,info,.true.)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
! STEP 7: Compute W = W - V(i)*H(i,j)
|
||||
call psb_geaxpby(-done,psb_gedot(v(i),h(idx_i:idx_i+n_add,idx_j:idx_j+n_add),desc_a,info),done,w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
end do inner
|
||||
|
||||
! STEP 8: Compute QR_fact(W)
|
||||
|
||||
! Store R in H(j+1,j)
|
||||
h(idx_j+n:idx_j+n+n_add,idx_j:idx_j+n_add) = psb_geqrfact(w,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
! Store Q in V(j+1)
|
||||
call psb_geaxpby(done,w,dzero,v(j+1),desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
end do outer
|
||||
|
||||
! STEP 9: Compute Y(m)
|
||||
call frobenius_norm_min()
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
! STEP 10: Compute V = {V(1),...,V(m)}
|
||||
do i=1,nrep+1
|
||||
idx = (i-1)*n+1
|
||||
v_tot%v%v(:,idx:idx+n_add) = v(i)%v%v(:,1:n)
|
||||
enddo
|
||||
|
||||
! STEP 11: X(m) = X(0) + V*Y(m)
|
||||
call psb_geaxpby(done,psb_gedot(v_tot,h,desc_a,info),done,x,desc_a,info)
|
||||
if (info /= psb_success_) then
|
||||
info=psb_err_from_subroutine_non_
|
||||
call psb_errpush(info,name)
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
! END algorithm
|
||||
|
||||
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(v_tot,desc_a,info)
|
||||
if (info == psb_success_) call psb_gefree(w,desc_a,info)
|
||||
if (info == psb_success_) deallocate(aux,h,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
|
||||
|
||||
contains
|
||||
|
||||
! Minimize Frobenius norm
|
||||
subroutine frobenius_norm_min()
|
||||
|
||||
implicit none
|
||||
|
||||
integer(psb_ipk_) :: lwork
|
||||
real(psb_dpk_), allocatable :: work(:), beta_e1(:,:)
|
||||
|
||||
integer(psb_ipk_) :: m_h, n_h, mn
|
||||
|
||||
! Initialize params
|
||||
m_h = (nrep+1)*n
|
||||
n_h = nrep*n
|
||||
mn = min(m_h,n_h)
|
||||
lwork = max(1,mn+max(mn,n))
|
||||
allocate(work(lwork))
|
||||
|
||||
! Compute E1*beta
|
||||
allocate(beta_e1(m_h,n))
|
||||
beta_e1 = dzero
|
||||
beta_e1(1:n,1:n) = beta
|
||||
|
||||
! Compute min Frobenius norm
|
||||
call dgels('N',m_h,n_h,n,h,m_h,beta_e1,m_h,work,lwork,info)
|
||||
|
||||
deallocate(work,beta_e1)
|
||||
|
||||
return
|
||||
|
||||
end subroutine frobenius_norm_min
|
||||
|
||||
end subroutine psb_dbgmres_multivect
|
@ -0,0 +1,40 @@
|
||||
INSTALLDIR=../..
|
||||
INCDIR=$(INSTALLDIR)/include/
|
||||
MODDIR=$(INSTALLDIR)/modules/
|
||||
include $(INCDIR)/Make.inc.psblas
|
||||
#
|
||||
# Libraries used
|
||||
#
|
||||
LIBDIR=$(INSTALLDIR)/lib/
|
||||
PSBLAS_LIB= -L$(LIBDIR) -lpsb_util -lpsb_krylov -lpsb_prec -lpsb_base
|
||||
LDLIBS=$(PSBLDLIBS)
|
||||
|
||||
FINCLUDES=$(FMFLAG)$(MODDIR) $(FMFLAG).
|
||||
|
||||
DBFOBJS=getp.o psb_dbf_sample.o
|
||||
|
||||
EXEDIR=./runs
|
||||
|
||||
all: runsd psb_dbf_sample
|
||||
|
||||
runsd:
|
||||
(if test ! -d runs ; then mkdir runs; fi)
|
||||
|
||||
psb_dbf_sample.o: getp.o
|
||||
|
||||
psb_dbf_sample: $(DBFOBJS)
|
||||
$(FLINK) $(LOPT) $(DBFOBJS) -o psb_dbf_sample $(PSBLAS_LIB) $(LDLIBS)
|
||||
/bin/mv psb_dbf_sample $(EXEDIR)
|
||||
|
||||
.f90.o:
|
||||
$(MPFC) $(FCOPT) $(FINCLUDES) $(FDEFINES) -c $<
|
||||
|
||||
clean:
|
||||
/bin/rm -f $(DBFOBJS)\
|
||||
*$(.mod) $(EXEDIR)/psb_*f_sample
|
||||
|
||||
lib:
|
||||
(cd ../../; make library)
|
||||
verycleanlib:
|
||||
(cd ../../; make veryclean)
|
||||
|
@ -0,0 +1,169 @@
|
||||
!
|
||||
! 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.
|
||||
!
|
||||
!
|
||||
Module getp
|
||||
interface get_parms
|
||||
module procedure get_dparms
|
||||
end interface
|
||||
|
||||
contains
|
||||
!
|
||||
! Get iteration parameters from the command line
|
||||
!
|
||||
subroutine get_dparms(ctxt,mtrx_file,rhs_file,filefmt,kmethd,ptype,part,&
|
||||
& afmt,nrhs,istopc,itmax,itrace,itrs,eps)
|
||||
use psb_base_mod
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
character(len=2) :: filefmt
|
||||
character(len=40) :: kmethd, mtrx_file, rhs_file, ptype
|
||||
character(len=20) :: part
|
||||
integer(psb_ipk_) :: nrhs,iret,istopc,itmax,itrace,itrs
|
||||
character(len=40) :: charbuf
|
||||
real(psb_dpk_) :: eps
|
||||
character :: afmt*5
|
||||
integer(psb_ipk_) :: np, iam
|
||||
integer(psb_ipk_) :: inparms(40), ip, inp_unit
|
||||
character(len=1024) :: filename
|
||||
|
||||
call psb_info(ctxt,iam,np)
|
||||
if (iam == 0) then
|
||||
if (command_argument_count()>0) then
|
||||
call get_command_argument(1,filename)
|
||||
inp_unit = 30
|
||||
open(inp_unit,file=filename,action='read',iostat=info)
|
||||
if (info /= 0) then
|
||||
write(psb_err_unit,*) 'Could not open file ',filename,' for input'
|
||||
call psb_abort(ctxt)
|
||||
stop
|
||||
else
|
||||
write(psb_err_unit,*) 'Opened file ',trim(filename),' for input'
|
||||
end if
|
||||
else
|
||||
inp_unit=psb_inp_unit
|
||||
end if
|
||||
! Read Input Parameters
|
||||
read(inp_unit,*) ip
|
||||
if (ip >= 5) then
|
||||
read(inp_unit,*) mtrx_file
|
||||
read(inp_unit,*) rhs_file
|
||||
read(inp_unit,*) filefmt
|
||||
read(inp_unit,*) kmethd
|
||||
read(inp_unit,*) ptype
|
||||
read(inp_unit,*) afmt
|
||||
read(inp_unit,*) part
|
||||
|
||||
call psb_bcast(ctxt,mtrx_file)
|
||||
call psb_bcast(ctxt,rhs_file)
|
||||
call psb_bcast(ctxt,filefmt)
|
||||
call psb_bcast(ctxt,kmethd)
|
||||
call psb_bcast(ctxt,ptype)
|
||||
call psb_bcast(ctxt,afmt)
|
||||
call psb_bcast(ctxt,part)
|
||||
|
||||
if (ip >= 7) then
|
||||
read(inp_unit,*) nrhs
|
||||
else
|
||||
nrhs=4
|
||||
endif
|
||||
if (ip >= 8) then
|
||||
read(inp_unit,*) istopc
|
||||
else
|
||||
istopc=1
|
||||
endif
|
||||
if (ip >= 9) then
|
||||
read(inp_unit,*) itmax
|
||||
else
|
||||
itmax=500
|
||||
endif
|
||||
if (ip >= 10) then
|
||||
read(inp_unit,*) itrace
|
||||
else
|
||||
itrace=-1
|
||||
endif
|
||||
if (ip >= 11) then
|
||||
read(inp_unit,*) itrs
|
||||
else
|
||||
itrs = 1
|
||||
endif
|
||||
if (ip >= 12) then
|
||||
read(inp_unit,*) eps
|
||||
else
|
||||
eps=1.d-6
|
||||
endif
|
||||
inparms(1) = nrhs
|
||||
inparms(2) = istopc
|
||||
inparms(3) = itmax
|
||||
inparms(4) = itrace
|
||||
inparms(5) = itrs
|
||||
call psb_bcast(ctxt,inparms(1:5))
|
||||
call psb_bcast(ctxt,eps)
|
||||
|
||||
write(psb_out_unit,'(" ")')
|
||||
write(psb_out_unit,'("Solving matrix : ",a)') mtrx_file
|
||||
write(psb_out_unit,'("Number of processors : ",i1)') np
|
||||
write(psb_out_unit,'("Data distribution : ",a)') part
|
||||
write(psb_out_unit,'("Iterative method : ",a)') kmethd
|
||||
write(psb_out_unit,'("Preconditioner : ",a)') ptype
|
||||
write(psb_out_unit,'("Number of RHS : ",i1)') nrhs
|
||||
write(psb_out_unit,'("Number of iterations : ",i1)') itrs
|
||||
write(psb_out_unit,'("Storage format : ",a)') afmt(1:3)
|
||||
write(psb_out_unit,'(" ")')
|
||||
else
|
||||
write(psb_err_unit,*) 'Wrong format for input file'
|
||||
call psb_abort(ctxt)
|
||||
stop 1
|
||||
end if
|
||||
if (inp_unit /= psb_inp_unit) then
|
||||
close(inp_unit)
|
||||
end if
|
||||
else
|
||||
! Receive Parameters
|
||||
call psb_bcast(ctxt,mtrx_file)
|
||||
call psb_bcast(ctxt,rhs_file)
|
||||
call psb_bcast(ctxt,filefmt)
|
||||
call psb_bcast(ctxt,kmethd)
|
||||
call psb_bcast(ctxt,ptype)
|
||||
call psb_bcast(ctxt,afmt)
|
||||
call psb_bcast(ctxt,part)
|
||||
|
||||
call psb_bcast(ctxt,inparms(1:5))
|
||||
nrhs = inparms(1)
|
||||
istopc = inparms(2)
|
||||
itmax = inparms(3)
|
||||
itrace = inparms(4)
|
||||
itrs = inparms(5)
|
||||
call psb_bcast(ctxt,eps)
|
||||
|
||||
end if
|
||||
|
||||
end subroutine get_dparms
|
||||
|
||||
end module getp
|
@ -0,0 +1,265 @@
|
||||
program psb_dbf_sample
|
||||
|
||||
use psb_base_mod
|
||||
use psb_prec_mod
|
||||
use psb_krylov_mod
|
||||
use psb_util_mod
|
||||
use getp
|
||||
|
||||
implicit none
|
||||
|
||||
! input parameters
|
||||
character(len=40) :: kmethd, ptype, mtrx_file, rhs_file
|
||||
|
||||
! sparse matrices
|
||||
type(psb_dspmat_type) :: a
|
||||
type(psb_ldspmat_type) :: aux_a
|
||||
|
||||
! preconditioner data
|
||||
type(psb_dprec_type) :: prec
|
||||
|
||||
! dense matrices
|
||||
real(psb_dpk_), allocatable, target :: aux_b(:,:)
|
||||
real(psb_dpk_), allocatable, save :: x_mv_glob(:,:), r_mv_glob(:,:)
|
||||
real(psb_dpk_), pointer :: b_mv_glob(:,:)
|
||||
type(psb_d_multivect_type) :: b_mv, x_mv, r_mv
|
||||
integer(psb_ipk_) :: m, nrhs
|
||||
real(psb_dpk_) :: random_value
|
||||
|
||||
! communications data structure
|
||||
type(psb_desc_type) :: desc_a
|
||||
type(psb_ctxt_type) :: ctxt
|
||||
integer(psb_ipk_) :: iam, np
|
||||
integer(psb_lpk_) :: lnp
|
||||
|
||||
! solver paramters
|
||||
integer(psb_ipk_) :: iter, itmax, ierr, itrace, ircode, methd, istopc, itrs
|
||||
integer(psb_epk_) :: amatsize, precsize, descsize
|
||||
real(psb_dpk_) :: err, eps
|
||||
|
||||
! input parameters
|
||||
character(len=5) :: afmt
|
||||
character(len=20) :: name, part
|
||||
character(len=2) :: filefmt
|
||||
integer(psb_ipk_), parameter :: iunit=12
|
||||
|
||||
! other variables
|
||||
integer(psb_ipk_) :: i, j, info
|
||||
real(psb_dpk_) :: t1, t2, tprec
|
||||
real(psb_dpk_) :: resmx, resmxp
|
||||
integer(psb_ipk_), allocatable :: ivg(:)
|
||||
|
||||
call psb_init(ctxt)
|
||||
call psb_info(ctxt,iam,np)
|
||||
|
||||
if (iam < 0) then
|
||||
! This should not happen, but just in case
|
||||
call psb_exit(ctxt)
|
||||
stop
|
||||
endif
|
||||
|
||||
name='psb_dbf_sample'
|
||||
if(psb_errstatus_fatal()) goto 9999
|
||||
info=psb_success_
|
||||
call psb_set_errverbosity(itwo)
|
||||
!
|
||||
! Hello world
|
||||
!
|
||||
if (iam == psb_root_) then
|
||||
write(psb_out_unit,'(" ")')
|
||||
write(psb_out_unit,'("Welcome to PSBLAS version: ",a)') psb_version_string_
|
||||
write(psb_out_unit,'("This is the ",a," sample program")') trim(name)
|
||||
write(psb_out_unit,'(" ")')
|
||||
end if
|
||||
!
|
||||
! get parameters
|
||||
!
|
||||
call get_parms(ctxt,mtrx_file,rhs_file,filefmt,kmethd,ptype,&
|
||||
& part,afmt,nrhs,istopc,itmax,itrace,itrs,eps)
|
||||
|
||||
call psb_barrier(ctxt)
|
||||
t1 = psb_wtime()
|
||||
|
||||
if (iam == psb_root_) then
|
||||
select case(psb_toupper(filefmt))
|
||||
case('MM')
|
||||
! For Matrix Market we have an input file for the matrix
|
||||
! and an (optional) second file for the RHS.
|
||||
call mm_mat_read(aux_a,info,iunit=iunit,filename=mtrx_file)
|
||||
if (info == psb_success_) then
|
||||
if (rhs_file /= 'NONE') then
|
||||
call mm_array_read(aux_b,info,iunit=iunit,filename=rhs_file)
|
||||
end if
|
||||
end if
|
||||
|
||||
case ('HB')
|
||||
! For Harwell-Boeing we have a single file which may or may not
|
||||
! contain an RHS.
|
||||
call hb_read(aux_a,info,iunit=iunit,b=aux_b,filename=mtrx_file)
|
||||
|
||||
case default
|
||||
info = -1
|
||||
write(psb_err_unit,*) 'Wrong choice for fileformat ', filefmt
|
||||
end select
|
||||
|
||||
if (info /= psb_success_) then
|
||||
write(psb_err_unit,*) 'Error while reading input matrix '
|
||||
call psb_abort(ctxt)
|
||||
end if
|
||||
|
||||
m = aux_a%get_nrows()
|
||||
call psb_bcast(ctxt,m)
|
||||
|
||||
! At this point aux_b may still be unallocated
|
||||
if (size(aux_b) == m*nrhs) then
|
||||
! if any rhs were present, broadcast the first one
|
||||
write(psb_err_unit,'("Ok, got an rhs ")')
|
||||
b_mv_glob =>aux_b(:,:)
|
||||
else
|
||||
write(psb_out_unit,'("Generating an rhs...")')
|
||||
write(psb_out_unit,'("Number of RHS: ",i1)') nrhs
|
||||
write(psb_out_unit,'(" ")')
|
||||
call psb_realloc(m,nrhs,aux_b,ircode)
|
||||
if (ircode /= 0) then
|
||||
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||||
goto 9999
|
||||
endif
|
||||
|
||||
b_mv_glob => aux_b(:,:)
|
||||
do i=1, m
|
||||
do j=1, nrhs
|
||||
!b_mv_glob(i,j) = done
|
||||
call random_number(random_value)
|
||||
b_mv_glob(i,j) = random_value
|
||||
enddo
|
||||
enddo
|
||||
endif
|
||||
|
||||
else
|
||||
call psb_bcast(ctxt,m)
|
||||
|
||||
end if
|
||||
|
||||
! switch over different partition types
|
||||
select case(psb_toupper(part))
|
||||
case('BLOCK')
|
||||
if (iam == psb_root_) write(psb_out_unit,'("Partition type: block")')
|
||||
call psb_matdist(aux_a,a,ctxt,desc_a,info,fmt=afmt,parts=part_block)
|
||||
|
||||
case('GRAPH')
|
||||
if (iam == psb_root_) then
|
||||
write(psb_out_unit,'("Partition type: graph vector")')
|
||||
write(psb_out_unit,'(" ")')
|
||||
call aux_a%cscnv(info,type='csr')
|
||||
lnp = np
|
||||
call build_mtpart(aux_a,lnp)
|
||||
|
||||
endif
|
||||
call psb_barrier(ctxt)
|
||||
call distr_mtpart(psb_root_,ctxt)
|
||||
call getv_mtpart(ivg)
|
||||
call psb_matdist(aux_a,a,ctxt,desc_a,info,fmt=afmt,vg=ivg)
|
||||
|
||||
case default
|
||||
if (iam == psb_root_) write(psb_out_unit,'("Partition type: block")')
|
||||
call psb_matdist(aux_a,a,ctxt,desc_a,info,fmt=afmt,parts=part_block)
|
||||
end select
|
||||
|
||||
call psb_scatter(b_mv_glob,b_mv,desc_a,info,root=psb_root_)
|
||||
call psb_geall(x_mv,desc_a,info,nrhs)
|
||||
call x_mv%zero()
|
||||
call psb_geasb(x_mv,desc_a,info)
|
||||
call psb_geall(r_mv,desc_a,info,nrhs)
|
||||
call r_mv%zero()
|
||||
call psb_geasb(r_mv,desc_a,info)
|
||||
|
||||
t2 = psb_wtime() - t1
|
||||
call psb_amx(ctxt, t2)
|
||||
|
||||
if (iam == psb_root_) then
|
||||
write(psb_out_unit,'(" ")')
|
||||
write(psb_out_unit,'("Time to read and partition matrix : ",es12.5)')t2
|
||||
write(psb_out_unit,'(" ")')
|
||||
end if
|
||||
|
||||
! building the preconditioner
|
||||
call prec%init(ctxt,ptype,info)
|
||||
t1 = psb_wtime()
|
||||
call prec%build(a,desc_a,info)
|
||||
tprec = psb_wtime()-t1
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_,name,a_err='psb_precbld')
|
||||
goto 9999
|
||||
end if
|
||||
|
||||
call psb_amx(ctxt,tprec)
|
||||
|
||||
if(iam == psb_root_) then
|
||||
write(psb_out_unit,'("Preconditioner time: ",es12.5)')tprec
|
||||
write(psb_out_unit,'(" ")')
|
||||
end if
|
||||
|
||||
call psb_barrier(ctxt)
|
||||
t1 = psb_wtime()
|
||||
call psb_krylov(kmethd,a,prec,b_mv,x_mv,eps,desc_a,info,&
|
||||
& itmax=itmax,iter=iter,err=err,itrace=itrace,&
|
||||
& itrs=itrs,istop=istopc)
|
||||
call psb_barrier(ctxt)
|
||||
t2 = psb_wtime() - t1
|
||||
call psb_amx(ctxt,t2)
|
||||
call psb_geaxpby(done,b_mv,dzero,r_mv,desc_a,info)
|
||||
call psb_spmm(-done,a,x_mv,done,r_mv,desc_a,info)
|
||||
|
||||
resmx = psb_genrm2(r_mv,desc_a,info)
|
||||
resmxp = psb_geamax(r_mv,desc_a,info)
|
||||
|
||||
amatsize = a%sizeof()
|
||||
descsize = desc_a%sizeof()
|
||||
precsize = prec%sizeof()
|
||||
|
||||
call psb_sum(ctxt,amatsize)
|
||||
call psb_sum(ctxt,descsize)
|
||||
call psb_sum(ctxt,precsize)
|
||||
|
||||
if (iam == psb_root_) then
|
||||
call prec%descr(info)
|
||||
write(psb_out_unit,'(" ")')
|
||||
write(psb_out_unit,'("Computed solution on: ",i8," processors")')np
|
||||
write(psb_out_unit,'("Matrix: ",a)')mtrx_file
|
||||
write(psb_out_unit,'("Storage format for A: ",a)')a%get_fmt()
|
||||
write(psb_out_unit,'("Storage format for DESC_A: ",a)')desc_a%get_fmt()
|
||||
write(psb_out_unit,'("Total memory occupation for A: ",i12)')amatsize
|
||||
write(psb_out_unit,'("Total memory occupation for PREC: ",i12)')precsize
|
||||
write(psb_out_unit,'("Total memory occupation for DESC_A: ",i12)')descsize
|
||||
write(psb_out_unit,'("Iterations to convergence: ",i12)')iter
|
||||
write(psb_out_unit,'("Error estimate on exit: ",es12.5)')err
|
||||
write(psb_out_unit,'("Time to buil prec.: ",es12.5)')tprec
|
||||
write(psb_out_unit,'("Time to solve system: ",es12.5)')t2
|
||||
write(psb_out_unit,'("Time per iteration: ",es12.5)')t2/(iter)
|
||||
write(psb_out_unit,'("Total time: ",es12.5)')t2+tprec
|
||||
write(psb_out_unit,'("Residual norm 2: ",es12.5)')resmx
|
||||
write(psb_out_unit,'("Residual norm inf: ",es12.5)')resmxp
|
||||
write(psb_out_unit,'(" ")')
|
||||
end if
|
||||
|
||||
call psb_gather(x_mv_glob,x_mv,desc_a,info,root=psb_root_)
|
||||
if (info == psb_success_) call psb_gather(r_mv_glob,r_mv,desc_a,info,root=psb_root_)
|
||||
if (info /= psb_success_) goto 9999
|
||||
|
||||
998 format(i8,4(2x,g20.14))
|
||||
993 format(i6,4(1x,e12.6))
|
||||
|
||||
call psb_gefree(b_mv, desc_a,info)
|
||||
call psb_gefree(x_mv, desc_a,info)
|
||||
call psb_spfree(a, desc_a,info)
|
||||
call prec%free(info)
|
||||
call psb_cdfree(desc_a,info)
|
||||
call psb_exit(ctxt)
|
||||
|
||||
return
|
||||
|
||||
9999 call psb_error(ctxt)
|
||||
|
||||
return
|
||||
|
||||
end program psb_dbf_sample
|
Loading…
Reference in New Issue