Beginning new version of smth_bld

stopcriterion
Salvatore Filippone 5 years ago
parent 7cefe92b0b
commit c6257025d8

@ -20,8 +20,9 @@ mld_d_dec_aggregator_mat_asb.o \
mld_d_dec_aggregator_mat_bld.o \
mld_d_dec_aggregator_tprol.o \
mld_d_symdec_aggregator_tprol.o \
mld_d_map_to_tprol.o mld_d_soc1_map_bld.o mld_d_soc2_map_bld.o\
mld_daggrmat_biz_bld.o mld_daggrmat_minnrg_bld.o\
mld_d_map_to_tprol.o mld_d_soc1_map_bld.o mld_d_soc2_map_bld.o \
mld_d_spmm_bld_inner.o \
mld_daggrmat_biz_bld.o mld_daggrmat_minnrg_bld.o \
mld_daggrmat_nosmth_bld.o mld_daggrmat_smth_bld.o \
mld_c_dec_aggregator_mat_asb.o \
mld_c_dec_aggregator_mat_bld.o \

@ -77,6 +77,7 @@
subroutine mld_d_dec_aggregator_build_tprol(ag,parms,ag_data,&
& a,desc_a,ilaggr,nlaggr,op_prol,info)
use psb_base_mod
use psb_util_mod
use mld_d_prec_type, mld_protect_name => mld_d_dec_aggregator_build_tprol
use mld_d_inner_mod
implicit none
@ -96,6 +97,8 @@ subroutine mld_d_dec_aggregator_build_tprol(ag,parms,ag_data,&
integer(psb_lpk_) :: ntaggr
integer(psb_ipk_) :: debug_level, debug_unit
logical :: clean_zeros
logical, parameter :: debug_new=.false.
character(len=80) :: filename
name='mld_d_dec_aggregator_tprol'
call psb_erractionsave(err_act)
@ -121,9 +124,21 @@ subroutine mld_d_dec_aggregator_build_tprol(ag,parms,ag_data,&
! ag_data except for clean_zeros; soc_map_bld is a procedure pointer.
!
clean_zeros = ag%do_clean_zeros
if (debug_new) then
write(filename,'(a,i3.3,a)') 'pre-a-',me,'.mtx'
call a%print(filename,head='Test')
end if
call ag%soc_map_bld(parms%aggr_ord,parms%aggr_thresh,clean_zeros,a,desc_a,nlaggr,ilaggr,info)
if (info==psb_success_) call mld_map_to_tprol(desc_a,ilaggr,nlaggr,op_prol,info)
if (debug_new) then
write(filename,'(a,i3.3,a)') 'ilaggr-',me,'.mtx'
call mm_array_write(ilaggr,' Aggregation vector ',info,filename=filename)
write(filename,'(a,i3.3,a)') 'pre-op-prol-',me,'.mtx'
call op_prol%print(filename,head='Test')
end if
if (info /= psb_success_) then
info=psb_err_from_subroutine_
call psb_errpush(info,name,a_err='soc_map_bld/map_to_tprol')

@ -0,0 +1,222 @@
!
!
! MLD2P4 Extensions
!
! (C) Copyright 2019
!
! Salvatore Filippone Cranfield University
! Pasqua D'Ambra IAC-CNR, Naples, IT
!
! 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.
!
!
! File: mld_daggrmat_nosmth_bld.F90
!
!
subroutine mld_d_spmm_bld_inner(a_csr,desc_a,ilaggr,nlaggr,parms,ac,&
& op_prol,op_restr,info)
use psb_base_mod
use mld_d_inner_mod
use mld_d_base_aggregator_mod, mld_protect_name => mld_d_spmm_bld_inner
implicit none
! Arguments
type(psb_ld_csr_sparse_mat), intent(inout) :: a_csr
type(psb_desc_type), intent(in) :: desc_a
integer(psb_lpk_), intent(inout) :: ilaggr(:), nlaggr(:)
type(mld_dml_parms), intent(inout) :: parms
type(psb_ldspmat_type), intent(inout) :: op_prol, op_restr
type(psb_ldspmat_type), intent(out) :: ac
integer(psb_ipk_), intent(out) :: info
! Local variables
integer(psb_ipk_) :: err_act
integer(psb_ipk_) :: ictxt,np,me, icomm, ndx, minfo
character(len=40) :: name
integer(psb_ipk_) :: ierr(5)
type(psb_ld_coo_sparse_mat) :: ac_coo, tmpcoo, coo_prol
type(psb_ld_csr_sparse_mat) :: acsr2, acsr3, acsr4, csr_prol, ac_csr, csr_restr
type(psb_ldspmat_type) :: am3, am4, tmp_prol
type(psb_desc_type), target :: tmp_desc
integer(psb_ipk_) :: debug_level, debug_unit, naggr
integer(psb_lpk_) :: nrow, nglob, ncol, ntaggr, nzl, ip, &
& nzt, naggrm1, naggrp1, i, k
integer(psb_lpk_) :: nrsave, ncsave, nzsave, nza, nrpsave, ncpsave, nzpsave
logical, parameter :: do_timings=.true., oldstyle=.false., debug=.false.
integer(psb_ipk_), save :: idx_spspmm=-1
name='mld_spmm_bld_inner'
if(psb_get_errstatus().ne.0) return
info=psb_success_
call psb_erractionsave(err_act)
ictxt = desc_a%get_context()
icomm = desc_a%get_mpic()
call psb_info(ictxt, me, np)
debug_unit = psb_get_debug_unit()
debug_level = psb_get_debug_level()
nglob = desc_a%get_global_rows()
nrow = desc_a%get_local_rows()
ncol = desc_a%get_local_cols()
if ((do_timings).and.(idx_spspmm==-1)) &
& idx_spspmm = psb_get_timer_idx("SPMM_BLD: par_spspmm")
naggr = nlaggr(me+1)
ntaggr = sum(nlaggr)
naggrm1 = sum(nlaggr(1:me))
naggrp1 = sum(nlaggr(1:me+1))
!write(0,*)me,' ',name,' input sizes',nlaggr(:),':',naggr
nrpsave = op_prol%get_nrows()
ncpsave = op_prol%get_ncols()
nzpsave = op_prol%get_nzeros()
!write(0,*)me,' ',name,' input op_prol ',nrpsave,ncpsave,nzpsave
!
! Here OP_PROL should be with GLOBAL indices on the cols
! and LOCAL indices on the rows.
!
if (debug) write(0,*) me,' ',trim(name),' Size check on entry New: ',&
& op_prol%get_fmt(),op_prol%get_nrows(),op_prol%get_ncols(),op_prol%get_nzeros(),&
& nrow,ntaggr,naggr
call op_prol%cp_to(coo_prol)
if (debug) write(0,*) me,' ',trim(name),' coo_prol: ',&
& coo_prol%ia(1:min(10,nzpsave)),' :',coo_prol%ja(1:min(10,nzpsave))
call psb_cdall(ictxt,tmp_desc,info,nl=naggr)
call tmp_desc%indxmap%g2lip_ins(coo_prol%ja(1:nzpsave),info)
call coo_prol%set_ncols(tmp_desc%get_local_cols())
call coo_prol%mv_to_fmt(csr_prol,info)
if (debug) write(0,*) me,trim(name),' Product AxPROL ',&
& a_csr%get_nrows(),a_csr%get_ncols(), csr_prol%get_nrows(), &
& desc_a%get_local_rows(),desc_a%get_local_cols(),&
& tmp_desc%get_local_rows(),desc_a%get_local_cols()
if (debug) flush(0)
if (do_timings) call psb_tic(idx_spspmm)
call psb_par_spspmm(a_csr,desc_a,csr_prol,acsr3,tmp_desc,info)
if (do_timings) call psb_toc(idx_spspmm)
if (debug) write(0,*) me,trim(name),' Done AxPROL ',&
& acsr3%get_nrows(),acsr3%get_ncols(), acsr3%get_nzeros(),&
& tmp_desc%get_local_rows(),tmp_desc%get_local_cols()
!
! Ok first product done.
!
! Remember that RESTR must be built from PROL after halo extension,
! which is done above in psb_par_spspmm
if (debug) write(0,*)me,' ',name,' No inp_restr, transposing prol ',&
& csr_prol%get_nrows(),csr_prol%get_ncols(),csr_prol%get_nzeros()
call csr_prol%cp_to_fmt(tmpcoo,info)
!!$ write(0,*)me,' ',name,' new into transposition ',tmpcoo%get_nrows(),&
!!$ & tmpcoo%get_ncols(),tmpcoo%get_nzeros()
call tmpcoo%transp()
nzl = tmpcoo%get_nzeros()
call tmp_desc%l2gip(tmpcoo%ia(1:nzl),info)
i=0
!
! Now we have to fix this. The only rows of the restrictor that are correct
! are those corresponding to "local" aggregates, i.e. indices in ilaggr(:)
!
do k=1, nzl
if ((naggrm1 < tmpcoo%ia(k)) .and.(tmpcoo%ia(k) <= naggrp1)) then
i = i+1
tmpcoo%val(i) = tmpcoo%val(k)
tmpcoo%ia(i) = tmpcoo%ia(k)
tmpcoo%ja(i) = tmpcoo%ja(k)
end if
end do
call tmpcoo%set_nzeros(i)
call tmpcoo%fix(info)
call op_restr%cp_from(tmpcoo)
!!$ write(0,*)me,' ',name,' after transposition ',tmpcoo%get_nrows(),tmpcoo%get_ncols(),tmpcoo%get_nzeros()
if (info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spcnv op_restr')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'starting sphalo/ rwxtd'
nzl = tmpcoo%get_nzeros()
call psb_glob_to_loc(tmpcoo%ia(1:nzl),tmp_desc,info,iact='I',owned=.true.)
call tmpcoo%clean_negidx(info)
nzl = tmpcoo%get_nzeros()
call tmpcoo%set_nrows(tmp_desc%get_local_rows())
call tmpcoo%set_ncols(desc_a%get_local_cols())
!!$ write(0,*)me,' ',name,' after G2L on rows ',tmpcoo%get_nrows(),tmpcoo%get_ncols(),tmpcoo%get_nzeros()
call csr_restr%mv_from_coo(tmpcoo,info)
if (debug) write(0,*) me,trim(name),' Product RESTRxAP ',&
& csr_restr%get_nrows(),csr_restr%get_ncols(), &
& tmp_desc%get_local_rows(),desc_a%get_local_cols(),&
& acsr3%get_nrows(),acsr3%get_ncols()
if (do_timings) call psb_tic(idx_spspmm)
call psb_par_spspmm(csr_restr,desc_a,acsr3,ac_csr,tmp_desc,info)
if (do_timings) call psb_toc(idx_spspmm)
call ac_csr%mv_to_coo(ac_coo,info)
nza = ac_coo%get_nzeros()
if (debug) write(0,*) me,trim(name),' Fixing ac ',&
& ac_coo%get_nrows(),ac_coo%get_ncols(), nza
call ac_coo%fix(info)
call tmp_desc%indxmap%l2gip(ac_coo%ia(1:nza),info)
call tmp_desc%indxmap%l2gip(ac_coo%ja(1:nza),info)
call ac_coo%set_nrows(ntaggr)
call ac_coo%set_ncols(ntaggr)
if (debug) write(0,*) me,' ',trim(name),' Before mv_from',psb_get_errstatus()
if (info == 0) call ac%mv_from(ac_coo)
if (debug) write(0,*) me,' ',trim(name),' After mv_from',psb_get_errstatus()
if (debug) write(0,*) me,' ',trim(name),' ',ac%get_fmt(),ac%get_nrows(),ac%get_ncols(),ac%get_nzeros(),naggr,ntaggr
! write(0,*) me,' ',trim(name),' Final AC newstyle ',ac%get_fmt(),ac%get_nrows(),ac%get_ncols(),ac%get_nzeros()
if (debug) then
write(0,*) me,' ',trim(name),' Checkpoint at exit'
call psb_barrier(ictxt)
write(0,*) me,' ',trim(name),' Checkpoint through'
end if
if (info /= psb_success_) then
call psb_errpush(psb_err_internal_error_,name,a_err='Build ac = op_restr x am3')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done smooth_aggregate '
call psb_erractionrestore(err_act)
return
9999 call psb_error_handler(err_act)
return
end subroutine mld_d_spmm_bld_inner

@ -97,7 +97,7 @@
! The tentative prolongator on input, the computed prolongator on output
!
! op_restr - type(psb_dspmat_type), output
! The restrictor operator; normally, it is the transpose of the prolongator.
! The restrictor operagtor; normally, it is the transpose of the prolongator.
!
! info - integer, output.
! Error code.
@ -106,7 +106,7 @@ subroutine mld_daggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest
use psb_base_mod
use mld_base_prec_type
use mld_d_inner_mod, mld_protect_name => mld_daggrmat_smth_bld
use mld_d_base_aggregator_mod
implicit none
! Arguments
@ -121,17 +121,21 @@ subroutine mld_daggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest
! Local variables
integer(psb_lpk_) :: nrow, nglob, ncol, ntaggr, ip, &
& naggr, nzl,naggrm1,naggrp1, i, j, k, jd, icolF, nrw
integer(psb_ipk_) :: inaggr, nzlp
integer(psb_ipk_) :: ictxt, np, me
character(len=20) :: name
type(psb_desc_type) :: tmp_desc
type(psb_ldspmat_type) :: la, am3, am4, tmp_prol
type(psb_ld_coo_sparse_mat) :: tmpcoo
type(psb_ld_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde
type(psb_ld_csr_sparse_mat) :: acsr1, acsr3, acsrf, ptilde, csr_prol, acsr
real(psb_dpk_), allocatable :: adiag(:)
integer(psb_ipk_) :: ierr(5)
logical :: filter_mat
integer(psb_ipk_) :: debug_level, debug_unit, err_act
integer(psb_ipk_), parameter :: ncmax=16
real(psb_dpk_) :: anorm, omega, tmp, dg, theta
logical, parameter :: debug_new=.false.
character(len=80) :: filename
name='mld_aggrmat_smth_bld'
info=psb_success_
@ -159,247 +163,408 @@ subroutine mld_daggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest
naggrp1 = sum(nlaggr(1:me+1))
filter_mat = (parms%aggr_filter == mld_filter_mat_)
!
! naggr: number of local aggregates
! nrow: local rows.
!
! Get the diagonal D
adiag = a%get_diag(info)
if (info == psb_success_) &
& call psb_realloc(ncol,adiag,info)
if (info == psb_success_) &
& call psb_halo(adiag,desc_a,info)
if (info == psb_success_) call a%cp_to_l(la)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='sp_getdiag')
goto 9999
if (debug_new) then
write(filename,'(a,i3.3,a)') 'in_prol-',me,'.mtx'
call op_prol%print(filename,head=' Test ')
end if
! 1. Allocate Ptilde in sparse matrix form
call op_prol%mv_to(tmpcoo)
call ptilde%mv_from_coo(tmpcoo,info)
if (info == psb_success_) call la%cscnv(acsr3,info,dupl=psb_dupl_add_)
if (info /= psb_success_) goto 9999
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& ' Initial copies done.'
if (.false.) then
if (filter_mat) then
!
! Build the filtered matrix Af from A
! naggr: number of local aggregates
! nrow: local rows.
!
if (info == psb_success_) call acsr3%cp_to_fmt(acsrf,info)
do i=1, nrow
tmp = dzero
jd = -1
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)=dzero
endif
! Get the diagonal D
adiag = a%get_diag(info)
if (info == psb_success_) &
& call psb_realloc(ncol,adiag,info)
if (info == psb_success_) &
& call psb_halo(adiag,desc_a,info)
if (info == psb_success_) call a%cp_to_l(la)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='sp_getdiag')
goto 9999
end if
! 1. Allocate Ptilde in sparse matrix form
call op_prol%mv_to(tmpcoo)
call ptilde%mv_from_coo(tmpcoo,info)
if (info == psb_success_) call la%cscnv(acsr3,info,dupl=psb_dupl_add_)
if (info /= psb_success_) goto 9999
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& ' Initial copies done.'
if (filter_mat) then
!
! Build the filtered matrix Af from A
!
if (info == psb_success_) call acsr3%cp_to_fmt(acsrf,info)
do i=1, nrow
tmp = dzero
jd = -1
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)=dzero
endif
enddo
if (jd == -1) then
write(0,*) 'Wrong input: we need the diagonal!!!!', i
else
acsrf%val(jd)=acsrf%val(jd)-tmp
end if
enddo
if (jd == -1) then
write(0,*) 'Wrong input: we need the diagonal!!!!', i
! Take out zeroed terms
call acsrf%clean_zeros(info)
end if
do i=1,size(adiag)
if (adiag(i) /= dzero) then
adiag(i) = done / adiag(i)
else
acsrf%val(jd)=acsrf%val(jd)-tmp
adiag(i) = done
end if
enddo
! Take out zeroed terms
call acsrf%clean_zeros(info)
end if
end do
if (filter_mat) call acsrf%scal(adiag,info)
if (info == psb_success_) call acsr3%scal(adiag,info)
if (info /= psb_success_) goto 9999
do i=1,size(adiag)
if (adiag(i) /= dzero) then
adiag(i) = done / adiag(i)
else
adiag(i) = done
end if
end do
if (filter_mat) call acsrf%scal(adiag,info)
if (info == psb_success_) call acsr3%scal(adiag,info)
if (info /= psb_success_) goto 9999
if (parms%aggr_omega_alg == mld_eig_est_) then
if (parms%aggr_eig == mld_max_norm_) then
anorm = acsr3%spnmi()
call psb_amx(ictxt,anorm)
omega = 4.d0/(3.d0*anorm)
parms%aggr_omega_val = omega
if (parms%aggr_omega_alg == mld_eig_est_) then
else
info = psb_err_internal_error_
call psb_errpush(info,name,a_err='invalid mld_aggr_eig_')
goto 9999
end if
if (parms%aggr_eig == mld_max_norm_) then
else if (parms%aggr_omega_alg == mld_user_choice_) then
anorm = acsr3%spnmi()
call psb_amx(ictxt,anorm)
omega = 4.d0/(3.d0*anorm)
parms%aggr_omega_val = omega
omega = parms%aggr_omega_val
else
else if (parms%aggr_omega_alg /= mld_user_choice_) then
info = psb_err_internal_error_
call psb_errpush(info,name,a_err='invalid mld_aggr_eig_')
call psb_errpush(info,name,a_err='invalid mld_aggr_omega_alg_')
goto 9999
end if
else if (parms%aggr_omega_alg == mld_user_choice_) then
if (filter_mat) then
!
! Build the smoothed prolongator using the filtered matrix
!
!!$ 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) = done - omega*acsrf%val(j)
!!$ else
!!$ acsrf%val(j) = - omega*acsrf%val(j)
!!$ end if
!!$ end do
!!$ end do
!!$
!!$ if (debug_level >= psb_debug_outer_) &
!!$ & write(debug_unit,*) me,' ',trim(name),&
!!$ & 'Done gather, going for SPSPMM 1'
!
!
! acsrm1 = (I-w*D*Af)Ptilde
! Doing it this way means to consider diag(Af_i)
!
!
call omega_smooth(omega,acsrf)
call psb_spspmm(acsrf,ptilde,acsr1,info)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
goto 9999
end if
omega = parms%aggr_omega_val
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done SPSPMM 1'
else if (parms%aggr_omega_alg /= mld_user_choice_) then
info = psb_err_internal_error_
call psb_errpush(info,name,a_err='invalid mld_aggr_omega_alg_')
goto 9999
end if
else
if (filter_mat) then
!
! Build the smoothed prolongator using the filtered matrix
!
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) = done - omega*acsrf%val(j)
else
acsrf%val(j) = - omega*acsrf%val(j)
end if
end do
end do
!
! Build the smoothed prolongator using the original matrix
!
!!$ 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) = done - omega*acsr3%val(j)
!!$ else
!!$ acsr3%val(j) = - omega*acsr3%val(j)
!!$ end if
!!$ end do
!!$ end do
!!$
!!$ if (debug_level >= psb_debug_outer_) &
!!$ & write(debug_unit,*) me,' ',trim(name),&
!!$ & 'Done gather, going for SPSPMM 1'
!
! acsrm1 = (I-w*D*A)Ptilde
! Doing it this way means to consider diag(A_i)
!
!
call omega_smooth(omega,acsr3)
call psb_spspmm(acsr3,ptilde,acsr1,info)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done gather, going for SPSPMM 1'
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done SPSPMM 1'
end if
call ptilde%free()
call acsr1%set_dupl(psb_dupl_add_)
call op_prol%cp_from(acsr1)
call tmp_prol%mv_from(acsr1)
!
!
! acsrm1 = (I-w*D*Af)Ptilde
! Doing it this way means to consider diag(Af_i)
!
! Now we have to gather the halo of tmp_prol, and add it to itself
! to multiply it by A,
!
call psb_spspmm(acsrf,ptilde,acsr1,info)
call psb_sphalo(tmp_prol,desc_a,am4,info,&
& colcnv=.false.,rowscale=.true.)
if (info == psb_success_) call psb_rwextd(ncol,tmp_prol,info,b=am4)
if (info == psb_success_) call am4%free()
if(info /= psb_success_) then
call psb_errpush(psb_err_internal_error_,name,a_err='Halo of tmp_prol')
goto 9999
end if
call psb_spspmm(la,tmp_prol,am3,info)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 2')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done SPSPMM 1'
& 'Done SPSPMM 2',parms%aggr_prol, mld_smooth_prol_
else
call tmp_prol%cp_to(tmpcoo)
call tmpcoo%transp()
nzl = tmpcoo%get_nzeros()
i=0
!
! Build the smoothed prolongator using the original matrix
! 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 i=1,acsr3%get_nrows()
do j=acsr3%irp(i),acsr3%irp(i+1)-1
if (acsr3%ja(j) == i) then
acsr3%val(j) = done - omega*acsr3%val(j)
else
acsr3%val(j) = - omega*acsr3%val(j)
end if
end do
do k=1, nzl
if ((naggrm1 < tmpcoo%ia(k)) .and.(tmpcoo%ia(k) <= naggrp1)) then
i = i+1
tmpcoo%val(i) = tmpcoo%val(k)
tmpcoo%ia(i) = tmpcoo%ia(k)
tmpcoo%ja(i) = tmpcoo%ja(k)
end if
end do
call tmpcoo%set_nzeros(i)
! call tmpcoo%trim()
call op_restr%mv_from(tmpcoo)
call op_restr%cscnv(info,type='csr',dupl=psb_dupl_add_)
if (info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spcnv op_restr')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done gather, going for SPSPMM 1'
!
! acsrm1 = (I-w*D*A)Ptilde
! Doing it this way means to consider diag(A_i)
!
!
call psb_spspmm(acsr3,ptilde,acsr1,info)
& 'starting sphalo/ rwxtd'
! 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()
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
call psb_errpush(psb_err_internal_error_,name,a_err='Extend am3')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done SPSPMM 1'
& 'starting spspmm 3'
call psb_spspmm(op_restr,am3,ac,info)
if (info == psb_success_) call am3%free()
if (info == psb_success_) call ac%cscnv(info,type='csr',dupl=psb_dupl_add_)
if (info /= psb_success_) then
call psb_errpush(psb_err_internal_error_,name,a_err='Build ac = op_restr x am3')
goto 9999
end if
end if
call ptilde%free()
call acsr1%set_dupl(psb_dupl_add_)
call op_prol%cp_from(acsr1)
call tmp_prol%mv_from(acsr1)
!
! Now we have to gather the halo of tmp_prol, and add it to itself
! to multiply it by A,
!
call psb_sphalo(tmp_prol,desc_a,am4,info,&
& colcnv=.false.,rowscale=.true.)
if (info == psb_success_) call psb_rwextd(ncol,tmp_prol,info,b=am4)
if (info == psb_success_) call am4%free()
if(info /= psb_success_) then
call psb_errpush(psb_err_internal_error_,name,a_err='Halo of tmp_prol')
goto 9999
end if
else if (.true.) then
write(0,*) ' smth_bld new'
call psb_spspmm(la,tmp_prol,am3,info)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 2')
goto 9999
end if
! Get the diagonal D
adiag = a%get_diag(info)
if (info == psb_success_) &
& call psb_realloc(ncol,adiag,info)
if (info == psb_success_) &
& call psb_halo(adiag,desc_a,info)
if (info == psb_success_) call a%cp_to(acsr3)
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done SPSPMM 2',parms%aggr_prol, mld_smooth_prol_
call tmp_prol%cp_to(tmpcoo)
call tmpcoo%transp()
nzl = tmpcoo%get_nzeros()
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
if ((naggrm1 < tmpcoo%ia(k)) .and.(tmpcoo%ia(k) <= naggrp1)) then
i = i+1
tmpcoo%val(i) = tmpcoo%val(k)
tmpcoo%ia(i) = tmpcoo%ia(k)
tmpcoo%ja(i) = tmpcoo%ja(k)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='sp_getdiag')
goto 9999
end if
end do
call tmpcoo%set_nzeros(i)
! call tmpcoo%trim()
call op_restr%mv_from(tmpcoo)
call op_restr%cscnv(info,type='csr',dupl=psb_dupl_add_)
if (info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spcnv op_restr')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'starting sphalo/ rwxtd'
! 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()
if(info /= psb_success_) then
call psb_errpush(psb_err_internal_error_,name,a_err='Extend am3')
goto 9999
end if
! 1. Allocate Ptilde in sparse matrix form
call op_prol%cp_to(tmpcoo)
!if (info == psb_success_) call la%cscnv(acsr3,info,dupl=psb_dupl_add_)
if (info /= psb_success_) goto 9999
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'starting spspmm 3'
call psb_spspmm(op_restr,am3,ac,info)
if (info == psb_success_) call am3%free()
if (info == psb_success_) call ac%cscnv(info,type='csr',dupl=psb_dupl_add_)
if (info /= psb_success_) then
call psb_errpush(psb_err_internal_error_,name,a_err='Build ac = op_restr x am3')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& ' Initial copies done.'
if (filter_mat) then
!
! Build the filtered matrix Af from A
!
if (info == psb_success_) call acsr3%cp_to_fmt(acsrf,info)
do i=1, nrow
tmp = dzero
jd = -1
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)=dzero
endif
enddo
if (jd == -1) then
write(0,*) 'Wrong input: we need the diagonal!!!!', i
else
acsrf%val(jd)=acsrf%val(jd)-tmp
end if
enddo
! Take out zeroed terms
call acsrf%clean_zeros(info)
end if
do i=1,size(adiag)
if (adiag(i) /= dzero) then
adiag(i) = done / adiag(i)
else
adiag(i) = done
end if
end do
if (filter_mat) call acsrf%scal(adiag,info)
if (info == psb_success_) call acsr3%scal(adiag,info)
if (info /= psb_success_) goto 9999
if (parms%aggr_omega_alg == mld_eig_est_) then
if (parms%aggr_eig == mld_max_norm_) then
anorm = acsr3%spnmi()
call psb_amx(ictxt,anorm)
omega = 4.d0/(3.d0*anorm)
parms%aggr_omega_val = omega
else
info = psb_err_internal_error_
call psb_errpush(info,name,a_err='invalid mld_aggr_eig_')
goto 9999
end if
else if (parms%aggr_omega_alg == mld_user_choice_) then
omega = parms%aggr_omega_val
else if (parms%aggr_omega_alg /= mld_user_choice_) then
info = psb_err_internal_error_
call psb_errpush(info,name,a_err='invalid mld_aggr_omega_alg_')
goto 9999
end if
inaggr = naggr
call psb_cdall(ictxt,tmp_desc,info,nl=inaggr)
nzlp = tmpcoo%get_nzeros()
call tmp_desc%indxmap%g2lip_ins(tmpcoo%ja(1:nzlp),info)
call tmpcoo%set_ncols(tmp_desc%get_local_cols())
call tmpcoo%mv_to_fmt(csr_prol,info)
if (filter_mat) then
!
! Build the smoothed prolongator using the filtered matrix
!
! acsrm1 = (I-w*D*Af)Ptilde
! Doing it this way means to consider diag(Af_i)
!
!
call omega_smooth(omega,acsrf)
call psb_par_spspmm(acsrf,desc_a,csr_prol,acsr1,tmp_desc,info)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done SPSPMM 1'
else
!
! Build the smoothed prolongator using the original matrix
!
!
! acsrm1 = (I-w*D*A)Ptilde
! Doing it this way means to consider diag(A_i)
!
!
call acsr3%cp_to_fmt(acsrf,info)
call omega_smooth(omega,acsrf)
call psb_par_spspmm(acsrf,desc_a,csr_prol,acsr1,tmp_desc,info)
if(info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_,name,a_err='spspmm 1')
goto 9999
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done SPSPMM 1'
end if
nzl = acsr1%get_nzeros()
call tmp_desc%l2gip(acsr1%ja(1:nzl),info)
call acsr1%set_dupl(psb_dupl_add_)
call acsr1%set_ncols(ntaggr)
call op_prol%cp_from(acsr1)
call a%cp_to(acsr3)
call mld_spmm_bld_inner(acsr3,desc_a,ilaggr,nlaggr,parms,ac,&
& op_prol,op_restr,info)
end if
if (debug_level >= psb_debug_outer_) &
& write(debug_unit,*) me,' ',trim(name),&
& 'Done smooth_aggregate '
@ -411,4 +576,21 @@ subroutine mld_daggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest
call psb_error_handler(err_act)
return
contains
subroutine omega_smooth(omega,acsr)
real(psb_dpk_),intent(in) :: omega
type(psb_ld_csr_sparse_mat), intent(inout) :: acsr
!
integer(psb_lpk_) :: i,j
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) = done - omega*acsrf%val(j)
else
acsrf%val(j) = - omega*acsrf%val(j)
end if
end do
end do
end subroutine omega_smooth
end subroutine mld_daggrmat_smth_bld

