From 82bc6a7fc4f721ed2091255bdf1f387e938cc225 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 5 Feb 2020 11:23:18 +0000 Subject: [PATCH] New implementation of SMTH_BLD. --- .../impl/aggregator/mld_c_spmm_bld_inner.f90 | 222 ++++++++ .../impl/aggregator/mld_caggrmat_smth_bld.f90 | 213 +++----- .../impl/aggregator/mld_daggrmat_smth_bld.f90 | 493 ++++-------------- .../impl/aggregator/mld_s_spmm_bld_inner.f90 | 222 ++++++++ .../impl/aggregator/mld_saggrmat_smth_bld.f90 | 213 +++----- .../impl/aggregator/mld_z_spmm_bld_inner.f90 | 222 ++++++++ .../impl/aggregator/mld_zaggrmat_smth_bld.f90 | 213 +++----- 7 files changed, 959 insertions(+), 839 deletions(-) create mode 100644 mlprec/impl/aggregator/mld_c_spmm_bld_inner.f90 create mode 100644 mlprec/impl/aggregator/mld_s_spmm_bld_inner.f90 create mode 100644 mlprec/impl/aggregator/mld_z_spmm_bld_inner.f90 diff --git a/mlprec/impl/aggregator/mld_c_spmm_bld_inner.f90 b/mlprec/impl/aggregator/mld_c_spmm_bld_inner.f90 new file mode 100644 index 00000000..8c9dbbc7 --- /dev/null +++ b/mlprec/impl/aggregator/mld_c_spmm_bld_inner.f90 @@ -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_c_spmm_bld_inner(a_csr,desc_a,ilaggr,nlaggr,parms,ac,& + & op_prol,op_restr,info) + use psb_base_mod + use mld_c_inner_mod + use mld_c_base_aggregator_mod, mld_protect_name => mld_c_spmm_bld_inner + implicit none + + ! Arguments + type(psb_lc_csr_sparse_mat), intent(inout) :: a_csr + type(psb_desc_type), intent(in) :: desc_a + integer(psb_lpk_), intent(inout) :: ilaggr(:), nlaggr(:) + type(mld_sml_parms), intent(inout) :: parms + type(psb_lcspmat_type), intent(inout) :: op_prol, op_restr + type(psb_lcspmat_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_lc_coo_sparse_mat) :: ac_coo, tmpcoo, coo_prol + type(psb_lc_csr_sparse_mat) :: acsr2, acsr3, acsr4, csr_prol, ac_csr, csr_restr + type(psb_lcspmat_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_c_spmm_bld_inner diff --git a/mlprec/impl/aggregator/mld_caggrmat_smth_bld.f90 b/mlprec/impl/aggregator/mld_caggrmat_smth_bld.f90 index b63f7e06..f9432c69 100644 --- a/mlprec/impl/aggregator/mld_caggrmat_smth_bld.f90 +++ b/mlprec/impl/aggregator/mld_caggrmat_smth_bld.f90 @@ -106,6 +106,7 @@ subroutine mld_caggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest use psb_base_mod use mld_base_prec_type use mld_c_inner_mod, mld_protect_name => mld_caggrmat_smth_bld + use mld_c_base_aggregator_mod implicit none @@ -121,17 +122,22 @@ subroutine mld_caggrmat_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_lcspmat_type) :: la, am3, am4, tmp_prol type(psb_lc_coo_sparse_mat) :: tmpcoo - type(psb_lc_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde + type(psb_lc_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde, csr_prol, acsr complex(psb_spk_), allocatable :: adiag(:) + real(psb_spk_), allocatable :: arwsum(:) 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_spk_) :: anorm, omega, tmp, dg, theta + logical, parameter :: debug_new=.false. + character(len=80) :: filename name='mld_aggrmat_smth_bld' info=psb_success_ @@ -170,28 +176,25 @@ subroutine mld_caggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest & 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_) call a%cp_to(acsr) + call op_prol%cp_to(tmpcoo) 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.' + + call acsr%cp_to_fmt(acsrf,info) + 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 = czero @@ -223,16 +226,12 @@ subroutine mld_caggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest 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() + allocate(arwsum(nrow)) + call acsr%arwsum(arwsum) + anorm = maxval(abs(adiag(1:nrow)*arwsum(1:nrow))) call psb_amx(ictxt,anorm) omega = 4.d0/(3.d0*anorm) parms%aggr_omega_val = omega @@ -253,152 +252,43 @@ subroutine mld_caggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest goto 9999 end if - 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) = cone - 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 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 - - if (debug_level >= psb_debug_outer_) & - & write(debug_unit,*) me,' ',trim(name),& - & 'Done SPSPMM 1' - - else - - ! - ! 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) = cone - 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 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 SPSPMM 1' - - end if - call ptilde%free() - call acsr1%set_dupl(psb_dupl_add_) + + call acsrf%scal(adiag,info) + if (info /= psb_success_) goto 9999 - 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, + 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) ! - 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) + ! Build the smoothed prolongator using either A or Af + ! acsr1 = (I-w*D*A)Ptilde acsr1 = (I-w*D*Af)Ptilde + ! This is always done through the variable acsrf which + ! is a bit less readable, butsaves space and one extra matrix copy + ! + 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 2') + 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 2',parms%aggr_prol, mld_smooth_prol_ - - call tmp_prol%cp_to(tmpcoo) - call tmpcoo%transp() + & 'Done SPSPMM 1' - 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) - 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 + 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 mld_spmm_bld_inner(acsr,desc_a,ilaggr,nlaggr,parms,ac,& + & op_prol,op_restr,info) - 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),& @@ -411,4 +301,23 @@ subroutine mld_caggrmat_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) + implicit none + real(psb_spk_),intent(in) :: omega + type(psb_lc_csr_sparse_mat), intent(inout) :: acsr + ! + integer(psb_lpk_) :: i,j + do i=1,acsr%get_nrows() + do j=acsr%irp(i),acsr%irp(i+1)-1 + if (acsr%ja(j) == i) then + acsr%val(j) = cone - omega*acsr%val(j) + else + acsr%val(j) = - omega*acsr%val(j) + end if + end do + end do + end subroutine omega_smooth + end subroutine mld_caggrmat_smth_bld diff --git a/mlprec/impl/aggregator/mld_daggrmat_smth_bld.f90 b/mlprec/impl/aggregator/mld_daggrmat_smth_bld.f90 index 524ee213..19ca4167 100644 --- a/mlprec/impl/aggregator/mld_daggrmat_smth_bld.f90 +++ b/mlprec/impl/aggregator/mld_daggrmat_smth_bld.f90 @@ -97,7 +97,7 @@ ! The tentative prolongator on input, the computed prolongator on output ! ! op_restr - type(psb_dspmat_type), output -! The restrictor operagtor; normally, it is the transpose of the prolongator. +! The restrictor operator; normally, it is the transpose of the prolongator. ! ! info - integer, output. ! Error code. @@ -107,6 +107,7 @@ subroutine mld_daggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest 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 @@ -127,8 +128,9 @@ subroutine mld_daggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest 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, acsr3, acsrf, ptilde, csr_prol, acsr + type(psb_ld_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde, csr_prol, acsr real(psb_dpk_), allocatable :: adiag(:) + real(psb_dpk_), allocatable :: arwsum(:) integer(psb_ipk_) :: ierr(5) logical :: filter_mat integer(psb_ipk_) :: debug_level, debug_unit, err_act @@ -163,408 +165,131 @@ 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_) - if (debug_new) then - write(filename,'(a,i3.3,a)') 'in_prol-',me,'.mtx' - call op_prol%print(filename,head=' Test ') + ! + ! 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(acsr) + call op_prol%cp_to(tmpcoo) + + if(info /= psb_success_) then + call psb_errpush(psb_err_from_subroutine_,name,a_err='sp_getdiag') + goto 9999 end if - if (.false.) then + if (debug_level >= psb_debug_outer_) & + & write(debug_unit,*) me,' ',trim(name),& + & ' Initial copies done.' + + call acsr%cp_to_fmt(acsrf,info) + + if (filter_mat) then ! - ! naggr: number of local aggregates - ! nrow: local rows. + ! Build the filtered matrix Af from A ! - ! 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 + 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 - ! 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 - ! 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) + if (jd == -1) then + write(0,*) 'Wrong input: we need the diagonal!!!!', 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 - - 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 + acsrf%val(jd)=acsrf%val(jd)-tmp end if + enddo + ! Take out zeroed terms + call acsrf%clean_zeros(info) + end if - if (debug_level >= psb_debug_outer_) & - & write(debug_unit,*) me,' ',trim(name),& - & 'Done SPSPMM 1' + do i=1,size(adiag) + if (adiag(i) /= dzero) then + adiag(i) = done / adiag(i) else - - ! - ! 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 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) - ! - ! 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 - - 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 - - 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) - 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 + adiag(i) = done end if + end do + if (parms%aggr_omega_alg == mld_eig_est_) then - 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 - - else if (.true.) then - - write(0,*) ' smth_bld new' - - ! 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 (parms%aggr_eig == mld_max_norm_) then + allocate(arwsum(nrow)) + call acsr%arwsum(arwsum) + anorm = maxval(abs(adiag(1:nrow)*arwsum(1:nrow))) + call psb_amx(ictxt,anorm) + omega = 4.d0/(3.d0*anorm) + parms%aggr_omega_val = omega - if(info /= psb_success_) then - call psb_errpush(psb_err_from_subroutine_,name,a_err='sp_getdiag') + else + info = psb_err_internal_error_ + call psb_errpush(info,name,a_err='invalid mld_aggr_eig_') 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),& - & ' 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 - + else if (parms%aggr_omega_alg == mld_user_choice_) then - if (parms%aggr_omega_alg == mld_eig_est_) then + omega = parms%aggr_omega_val - 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 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 + + call acsrf%scal(adiag,info) + if (info /= psb_success_) goto 9999 + + 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) + ! + ! Build the smoothed prolongator using either A or Af + ! acsr1 = (I-w*D*A)Ptilde acsr1 = (I-w*D*Af)Ptilde + ! This is always done through the variable acsrf which + ! is a bit less readable, butsaves space and one extra matrix copy + ! + 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' - ! - ! 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 + 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) - if (debug_level >= psb_debug_outer_) & - & write(debug_unit,*) me,' ',trim(name),& - & 'Done SPSPMM 1' + call mld_spmm_bld_inner(acsr,desc_a,ilaggr,nlaggr,parms,ac,& + & op_prol,op_restr,info) - 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 ' @@ -577,20 +302,22 @@ subroutine mld_daggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest return contains + subroutine omega_smooth(omega,acsr) + implicit none 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) + do i=1,acsr%get_nrows() + do j=acsr%irp(i),acsr%irp(i+1)-1 + if (acsr%ja(j) == i) then + acsr%val(j) = done - omega*acsr%val(j) else - acsrf%val(j) = - omega*acsrf%val(j) + acsr%val(j) = - omega*acsr%val(j) end if end do end do end subroutine omega_smooth - + end subroutine mld_daggrmat_smth_bld diff --git a/mlprec/impl/aggregator/mld_s_spmm_bld_inner.f90 b/mlprec/impl/aggregator/mld_s_spmm_bld_inner.f90 new file mode 100644 index 00000000..8ecef8e6 --- /dev/null +++ b/mlprec/impl/aggregator/mld_s_spmm_bld_inner.f90 @@ -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_s_spmm_bld_inner(a_csr,desc_a,ilaggr,nlaggr,parms,ac,& + & op_prol,op_restr,info) + use psb_base_mod + use mld_s_inner_mod + use mld_s_base_aggregator_mod, mld_protect_name => mld_s_spmm_bld_inner + implicit none + + ! Arguments + type(psb_ls_csr_sparse_mat), intent(inout) :: a_csr + 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, op_restr + type(psb_lsspmat_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_ls_coo_sparse_mat) :: ac_coo, tmpcoo, coo_prol + type(psb_ls_csr_sparse_mat) :: acsr2, acsr3, acsr4, csr_prol, ac_csr, csr_restr + type(psb_lsspmat_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_s_spmm_bld_inner diff --git a/mlprec/impl/aggregator/mld_saggrmat_smth_bld.f90 b/mlprec/impl/aggregator/mld_saggrmat_smth_bld.f90 index fcf159d3..6e9f8103 100644 --- a/mlprec/impl/aggregator/mld_saggrmat_smth_bld.f90 +++ b/mlprec/impl/aggregator/mld_saggrmat_smth_bld.f90 @@ -106,6 +106,7 @@ subroutine mld_saggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest use psb_base_mod use mld_base_prec_type use mld_s_inner_mod, mld_protect_name => mld_saggrmat_smth_bld + use mld_s_base_aggregator_mod implicit none @@ -121,17 +122,22 @@ subroutine mld_saggrmat_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_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 + type(psb_ls_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde, csr_prol, acsr real(psb_spk_), allocatable :: adiag(:) + real(psb_spk_), allocatable :: arwsum(:) 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_spk_) :: anorm, omega, tmp, dg, theta + logical, parameter :: debug_new=.false. + character(len=80) :: filename name='mld_aggrmat_smth_bld' info=psb_success_ @@ -170,28 +176,25 @@ subroutine mld_saggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest & 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_) call a%cp_to(acsr) + call op_prol%cp_to(tmpcoo) 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.' + + call acsr%cp_to_fmt(acsrf,info) + 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 = szero @@ -223,16 +226,12 @@ subroutine mld_saggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest 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() + allocate(arwsum(nrow)) + call acsr%arwsum(arwsum) + anorm = maxval(abs(adiag(1:nrow)*arwsum(1:nrow))) call psb_amx(ictxt,anorm) omega = 4.d0/(3.d0*anorm) parms%aggr_omega_val = omega @@ -253,152 +252,43 @@ subroutine mld_saggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest goto 9999 end if - 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) = sone - 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 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 - - if (debug_level >= psb_debug_outer_) & - & write(debug_unit,*) me,' ',trim(name),& - & 'Done SPSPMM 1' - - else - - ! - ! 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) = sone - 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 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 SPSPMM 1' - - end if - call ptilde%free() - call acsr1%set_dupl(psb_dupl_add_) + + call acsrf%scal(adiag,info) + if (info /= psb_success_) goto 9999 - 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, + 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) ! - 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) + ! Build the smoothed prolongator using either A or Af + ! acsr1 = (I-w*D*A)Ptilde acsr1 = (I-w*D*Af)Ptilde + ! This is always done through the variable acsrf which + ! is a bit less readable, butsaves space and one extra matrix copy + ! + 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 2') + 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 2',parms%aggr_prol, mld_smooth_prol_ - - call tmp_prol%cp_to(tmpcoo) - call tmpcoo%transp() + & 'Done SPSPMM 1' - 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) - 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 + 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 mld_spmm_bld_inner(acsr,desc_a,ilaggr,nlaggr,parms,ac,& + & op_prol,op_restr,info) - 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),& @@ -411,4 +301,23 @@ subroutine mld_saggrmat_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) + implicit none + real(psb_spk_),intent(in) :: omega + type(psb_ls_csr_sparse_mat), intent(inout) :: acsr + ! + integer(psb_lpk_) :: i,j + do i=1,acsr%get_nrows() + do j=acsr%irp(i),acsr%irp(i+1)-1 + if (acsr%ja(j) == i) then + acsr%val(j) = sone - omega*acsr%val(j) + else + acsr%val(j) = - omega*acsr%val(j) + end if + end do + end do + end subroutine omega_smooth + end subroutine mld_saggrmat_smth_bld diff --git a/mlprec/impl/aggregator/mld_z_spmm_bld_inner.f90 b/mlprec/impl/aggregator/mld_z_spmm_bld_inner.f90 new file mode 100644 index 00000000..9938f122 --- /dev/null +++ b/mlprec/impl/aggregator/mld_z_spmm_bld_inner.f90 @@ -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_z_spmm_bld_inner(a_csr,desc_a,ilaggr,nlaggr,parms,ac,& + & op_prol,op_restr,info) + use psb_base_mod + use mld_z_inner_mod + use mld_z_base_aggregator_mod, mld_protect_name => mld_z_spmm_bld_inner + implicit none + + ! Arguments + type(psb_lz_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_lzspmat_type), intent(inout) :: op_prol, op_restr + type(psb_lzspmat_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_lz_coo_sparse_mat) :: ac_coo, tmpcoo, coo_prol + type(psb_lz_csr_sparse_mat) :: acsr2, acsr3, acsr4, csr_prol, ac_csr, csr_restr + type(psb_lzspmat_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_z_spmm_bld_inner diff --git a/mlprec/impl/aggregator/mld_zaggrmat_smth_bld.f90 b/mlprec/impl/aggregator/mld_zaggrmat_smth_bld.f90 index c96b5d12..a1687306 100644 --- a/mlprec/impl/aggregator/mld_zaggrmat_smth_bld.f90 +++ b/mlprec/impl/aggregator/mld_zaggrmat_smth_bld.f90 @@ -106,6 +106,7 @@ subroutine mld_zaggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest use psb_base_mod use mld_base_prec_type use mld_z_inner_mod, mld_protect_name => mld_zaggrmat_smth_bld + use mld_z_base_aggregator_mod implicit none @@ -121,17 +122,22 @@ subroutine mld_zaggrmat_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_lzspmat_type) :: la, am3, am4, tmp_prol type(psb_lz_coo_sparse_mat) :: tmpcoo - type(psb_lz_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde + type(psb_lz_csr_sparse_mat) :: acsr1, acsr2, acsr3, acsrf, ptilde, csr_prol, acsr complex(psb_dpk_), allocatable :: adiag(:) + real(psb_dpk_), allocatable :: arwsum(:) 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_ @@ -170,28 +176,25 @@ subroutine mld_zaggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest & 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_) call a%cp_to(acsr) + call op_prol%cp_to(tmpcoo) 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.' + + call acsr%cp_to_fmt(acsrf,info) + 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 = zzero @@ -223,16 +226,12 @@ subroutine mld_zaggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest 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() + allocate(arwsum(nrow)) + call acsr%arwsum(arwsum) + anorm = maxval(abs(adiag(1:nrow)*arwsum(1:nrow))) call psb_amx(ictxt,anorm) omega = 4.d0/(3.d0*anorm) parms%aggr_omega_val = omega @@ -253,152 +252,43 @@ subroutine mld_zaggrmat_smth_bld(a,desc_a,ilaggr,nlaggr,parms,ac,op_prol,op_rest goto 9999 end if - 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) = zone - 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 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 - - if (debug_level >= psb_debug_outer_) & - & write(debug_unit,*) me,' ',trim(name),& - & 'Done SPSPMM 1' - - else - - ! - ! 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) = zone - 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 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 SPSPMM 1' - - end if - call ptilde%free() - call acsr1%set_dupl(psb_dupl_add_) + + call acsrf%scal(adiag,info) + if (info /= psb_success_) goto 9999 - 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, + 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) ! - 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) + ! Build the smoothed prolongator using either A or Af + ! acsr1 = (I-w*D*A)Ptilde acsr1 = (I-w*D*Af)Ptilde + ! This is always done through the variable acsrf which + ! is a bit less readable, butsaves space and one extra matrix copy + ! + 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 2') + 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 2',parms%aggr_prol, mld_smooth_prol_ - - call tmp_prol%cp_to(tmpcoo) - call tmpcoo%transp() + & 'Done SPSPMM 1' - 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) - 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 + 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 mld_spmm_bld_inner(acsr,desc_a,ilaggr,nlaggr,parms,ac,& + & op_prol,op_restr,info) - 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),& @@ -411,4 +301,23 @@ subroutine mld_zaggrmat_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) + implicit none + real(psb_dpk_),intent(in) :: omega + type(psb_lz_csr_sparse_mat), intent(inout) :: acsr + ! + integer(psb_lpk_) :: i,j + do i=1,acsr%get_nrows() + do j=acsr%irp(i),acsr%irp(i+1)-1 + if (acsr%ja(j) == i) then + acsr%val(j) = zone - omega*acsr%val(j) + else + acsr%val(j) = - omega*acsr%val(j) + end if + end do + end do + end subroutine omega_smooth + end subroutine mld_zaggrmat_smth_bld