You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
415 lines
14 KiB
Fortran
415 lines
14 KiB
Fortran
8 years ago
|
!
|
||
|
!
|
||
7 years ago
|
! MLD2P4 version 2.2
|
||
8 years ago
|
! MultiLevel Domain Decomposition Parallel Preconditioners Package
|
||
8 years ago
|
! based on PSBLAS (Parallel Sparse BLAS version 3.5)
|
||
8 years ago
|
!
|
||
7 years ago
|
! (C) Copyright 2008-2018
|
||
8 years ago
|
!
|
||
7 years ago
|
! Salvatore Filippone
|
||
|
! Pasqua D'Ambra
|
||
|
! Daniela di Serafino
|
||
8 years ago
|
!
|
||
|
! 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 MLD2P4 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 MLD2P4 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.
|
||
|
!
|
||
|
!
|
||
6 years ago
|
! File: mld_saggrmat_smth_bld.F90
|
||
17 years ago
|
!
|
||
6 years ago
|
! Subroutine: mld_saggrmat_smth_bld
|
||
17 years ago
|
! Version: real
|
||
|
!
|
||
|
! This routine builds a coarse-level matrix A_C from a fine-level matrix A
|
||
16 years ago
|
! by using the Galerkin approach, i.e.
|
||
17 years ago
|
!
|
||
|
! A_C = P_C^T A P_C,
|
||
|
!
|
||
|
! where P_C is a prolongator from the coarse level to the fine one.
|
||
|
!
|
||
|
! The prolongator P_C is built according to a smoothed aggregation algorithm,
|
||
|
! i.e. it is obtained by applying a damped Jacobi smoother to the piecewise
|
||
|
! constant interpolation operator P corresponding to the fine-to-coarse level
|
||
|
! mapping built by the mld_aggrmap_bld subroutine:
|
||
|
!
|
||
|
! P_C = (I - omega*D^(-1)A) * P,
|
||
|
!
|
||
|
! where D is the diagonal matrix with main diagonal equal to the main diagonal
|
||
|
! of A, and omega is a suitable smoothing parameter. An estimate of the spectral
|
||
|
! radius of D^(-1)A, to be used in the computation of omega, is provided,
|
||
14 years ago
|
! according to the value of p%parms%aggr_omega_alg, specified by the user
|
||
13 years ago
|
! through mld_sprecinit and mld_zprecset.
|
||
17 years ago
|
!
|
||
|
! The coarse-level matrix A_C is distributed among the parallel processes or
|
||
14 years ago
|
! replicated on each of them, according to the value of p%parms%coarse_mat,
|
||
13 years ago
|
! specified by the user through mld_sprecinit and mld_zprecset.
|
||
8 years ago
|
! On output from this routine the entries of AC, op_prol, op_restr
|
||
|
! are still in "global numbering" mode; this is fixed in the calling routine
|
||
6 years ago
|
! aggregator%mat_bld.
|
||
17 years ago
|
!
|
||
8 years ago
|
!
|
||
17 years ago
|
! Arguments:
|
||
|
! a - type(psb_sspmat_type), input.
|
||
|
! The sparse matrix structure containing the local part of
|
||
|
! the fine-level matrix.
|
||
|
! desc_a - type(psb_desc_type), input.
|
||
|
! The communication descriptor of the fine-level matrix.
|
||
13 years ago
|
! p - type(mld_s_onelev_type), input/output.
|
||
16 years ago
|
! The 'one-level' data structure that will contain the local
|
||
8 years ago
|
! part of the matrix to be built as well as the information
|
||
16 years ago
|
! concerning the prolongator and its transpose.
|
||
8 years ago
|
! parms - type(mld_sml_parms), input
|
||
|
! Parameters controlling the choice of algorithm
|
||
|
! ac - type(psb_sspmat_type), output
|
||
|
! The coarse matrix on output
|
||
|
!
|
||
|
! ilaggr - integer, dimension(:), input
|
||
16 years ago
|
! The mapping between the row indices of the coarse-level
|
||
|
! matrix and the row indices of the fine-level matrix.
|
||
|
! ilaggr(i)=j means that node i in the adjacency graph
|
||
|
! of the fine-level matrix is mapped onto node j in the
|
||
8 years ago
|
! adjacency graph of the coarse-level matrix. Note that the indices
|
||
|
! are assumed to be shifted so as to make sure the ranges on
|
||
|
! the various processes do not overlap.
|
||
|
! nlaggr - integer, dimension(:) input
|
||
16 years ago
|
! nlaggr(i) contains the aggregates held by process i.
|
||
8 years ago
|
! op_prol - type(psb_sspmat_type), input/output
|
||
|
! The tentative prolongator on input, the computed prolongator on output
|
||
|
!
|
||
|
! op_restr - type(psb_sspmat_type), output
|
||
|
! The restrictor operator; normally, it is the transpose of the prolongator.
|
||
|
!
|
||
17 years ago
|
! info - integer, output.
|
||
|
! Error code.
|
||
|
!
|
||
6 years ago
|
subroutine mld_saggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_restr,info)
|
||
14 years ago
|
use psb_base_mod
|
||
8 years ago
|
use mld_base_prec_type
|
||
6 years ago
|
use mld_s_inner_mod, mld_protect_name => mld_saggrmat_smth_bld
|
||
17 years ago
|
|
||
|
implicit none
|
||
|
|
||
17 years ago
|
! Arguments
|
||
7 years ago
|
type(psb_sspmat_type), intent(in) :: a
|
||
|
type(psb_desc_type), intent(in) :: desc_a
|
||
|
integer(psb_lpk_), intent(inout) :: ilaggr(:), nlaggr(:)
|
||
|
type(mld_sml_parms), intent(inout) :: parms
|
||
|
type(psb_lsspmat_type), intent(inout) :: op_prol
|
||
|
type(psb_lsspmat_type), intent(out) :: ac,op_restr
|
||
|
integer(psb_ipk_), intent(out) :: info
|
||
17 years ago
|
|
||
17 years ago
|
! Local variables
|
||
7 years ago
|
integer(psb_lpk_) :: nrow, nglob, ncol, ntaggr, ip, &
|
||
7 years ago
|
& naggr, nzl,naggrm1,naggrp1, i, j, k, jd, icolF, nrw
|
||
7 years ago
|
integer(psb_ipk_) :: ictxt, np, me
|
||
17 years ago
|
character(len=20) :: name
|
||
7 years ago
|
type(psb_lsspmat_type) :: la, am3, am4, tmp_prol
|
||
|
type(psb_ls_coo_sparse_mat) :: tmpcoo
|
||
|
type(psb_ls_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde
|
||
17 years ago
|
real(psb_spk_), allocatable :: adiag(:)
|
||
13 years ago
|
integer(psb_ipk_) :: ierr(5)
|
||
13 years ago
|
logical :: filter_mat
|
||
7 years ago
|
integer(psb_ipk_) :: debug_level, debug_unit, err_act
|
||
12 years ago
|
integer(psb_ipk_), parameter :: ncmax=16
|
||
13 years ago
|
real(psb_spk_) :: anorm, omega, tmp, dg, theta
|
||
17 years ago
|
|
||
6 years ago
|
name='mld_aggrmat_smth_bld'
|
||
15 years ago
|
info=psb_success_
|
||
17 years ago
|
call psb_erractionsave(err_act)
|
||
7 years ago
|
if (psb_errstatus_fatal()) then
|
||
|
info = psb_err_internal_error_; goto 9999
|
||
|
end if
|
||
17 years ago
|
debug_unit = psb_get_debug_unit()
|
||
|
debug_level = psb_get_debug_level()
|
||
|
|
||
14 years ago
|
ictxt = desc_a%get_context()
|
||
17 years ago
|
|
||
|
call psb_info(ictxt, me, np)
|
||
|
|
||
14 years ago
|
nglob = desc_a%get_global_rows()
|
||
|
nrow = desc_a%get_local_rows()
|
||
|
ncol = desc_a%get_local_cols()
|
||
17 years ago
|
|
||
13 years ago
|
theta = parms%aggr_thresh
|
||
16 years ago
|
|
||
16 years ago
|
naggr = nlaggr(me+1)
|
||
|
ntaggr = sum(nlaggr)
|
||
17 years ago
|
|
||
16 years ago
|
naggrm1 = sum(nlaggr(1:me))
|
||
|
naggrp1 = sum(nlaggr(1:me+1))
|
||
13 years ago
|
filter_mat = (parms%aggr_filter == mld_filter_mat_)
|
||
16 years ago
|
|
||
8 years ago
|
!
|
||
17 years ago
|
! naggr: number of local aggregates
|
||
|
! nrow: local rows.
|
||
|
!
|
||
|
|
||
16 years ago
|
! Get the diagonal D
|
||
11 years ago
|
adiag = a%get_diag(info)
|
||
|
if (info == psb_success_) &
|
||
|
& call psb_realloc(ncol,adiag,info)
|
||
15 years ago
|
if (info == psb_success_) &
|
||
16 years ago
|
& call psb_halo(adiag,desc_a,info)
|
||
7 years ago
|
if (info == psb_success_) call a%cp_to_l(la)
|
||
16 years ago
|
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_from_subroutine_,name,a_err='sp_getdiag')
|
||
17 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
! 1. Allocate Ptilde in sparse matrix form
|
||
8 years ago
|
call op_prol%mv_to(tmpcoo)
|
||
13 years ago
|
call ptilde%mv_from_coo(tmpcoo,info)
|
||
7 years ago
|
if (info == psb_success_) call la%cscnv(acsr3,info,dupl=psb_dupl_add_)
|
||
8 years ago
|
if (info /= psb_success_) goto 9999
|
||
17 years ago
|
|
||
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
12 years ago
|
& ' Initial copies done.'
|
||
13 years ago
|
|
||
16 years ago
|
if (filter_mat) then
|
||
|
!
|
||
|
! Build the filtered matrix Af from A
|
||
|
!
|
||
11 years ago
|
if (info == psb_success_) call acsr3%cp_to_fmt(acsrf,info)
|
||
16 years ago
|
|
||
7 years ago
|
do i=1, nrow
|
||
16 years ago
|
tmp = szero
|
||
|
jd = -1
|
||
14 years ago
|
do j=acsrf%irp(i),acsrf%irp(i+1)-1
|
||
|
if (acsrf%ja(j) == i) jd = j
|
||
|
if (abs(acsrf%val(j)) < theta*sqrt(abs(adiag(i)*adiag(acsrf%ja(j))))) then
|
||
|
tmp=tmp+acsrf%val(j)
|
||
|
acsrf%val(j)=szero
|
||
16 years ago
|
endif
|
||
16 years ago
|
|
||
16 years ago
|
enddo
|
||
|
if (jd == -1) then
|
||
|
write(0,*) 'Wrong input: we need the diagonal!!!!', i
|
||
|
else
|
||
14 years ago
|
acsrf%val(jd)=acsrf%val(jd)-tmp
|
||
16 years ago
|
end if
|
||
16 years ago
|
enddo
|
||
16 years ago
|
! Take out zeroed terms
|
||
8 years ago
|
call acsrf%clean_zeros(info)
|
||
16 years ago
|
end if
|
||
16 years ago
|
|
||
|
|
||
|
do i=1,size(adiag)
|
||
|
if (adiag(i) /= szero) then
|
||
|
adiag(i) = sone / adiag(i)
|
||
|
else
|
||
|
adiag(i) = sone
|
||
|
end if
|
||
|
end do
|
||
16 years ago
|
|
||
14 years ago
|
if (filter_mat) call acsrf%scal(adiag,info)
|
||
|
if (info == psb_success_) call acsr3%scal(adiag,info)
|
||
15 years ago
|
if (info /= psb_success_) goto 9999
|
||
16 years ago
|
|
||
|
|
||
13 years ago
|
if (parms%aggr_omega_alg == mld_eig_est_) then
|
||
17 years ago
|
|
||
13 years ago
|
if (parms%aggr_eig == mld_max_norm_) then
|
||
17 years ago
|
|
||
12 years ago
|
anorm = acsr3%spnmi()
|
||
6 years ago
|
call psb_amx(ictxt,anorm)
|
||
17 years ago
|
omega = 4.d0/(3.d0*anorm)
|
||
13 years ago
|
parms%aggr_omega_val = omega
|
||
17 years ago
|
|
||
|
else
|
||
15 years ago
|
info = psb_err_internal_error_
|
||
17 years ago
|
call psb_errpush(info,name,a_err='invalid mld_aggr_eig_')
|
||
17 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
13 years ago
|
else if (parms%aggr_omega_alg == mld_user_choice_) then
|
||
17 years ago
|
|
||
13 years ago
|
omega = parms%aggr_omega_val
|
||
17 years ago
|
|
||
13 years ago
|
else if (parms%aggr_omega_alg /= mld_user_choice_) then
|
||
15 years ago
|
info = psb_err_internal_error_
|
||
17 years ago
|
call psb_errpush(info,name,a_err='invalid mld_aggr_omega_alg_')
|
||
17 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
16 years ago
|
if (filter_mat) then
|
||
|
!
|
||
|
! Build the smoothed prolongator using the filtered matrix
|
||
|
!
|
||
14 years ago
|
do i=1,acsrf%get_nrows()
|
||
|
do j=acsrf%irp(i),acsrf%irp(i+1)-1
|
||
|
if (acsrf%ja(j) == i) then
|
||
|
acsrf%val(j) = sone - omega*acsrf%val(j)
|
||
|
else
|
||
|
acsrf%val(j) = - omega*acsrf%val(j)
|
||
|
end if
|
||
17 years ago
|
end do
|
||
14 years ago
|
end do
|
||
17 years ago
|
|
||
16 years ago
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
11 years ago
|
& 'Done gather, going for SPSPMM 1'
|
||
16 years ago
|
!
|
||
|
!
|
||
14 years ago
|
! acsrm1 = (I-w*D*Af)Ptilde
|
||
16 years ago
|
! Doing it this way means to consider diag(Af_i)
|
||
|
!
|
||
|
!
|
||
11 years ago
|
call psb_spspmm(acsrf,ptilde,acsr1,info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
11 years ago
|
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
|
||
16 years ago
|
goto 9999
|
||
|
end if
|
||
17 years ago
|
|
||
16 years ago
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
11 years ago
|
& 'Done SPSPMM 1'
|
||
13 years ago
|
|
||
16 years ago
|
else
|
||
11 years ago
|
|
||
16 years ago
|
!
|
||
|
! Build the smoothed prolongator using the original matrix
|
||
|
!
|
||
14 years ago
|
do i=1,acsr3%get_nrows()
|
||
|
do j=acsr3%irp(i),acsr3%irp(i+1)-1
|
||
|
if (acsr3%ja(j) == i) then
|
||
|
acsr3%val(j) = sone - omega*acsr3%val(j)
|
||
|
else
|
||
|
acsr3%val(j) = - omega*acsr3%val(j)
|
||
|
end if
|
||
16 years ago
|
end do
|
||
14 years ago
|
end do
|
||
16 years ago
|
|
||
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
11 years ago
|
& 'Done gather, going for SPSPMM 1'
|
||
16 years ago
|
!
|
||
14 years ago
|
! acsrm1 = (I-w*D*A)Ptilde
|
||
16 years ago
|
! Doing it this way means to consider diag(A_i)
|
||
|
!
|
||
|
!
|
||
11 years ago
|
call psb_spspmm(acsr3,ptilde,acsr1,info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
11 years ago
|
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
|
||
16 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
11 years ago
|
& 'Done SPSPMM 1'
|
||
16 years ago
|
|
||
|
end if
|
||
13 years ago
|
call ptilde%free()
|
||
14 years ago
|
call acsr1%set_dupl(psb_dupl_add_)
|
||
17 years ago
|
|
||
9 years ago
|
call op_prol%cp_from(acsr1)
|
||
|
call tmp_prol%mv_from(acsr1)
|
||
13 years ago
|
!
|
||
9 years ago
|
! Now we have to gather the halo of tmp_prol, and add it to itself
|
||
13 years ago
|
! to multiply it by A,
|
||
|
!
|
||
9 years ago
|
call psb_sphalo(tmp_prol,desc_a,am4,info,&
|
||
13 years ago
|
& colcnv=.false.,rowscale=.true.)
|
||
9 years ago
|
if (info == psb_success_) call psb_rwextd(ncol,tmp_prol,info,b=am4)
|
||
13 years ago
|
if (info == psb_success_) call am4%free()
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
9 years ago
|
call psb_errpush(psb_err_internal_error_,name,a_err='Halo of tmp_prol')
|
||
17 years ago
|
goto 9999
|
||
|
end if
|
||
17 years ago
|
|
||
7 years ago
|
call psb_spspmm(la,tmp_prol,am3,info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
11 years ago
|
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 2')
|
||
17 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
8 years ago
|
& 'Done SPSPMM 2',parms%aggr_prol, mld_smooth_prol_
|
||
17 years ago
|
|
||
9 years ago
|
call tmp_prol%cp_to(tmpcoo)
|
||
11 years ago
|
call tmpcoo%transp()
|
||
|
|
||
13 years ago
|
nzl = tmpcoo%get_nzeros()
|
||
13 years ago
|
i=0
|
||
|
!
|
||
|
! Now we have to fix this. The only rows of B that are correct
|
||
|
! are those corresponding to "local" aggregates, i.e. indices in ilaggr(:)
|
||
|
!
|
||
|
do k=1, nzl
|
||
13 years ago
|
if ((naggrm1 < tmpcoo%ia(k)) .and.(tmpcoo%ia(k) <= naggrp1)) then
|
||
13 years ago
|
i = i+1
|
||
13 years ago
|
tmpcoo%val(i) = tmpcoo%val(k)
|
||
|
tmpcoo%ia(i) = tmpcoo%ia(k)
|
||
|
tmpcoo%ja(i) = tmpcoo%ja(k)
|
||
17 years ago
|
end if
|
||
13 years ago
|
end do
|
||
13 years ago
|
call tmpcoo%set_nzeros(i)
|
||
11 years ago
|
! call tmpcoo%trim()
|
||
13 years ago
|
call op_restr%mv_from(tmpcoo)
|
||
13 years ago
|
call op_restr%cscnv(info,type='csr',dupl=psb_dupl_add_)
|
||
9 years ago
|
|
||
13 years ago
|
if (info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_from_subroutine_,name,a_err='spcnv op_restr')
|
||
|
goto 9999
|
||
|
end if
|
||
17 years ago
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
|
& 'starting sphalo/ rwxtd'
|
||
|
|
||
13 years ago
|
! op_restr = ((i-wDA)Ptilde)^T
|
||
|
call psb_sphalo(am3,desc_a,am4,info,&
|
||
|
& colcnv=.false.,rowscale=.true.)
|
||
|
if (info == psb_success_) call psb_rwextd(ncol,am3,info,b=am4)
|
||
|
if (info == psb_success_) call am4%free()
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_internal_error_,name,a_err='Extend am3')
|
||
17 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
|
||
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
11 years ago
|
& 'starting spspmm 3'
|
||
|
call psb_spspmm(op_restr,am3,ac,info)
|
||
14 years ago
|
if (info == psb_success_) call am3%free()
|
||
9 years ago
|
if (info == psb_success_) call ac%cscnv(info,type='csr',dupl=psb_dupl_add_)
|
||
15 years ago
|
if (info /= psb_success_) then
|
||
13 years ago
|
call psb_errpush(psb_err_internal_error_,name,a_err='Build ac = op_restr x am3')
|
||
16 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
17 years ago
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),&
|
||
|
& 'Done smooth_aggregate '
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
|
9999 continue
|
||
|
call psb_errpush(info,name)
|
||
10 years ago
|
call psb_error_handler(err_act)
|
||
17 years ago
|
return
|
||
|
|
||
6 years ago
|
end subroutine mld_saggrmat_smth_bld
|