@ -43,7 +43,7 @@ module mld_d_base_aggregator_mod
use mld_base_prec_type, only : mld_dml_parms, mld_daggr_data
use psb_base_mod, only : psb_dspmat_type, psb_ldspmat_type, psb_d_vect_type, &
& psb_d_base_vect_type, psb_dlinmap_type, psb_dpk_, &
& psb_d_base_vect_type, psb_dlinmap_type, psb_dpk_, psb_ld_csr_sparse_mat, &
& psb_ipk_, psb_epk_, psb_lpk_, psb_desc_type, psb_i_base_vect_type, &
& psb_erractionsave, psb_error_handler, psb_success_, psb_toupper
!
@ -118,6 +118,24 @@ module mld_d_base_aggregator_mod
end subroutine mld_d_soc_map_bld
end interface
interface mld_spmm_bld_inner
subroutine mld_d_spmm_bld_inner(a_csr,desc_a,ilaggr,nlaggr,parms,ac,&
& op_prol,op_restr,info)
import :: psb_ld_csr_sparse_mat, psb_ldspmat_type, psb_desc_type, &
& mld_dml_parms,psb_dpk_, psb_ipk_, psb_lpk_
implicit none
! Arguments
type(psb_ld_csr_sparse_mat), intent(inout) :: a_csr
type(psb_desc_type), intent(in) :: desc_a
integer(psb_lpk_), intent(inout) :: ilaggr(:), nlaggr(:)
type(mld_dml_parms), intent(inout) :: parms
type(psb_ldspmat_type), intent(inout) :: op_prol, op_restr
type(psb_ldspmat_type), intent(out) :: ac
integer(psb_ipk_), intent(out) :: info
end subroutine mld_d_spmm_bld_inner
end interface mld_spmm_bld_inner
contains
subroutine mld_d_base_aggregator_cseti(ag,what,val,info,idx)

Loading…
Cancel
Save