mld2p4-2:

mlprec/impl/mld_c_dec_map_bld.f90
 mlprec/impl/mld_d_dec_map_bld.f90
 mlprec/impl/mld_s_dec_map_bld.f90
 mlprec/impl/mld_z_dec_map_bld.f90


Reimplemented Vanek-Brezina decoupled aggregation.
stopcriterion
Salvatore Filippone 8 years ago
parent 999c7eaf97
commit f7df243b6f

@ -56,10 +56,10 @@ subroutine mld_c_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),& integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),&
& ideg(:), idxs(:) & ideg(:), idxs(:)
complex(psb_spk_), allocatable :: val(:), diag(:) complex(psb_spk_), allocatable :: val(:), diag(:)
integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii, ip
type(psb_c_csr_sparse_mat) :: acsr type(psb_c_csr_sparse_mat) :: acsr
real(psb_spk_) :: cpling, tcl real(psb_spk_) :: cpling, tcl
logical :: recovery logical :: recovery, candidate
integer(psb_ipk_) :: debug_level, debug_unit,err_act integer(psb_ipk_) :: debug_level, debug_unit,err_act
integer(psb_ipk_) :: ictxt,np,me integer(psb_ipk_) :: ictxt,np,me
integer(psb_ipk_) :: nrow, ncol, n_ne integer(psb_ipk_) :: nrow, ncol, n_ne
@ -107,28 +107,17 @@ subroutine mld_c_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
call acsr%free() call acsr%free()
call psb_msort(ideg,ix=idxs,dir=psb_sort_down_) call psb_msort(ideg,ix=idxs,dir=psb_sort_down_)
end if end if
! Note: -(nr+1) Untouched as yet
! -i 1<=i<=nr Adjacent to aggregate i
! i 1<=i<=nr Belonging to aggregate i
! !
! Phase one: group nodes together. ! Phase one: Start with disjoint groups.
! Very simple minded strategy.
! !
naggr = 0 naggr = 0
nlp = 0
do
icnt = 0 icnt = 0
do ii=1, nr step1: do ii=1, nr
i = idxs(ii) i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
!
! 1. Untouched nodes are marked >0 together
! with their neighbours
!
icnt = icnt + 1
naggr = naggr + 1
ilaggr(i) = naggr
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
@ -136,162 +125,130 @@ subroutine mld_c_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
end if end if
!
! Build the set of all strongly coupled nodes
!
ip = 0
do k=1, nz do k=1, nz
j = icol(k) j = icol(k)
if ((1<=j).and.(j<=nr)) then if ((1<=j).and.(j<=nr)) then
ilg = ilaggr(j)
if ((ilg<0).and.(i /= j)) then
if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then
ilaggr(j) = naggr ip = ip + 1
else icol(ip) = icol(k)
ilaggr(j) = -naggr
endif
end if end if
end if end if
enddo enddo
if (ip < 1) then
write(0,*) "Should at least contain the node itself ! "
cycle step1
end if
candidate = .true.
do k=1, ip
candidate = candidate .and. (ilaggr(icol(k)) == -(nr+1))
end do
if (candidate) then
! !
! 2. Untouched neighbours of these nodes are marked <0. ! If the whole strongly coupled neighborhood of I is
! as yet unconnected, turn it into the next aggregate
! !
call a%get_neigh(i,neigh,n_ne,info,lev=2_psb_ipk_) icnt = icnt + 1
if (info /= psb_success_) then naggr = naggr + 1
info=psb_err_from_subroutine_ do k=1, ip
call psb_errpush(info,name,a_err='psb_neigh') ilaggr(icol(k)) = naggr
goto 9999
end if
do n = 1, n_ne
m = neigh(n)
if ((1<=m).and.(m<=nr)) then
if (ilaggr(m) == -(nr+1)) ilaggr(m) = -naggr
endif
end do end do
ilaggr(i) = naggr
end if end if
enddo endif
nlp = nlp + 1 enddo step1
if (icnt == 0) exit
enddo
if (debug_level >= psb_debug_outer_) then if (debug_level >= psb_debug_outer_) then
write(debug_unit,*) me,' ',trim(name),& write(debug_unit,*) me,' ',trim(name),&
& ' Check 1:',count(ilaggr == -(nr+1)) & ' Check 1:',count(ilaggr == -(nr+1))
end if end if
! !
! Phase two: sweep over leftovers. ! Phase two: join the neighbours
! !
allocate(ils(nr),stat=info) step2: do ii=1,nr
i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_alloc_request_ info=psb_err_from_subroutine_
call psb_errpush(info,name,i_err=(/naggr+10,izero,izero,izero,izero/),& call psb_errpush(info,name,a_err='psb_sp_getrow')
& a_err='integer')
goto 9999 goto 9999
end if end if
!
do i=1, size(ils) ! Find the most strongly connected neighbour that is
ils(i) = 0 ! already aggregated, if any, and join its aggregate
end do !
do i=1, nr cpling = szero
n = ilaggr(i) ip = 0
if (n>0) then do k=1, nz
if (n>naggr) then j = icol(k)
info=psb_err_internal_error_ if ((1<=j).and.(j<=nr)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 1 ?') if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
goto 9999 & .and. (ilaggr(j) > 0).and. (abs(val(k)) > cpling)) then
else ip = k
ils(n) = ils(n) + 1 cpling = abs(val(k))
end if end if
end if end if
enddo enddo
if (debug_level >= psb_debug_outer_) then if (ip > 0) then
write(debug_unit,*) me,' ',trim(name),& ilaggr(i) = ilaggr(icol(ip))
& 'Phase 1: number of aggregates ',naggr end if
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 1: nodes aggregated ',sum(ils)
end if end if
end do step2
recovery=.false.
do i=1, nr
if (ilaggr(i) < 0) then
! !
! Now some silly rule to break ties: ! Phase three: sweep over leftovers, if any
! Group with adjacent aggregate.
! !
isz = nr+1 step3: do ii=1,nr
ia = -1 i = idxs(ii)
cpling = czero
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
call psb_errpush(info,name,a_err='psb_sp_getrow') call psb_errpush(info,name,a_err='psb_sp_getrow')
goto 9999 goto 9999
end if end if
!
do j=1, nz ! Find the most strongly connected neighbour that is
k = icol(j) ! already aggregated, if any, and join its aggregate
if ((1<=k).and.(k<=nr).and.(k /= i)) then !
tcl = abs(val(j)) / sqrt(abs(diag(i)*diag(k))) cpling = szero
if (abs(val(j)) > theta*sqrt(abs(diag(i)*diag(k)))) then ip = 0
!!$ if (tcl > theta) then do k=1, nz
n = ilaggr(k) j = icol(k)
if (n>0) then if ((1<=j).and.(j<=nr)) then
if (n>naggr) then if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
info=psb_err_internal_error_ & .and. (ilaggr(j) < 0)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 2 ?') ip = ip + 1
goto 9999 icol(ip) = icol(k)
end if
if ((abs(val(j))>cpling) .or. &
& ((abs(val(j)) == cpling).and. (ils(n) < isz))) then
!!$ if ((tcl > cpling) .or. ((tcl == cpling).and. (ils(n) < isz))) then
ia = n
isz = ils(n)
cpling = abs(val(j))
!!$ cpling = tcl
endif
endif
end if end if
end if end if
enddo enddo
if (ip > 0) then
if (ia == -1) then icnt = icnt + 1
! At this point, the easiest thing is to start a new aggregate
naggr = naggr + 1 naggr = naggr + 1
ilaggr(i) = naggr ilaggr(i) = naggr
ils(ilaggr(i)) = 1 do k=1, ip
ilaggr(icol(k)) = naggr
end do
else else
!
ilaggr(i) = ia ! This should not happen: we did not even connect with ourselves.
! Create an isolate anyway.
if (ia>naggr) then !
info=psb_err_internal_error_ naggr = naggr + 1
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr ? ') ilaggr(i) = naggr
goto 9999
end if end if
ils(ia) = ils(ia) + 1
end if end if
end do step3
end if
end do
if (debug_level >= psb_debug_outer_) then
if (recovery) then
write(debug_unit,*) me,' ',trim(name),&
& 'Had to recover from strange situation in loc_aggregate.'
write(debug_unit,*) me,' ',trim(name),&
& 'Perhaps an unsymmetric pattern?'
endif
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 2: number of aggregates ',naggr,sum(ils)
do i=1, naggr
write(debug_unit,*) me,' ',trim(name),&
& 'Size of aggregate ',i,' :',count(ilaggr == i), ils(i)
enddo
write(debug_unit,*) me,' ',trim(name),&
& maxval(ils(1:naggr))
write(debug_unit,*) me,' ',trim(name),&
& 'Leftovers ',count(ilaggr<0), ' in ',nlp,' loops'
end if
if (count(ilaggr<0) >0) then if (count(ilaggr<0) >0) then
info=psb_err_internal_error_ info=psb_err_internal_error_
@ -299,12 +256,6 @@ subroutine mld_c_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
endif endif
deallocate(ils,neigh,stat=info)
if (info /= psb_success_) then
info=psb_err_alloc_dealloc_
call psb_errpush(info,name)
goto 9999
end if
if (naggr > ncol) then if (naggr > ncol) then
write(0,*) name,'Error : naggr > ncol',naggr,ncol write(0,*) name,'Error : naggr > ncol',naggr,ncol
info=psb_err_internal_error_ info=psb_err_internal_error_

@ -56,10 +56,10 @@ subroutine mld_d_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),& integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),&
& ideg(:), idxs(:) & ideg(:), idxs(:)
real(psb_dpk_), allocatable :: val(:), diag(:) real(psb_dpk_), allocatable :: val(:), diag(:)
integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii, ip
type(psb_d_csr_sparse_mat) :: acsr type(psb_d_csr_sparse_mat) :: acsr
real(psb_dpk_) :: cpling, tcl real(psb_dpk_) :: cpling, tcl
logical :: recovery logical :: recovery, candidate
integer(psb_ipk_) :: debug_level, debug_unit,err_act integer(psb_ipk_) :: debug_level, debug_unit,err_act
integer(psb_ipk_) :: ictxt,np,me integer(psb_ipk_) :: ictxt,np,me
integer(psb_ipk_) :: nrow, ncol, n_ne integer(psb_ipk_) :: nrow, ncol, n_ne
@ -107,28 +107,17 @@ subroutine mld_d_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
call acsr%free() call acsr%free()
call psb_msort(ideg,ix=idxs,dir=psb_sort_down_) call psb_msort(ideg,ix=idxs,dir=psb_sort_down_)
end if end if
! Note: -(nr+1) Untouched as yet
! -i 1<=i<=nr Adjacent to aggregate i
! i 1<=i<=nr Belonging to aggregate i
! !
! Phase one: group nodes together. ! Phase one: Start with disjoint groups.
! Very simple minded strategy.
! !
naggr = 0 naggr = 0
nlp = 0
do
icnt = 0 icnt = 0
do ii=1, nr step1: do ii=1, nr
i = idxs(ii) i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
!
! 1. Untouched nodes are marked >0 together
! with their neighbours
!
icnt = icnt + 1
naggr = naggr + 1
ilaggr(i) = naggr
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
@ -136,162 +125,130 @@ subroutine mld_d_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
end if end if
!
! Build the set of all strongly coupled nodes
!
ip = 0
do k=1, nz do k=1, nz
j = icol(k) j = icol(k)
if ((1<=j).and.(j<=nr)) then if ((1<=j).and.(j<=nr)) then
ilg = ilaggr(j)
if ((ilg<0).and.(i /= j)) then
if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then
ilaggr(j) = naggr ip = ip + 1
else icol(ip) = icol(k)
ilaggr(j) = -naggr
endif
end if end if
end if end if
enddo enddo
if (ip < 1) then
write(0,*) "Should at least contain the node itself ! "
cycle step1
end if
candidate = .true.
do k=1, ip
candidate = candidate .and. (ilaggr(icol(k)) == -(nr+1))
end do
if (candidate) then
! !
! 2. Untouched neighbours of these nodes are marked <0. ! If the whole strongly coupled neighborhood of I is
! as yet unconnected, turn it into the next aggregate
! !
call a%get_neigh(i,neigh,n_ne,info,lev=2_psb_ipk_) icnt = icnt + 1
if (info /= psb_success_) then naggr = naggr + 1
info=psb_err_from_subroutine_ do k=1, ip
call psb_errpush(info,name,a_err='psb_neigh') ilaggr(icol(k)) = naggr
goto 9999
end if
do n = 1, n_ne
m = neigh(n)
if ((1<=m).and.(m<=nr)) then
if (ilaggr(m) == -(nr+1)) ilaggr(m) = -naggr
endif
end do end do
ilaggr(i) = naggr
end if end if
enddo endif
nlp = nlp + 1 enddo step1
if (icnt == 0) exit
enddo
if (debug_level >= psb_debug_outer_) then if (debug_level >= psb_debug_outer_) then
write(debug_unit,*) me,' ',trim(name),& write(debug_unit,*) me,' ',trim(name),&
& ' Check 1:',count(ilaggr == -(nr+1)) & ' Check 1:',count(ilaggr == -(nr+1))
end if end if
! !
! Phase two: sweep over leftovers. ! Phase two: join the neighbours
! !
allocate(ils(nr),stat=info) step2: do ii=1,nr
i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_alloc_request_ info=psb_err_from_subroutine_
call psb_errpush(info,name,i_err=(/naggr+10,izero,izero,izero,izero/),& call psb_errpush(info,name,a_err='psb_sp_getrow')
& a_err='integer')
goto 9999 goto 9999
end if end if
!
do i=1, size(ils) ! Find the most strongly connected neighbour that is
ils(i) = 0 ! already aggregated, if any, and join its aggregate
end do !
do i=1, nr cpling = dzero
n = ilaggr(i) ip = 0
if (n>0) then do k=1, nz
if (n>naggr) then j = icol(k)
info=psb_err_internal_error_ if ((1<=j).and.(j<=nr)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 1 ?') if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
goto 9999 & .and. (ilaggr(j) > 0).and. (abs(val(k)) > cpling)) then
else ip = k
ils(n) = ils(n) + 1 cpling = abs(val(k))
end if end if
end if end if
enddo enddo
if (debug_level >= psb_debug_outer_) then if (ip > 0) then
write(debug_unit,*) me,' ',trim(name),& ilaggr(i) = ilaggr(icol(ip))
& 'Phase 1: number of aggregates ',naggr
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 1: nodes aggregated ',sum(ils)
end if end if
end if
end do step2
recovery=.false.
do i=1, nr
if (ilaggr(i) < 0) then
! !
! Now some silly rule to break ties: ! Phase three: sweep over leftovers, if any
! Group with adjacent aggregate.
! !
isz = nr+1 step3: do ii=1,nr
ia = -1 i = idxs(ii)
cpling = dzero
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
call psb_errpush(info,name,a_err='psb_sp_getrow') call psb_errpush(info,name,a_err='psb_sp_getrow')
goto 9999 goto 9999
end if end if
!
do j=1, nz ! Find the most strongly connected neighbour that is
k = icol(j) ! already aggregated, if any, and join its aggregate
if ((1<=k).and.(k<=nr).and.(k /= i)) then !
tcl = abs(val(j)) / sqrt(abs(diag(i)*diag(k))) cpling = dzero
if (abs(val(j)) > theta*sqrt(abs(diag(i)*diag(k)))) then ip = 0
!!$ if (tcl > theta) then do k=1, nz
n = ilaggr(k) j = icol(k)
if (n>0) then if ((1<=j).and.(j<=nr)) then
if (n>naggr) then if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
info=psb_err_internal_error_ & .and. (ilaggr(j) < 0)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 2 ?') ip = ip + 1
goto 9999 icol(ip) = icol(k)
end if
if ((abs(val(j))>cpling) .or. &
& ((abs(val(j)) == cpling).and. (ils(n) < isz))) then
!!$ if ((tcl > cpling) .or. ((tcl == cpling).and. (ils(n) < isz))) then
ia = n
isz = ils(n)
cpling = abs(val(j))
!!$ cpling = tcl
endif
endif
end if end if
end if end if
enddo enddo
if (ip > 0) then
if (ia == -1) then icnt = icnt + 1
! At this point, the easiest thing is to start a new aggregate
naggr = naggr + 1 naggr = naggr + 1
ilaggr(i) = naggr ilaggr(i) = naggr
ils(ilaggr(i)) = 1 do k=1, ip
ilaggr(icol(k)) = naggr
end do
else else
!
ilaggr(i) = ia ! This should not happen: we did not even connect with ourselves.
! Create an isolate anyway.
if (ia>naggr) then !
info=psb_err_internal_error_ naggr = naggr + 1
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr ? ') ilaggr(i) = naggr
goto 9999
end if end if
ils(ia) = ils(ia) + 1
end if end if
end do step3
end if
end do
if (debug_level >= psb_debug_outer_) then
if (recovery) then
write(debug_unit,*) me,' ',trim(name),&
& 'Had to recover from strange situation in loc_aggregate.'
write(debug_unit,*) me,' ',trim(name),&
& 'Perhaps an unsymmetric pattern?'
endif
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 2: number of aggregates ',naggr,sum(ils)
do i=1, naggr
write(debug_unit,*) me,' ',trim(name),&
& 'Size of aggregate ',i,' :',count(ilaggr == i), ils(i)
enddo
write(debug_unit,*) me,' ',trim(name),&
& maxval(ils(1:naggr))
write(debug_unit,*) me,' ',trim(name),&
& 'Leftovers ',count(ilaggr<0), ' in ',nlp,' loops'
end if
if (count(ilaggr<0) >0) then if (count(ilaggr<0) >0) then
info=psb_err_internal_error_ info=psb_err_internal_error_
@ -299,12 +256,6 @@ subroutine mld_d_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
endif endif
deallocate(ils,neigh,stat=info)
if (info /= psb_success_) then
info=psb_err_alloc_dealloc_
call psb_errpush(info,name)
goto 9999
end if
if (naggr > ncol) then if (naggr > ncol) then
write(0,*) name,'Error : naggr > ncol',naggr,ncol write(0,*) name,'Error : naggr > ncol',naggr,ncol
info=psb_err_internal_error_ info=psb_err_internal_error_

@ -56,10 +56,10 @@ subroutine mld_s_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),& integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),&
& ideg(:), idxs(:) & ideg(:), idxs(:)
real(psb_spk_), allocatable :: val(:), diag(:) real(psb_spk_), allocatable :: val(:), diag(:)
integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii, ip
type(psb_s_csr_sparse_mat) :: acsr type(psb_s_csr_sparse_mat) :: acsr
real(psb_spk_) :: cpling, tcl real(psb_spk_) :: cpling, tcl
logical :: recovery logical :: recovery, candidate
integer(psb_ipk_) :: debug_level, debug_unit,err_act integer(psb_ipk_) :: debug_level, debug_unit,err_act
integer(psb_ipk_) :: ictxt,np,me integer(psb_ipk_) :: ictxt,np,me
integer(psb_ipk_) :: nrow, ncol, n_ne integer(psb_ipk_) :: nrow, ncol, n_ne
@ -107,28 +107,17 @@ subroutine mld_s_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
call acsr%free() call acsr%free()
call psb_msort(ideg,ix=idxs,dir=psb_sort_down_) call psb_msort(ideg,ix=idxs,dir=psb_sort_down_)
end if end if
! Note: -(nr+1) Untouched as yet
! -i 1<=i<=nr Adjacent to aggregate i
! i 1<=i<=nr Belonging to aggregate i
! !
! Phase one: group nodes together. ! Phase one: Start with disjoint groups.
! Very simple minded strategy.
! !
naggr = 0 naggr = 0
nlp = 0
do
icnt = 0 icnt = 0
do ii=1, nr step1: do ii=1, nr
i = idxs(ii) i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
!
! 1. Untouched nodes are marked >0 together
! with their neighbours
!
icnt = icnt + 1
naggr = naggr + 1
ilaggr(i) = naggr
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
@ -136,162 +125,130 @@ subroutine mld_s_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
end if end if
!
! Build the set of all strongly coupled nodes
!
ip = 0
do k=1, nz do k=1, nz
j = icol(k) j = icol(k)
if ((1<=j).and.(j<=nr)) then if ((1<=j).and.(j<=nr)) then
ilg = ilaggr(j)
if ((ilg<0).and.(i /= j)) then
if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then
ilaggr(j) = naggr ip = ip + 1
else icol(ip) = icol(k)
ilaggr(j) = -naggr
endif
end if end if
end if end if
enddo enddo
if (ip < 1) then
write(0,*) "Should at least contain the node itself ! "
cycle step1
end if
candidate = .true.
do k=1, ip
candidate = candidate .and. (ilaggr(icol(k)) == -(nr+1))
end do
if (candidate) then
! !
! 2. Untouched neighbours of these nodes are marked <0. ! If the whole strongly coupled neighborhood of I is
! as yet unconnected, turn it into the next aggregate
! !
call a%get_neigh(i,neigh,n_ne,info,lev=2_psb_ipk_) icnt = icnt + 1
if (info /= psb_success_) then naggr = naggr + 1
info=psb_err_from_subroutine_ do k=1, ip
call psb_errpush(info,name,a_err='psb_neigh') ilaggr(icol(k)) = naggr
goto 9999
end if
do n = 1, n_ne
m = neigh(n)
if ((1<=m).and.(m<=nr)) then
if (ilaggr(m) == -(nr+1)) ilaggr(m) = -naggr
endif
end do end do
ilaggr(i) = naggr
end if end if
enddo endif
nlp = nlp + 1 enddo step1
if (icnt == 0) exit
enddo
if (debug_level >= psb_debug_outer_) then if (debug_level >= psb_debug_outer_) then
write(debug_unit,*) me,' ',trim(name),& write(debug_unit,*) me,' ',trim(name),&
& ' Check 1:',count(ilaggr == -(nr+1)) & ' Check 1:',count(ilaggr == -(nr+1))
end if end if
! !
! Phase two: sweep over leftovers. ! Phase two: join the neighbours
! !
allocate(ils(nr),stat=info) step2: do ii=1,nr
i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_alloc_request_ info=psb_err_from_subroutine_
call psb_errpush(info,name,i_err=(/naggr+10,izero,izero,izero,izero/),& call psb_errpush(info,name,a_err='psb_sp_getrow')
& a_err='integer')
goto 9999 goto 9999
end if end if
!
do i=1, size(ils) ! Find the most strongly connected neighbour that is
ils(i) = 0 ! already aggregated, if any, and join its aggregate
end do !
do i=1, nr cpling = szero
n = ilaggr(i) ip = 0
if (n>0) then do k=1, nz
if (n>naggr) then j = icol(k)
info=psb_err_internal_error_ if ((1<=j).and.(j<=nr)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 1 ?') if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
goto 9999 & .and. (ilaggr(j) > 0).and. (abs(val(k)) > cpling)) then
else ip = k
ils(n) = ils(n) + 1 cpling = abs(val(k))
end if end if
end if end if
enddo enddo
if (debug_level >= psb_debug_outer_) then if (ip > 0) then
write(debug_unit,*) me,' ',trim(name),& ilaggr(i) = ilaggr(icol(ip))
& 'Phase 1: number of aggregates ',naggr
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 1: nodes aggregated ',sum(ils)
end if end if
end if
end do step2
recovery=.false.
do i=1, nr
if (ilaggr(i) < 0) then
! !
! Now some silly rule to break ties: ! Phase three: sweep over leftovers, if any
! Group with adjacent aggregate.
! !
isz = nr+1 step3: do ii=1,nr
ia = -1 i = idxs(ii)
cpling = szero
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
call psb_errpush(info,name,a_err='psb_sp_getrow') call psb_errpush(info,name,a_err='psb_sp_getrow')
goto 9999 goto 9999
end if end if
!
do j=1, nz ! Find the most strongly connected neighbour that is
k = icol(j) ! already aggregated, if any, and join its aggregate
if ((1<=k).and.(k<=nr).and.(k /= i)) then !
tcl = abs(val(j)) / sqrt(abs(diag(i)*diag(k))) cpling = szero
if (abs(val(j)) > theta*sqrt(abs(diag(i)*diag(k)))) then ip = 0
!!$ if (tcl > theta) then do k=1, nz
n = ilaggr(k) j = icol(k)
if (n>0) then if ((1<=j).and.(j<=nr)) then
if (n>naggr) then if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
info=psb_err_internal_error_ & .and. (ilaggr(j) < 0)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 2 ?') ip = ip + 1
goto 9999 icol(ip) = icol(k)
end if
if ((abs(val(j))>cpling) .or. &
& ((abs(val(j)) == cpling).and. (ils(n) < isz))) then
!!$ if ((tcl > cpling) .or. ((tcl == cpling).and. (ils(n) < isz))) then
ia = n
isz = ils(n)
cpling = abs(val(j))
!!$ cpling = tcl
endif
endif
end if end if
end if end if
enddo enddo
if (ip > 0) then
if (ia == -1) then icnt = icnt + 1
! At this point, the easiest thing is to start a new aggregate
naggr = naggr + 1 naggr = naggr + 1
ilaggr(i) = naggr ilaggr(i) = naggr
ils(ilaggr(i)) = 1 do k=1, ip
ilaggr(icol(k)) = naggr
end do
else else
!
ilaggr(i) = ia ! This should not happen: we did not even connect with ourselves.
! Create an isolate anyway.
if (ia>naggr) then !
info=psb_err_internal_error_ naggr = naggr + 1
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr ? ') ilaggr(i) = naggr
goto 9999
end if end if
ils(ia) = ils(ia) + 1
end if end if
end do step3
end if
end do
if (debug_level >= psb_debug_outer_) then
if (recovery) then
write(debug_unit,*) me,' ',trim(name),&
& 'Had to recover from strange situation in loc_aggregate.'
write(debug_unit,*) me,' ',trim(name),&
& 'Perhaps an unsymmetric pattern?'
endif
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 2: number of aggregates ',naggr,sum(ils)
do i=1, naggr
write(debug_unit,*) me,' ',trim(name),&
& 'Size of aggregate ',i,' :',count(ilaggr == i), ils(i)
enddo
write(debug_unit,*) me,' ',trim(name),&
& maxval(ils(1:naggr))
write(debug_unit,*) me,' ',trim(name),&
& 'Leftovers ',count(ilaggr<0), ' in ',nlp,' loops'
end if
if (count(ilaggr<0) >0) then if (count(ilaggr<0) >0) then
info=psb_err_internal_error_ info=psb_err_internal_error_
@ -299,12 +256,6 @@ subroutine mld_s_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
endif endif
deallocate(ils,neigh,stat=info)
if (info /= psb_success_) then
info=psb_err_alloc_dealloc_
call psb_errpush(info,name)
goto 9999
end if
if (naggr > ncol) then if (naggr > ncol) then
write(0,*) name,'Error : naggr > ncol',naggr,ncol write(0,*) name,'Error : naggr > ncol',naggr,ncol
info=psb_err_internal_error_ info=psb_err_internal_error_

@ -56,10 +56,10 @@ subroutine mld_z_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),& integer(psb_ipk_), allocatable :: ils(:), neigh(:), irow(:), icol(:),&
& ideg(:), idxs(:) & ideg(:), idxs(:)
complex(psb_dpk_), allocatable :: val(:), diag(:) complex(psb_dpk_), allocatable :: val(:), diag(:)
integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii integer(psb_ipk_) :: icnt,nlp,k,n,ia,isz,nr, naggr,i,j,m, nz, ilg, ii, ip
type(psb_z_csr_sparse_mat) :: acsr type(psb_z_csr_sparse_mat) :: acsr
real(psb_dpk_) :: cpling, tcl real(psb_dpk_) :: cpling, tcl
logical :: recovery logical :: recovery, candidate
integer(psb_ipk_) :: debug_level, debug_unit,err_act integer(psb_ipk_) :: debug_level, debug_unit,err_act
integer(psb_ipk_) :: ictxt,np,me integer(psb_ipk_) :: ictxt,np,me
integer(psb_ipk_) :: nrow, ncol, n_ne integer(psb_ipk_) :: nrow, ncol, n_ne
@ -107,28 +107,17 @@ subroutine mld_z_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
call acsr%free() call acsr%free()
call psb_msort(ideg,ix=idxs,dir=psb_sort_down_) call psb_msort(ideg,ix=idxs,dir=psb_sort_down_)
end if end if
! Note: -(nr+1) Untouched as yet
! -i 1<=i<=nr Adjacent to aggregate i
! i 1<=i<=nr Belonging to aggregate i
! !
! Phase one: group nodes together. ! Phase one: Start with disjoint groups.
! Very simple minded strategy.
! !
naggr = 0 naggr = 0
nlp = 0
do
icnt = 0 icnt = 0
do ii=1, nr step1: do ii=1, nr
i = idxs(ii) i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
!
! 1. Untouched nodes are marked >0 together
! with their neighbours
!
icnt = icnt + 1
naggr = naggr + 1
ilaggr(i) = naggr
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
@ -136,162 +125,130 @@ subroutine mld_z_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
end if end if
!
! Build the set of all strongly coupled nodes
!
ip = 0
do k=1, nz do k=1, nz
j = icol(k) j = icol(k)
if ((1<=j).and.(j<=nr)) then if ((1<=j).and.(j<=nr)) then
ilg = ilaggr(j)
if ((ilg<0).and.(i /= j)) then
if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then if (abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j)))) then
ilaggr(j) = naggr ip = ip + 1
else icol(ip) = icol(k)
ilaggr(j) = -naggr
endif
end if end if
end if end if
enddo enddo
if (ip < 1) then
write(0,*) "Should at least contain the node itself ! "
cycle step1
end if
candidate = .true.
do k=1, ip
candidate = candidate .and. (ilaggr(icol(k)) == -(nr+1))
end do
if (candidate) then
! !
! 2. Untouched neighbours of these nodes are marked <0. ! If the whole strongly coupled neighborhood of I is
! as yet unconnected, turn it into the next aggregate
! !
call a%get_neigh(i,neigh,n_ne,info,lev=2_psb_ipk_) icnt = icnt + 1
if (info /= psb_success_) then naggr = naggr + 1
info=psb_err_from_subroutine_ do k=1, ip
call psb_errpush(info,name,a_err='psb_neigh') ilaggr(icol(k)) = naggr
goto 9999
end if
do n = 1, n_ne
m = neigh(n)
if ((1<=m).and.(m<=nr)) then
if (ilaggr(m) == -(nr+1)) ilaggr(m) = -naggr
endif
end do end do
ilaggr(i) = naggr
end if end if
enddo endif
nlp = nlp + 1 enddo step1
if (icnt == 0) exit
enddo
if (debug_level >= psb_debug_outer_) then if (debug_level >= psb_debug_outer_) then
write(debug_unit,*) me,' ',trim(name),& write(debug_unit,*) me,' ',trim(name),&
& ' Check 1:',count(ilaggr == -(nr+1)) & ' Check 1:',count(ilaggr == -(nr+1))
end if end if
! !
! Phase two: sweep over leftovers. ! Phase two: join the neighbours
! !
allocate(ils(nr),stat=info) step2: do ii=1,nr
i = idxs(ii)
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_alloc_request_ info=psb_err_from_subroutine_
call psb_errpush(info,name,i_err=(/naggr+10,izero,izero,izero,izero/),& call psb_errpush(info,name,a_err='psb_sp_getrow')
& a_err='integer')
goto 9999 goto 9999
end if end if
!
do i=1, size(ils) ! Find the most strongly connected neighbour that is
ils(i) = 0 ! already aggregated, if any, and join its aggregate
end do !
do i=1, nr cpling = dzero
n = ilaggr(i) ip = 0
if (n>0) then do k=1, nz
if (n>naggr) then j = icol(k)
info=psb_err_internal_error_ if ((1<=j).and.(j<=nr)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 1 ?') if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
goto 9999 & .and. (ilaggr(j) > 0).and. (abs(val(k)) > cpling)) then
else ip = k
ils(n) = ils(n) + 1 cpling = abs(val(k))
end if end if
end if end if
enddo enddo
if (debug_level >= psb_debug_outer_) then if (ip > 0) then
write(debug_unit,*) me,' ',trim(name),& ilaggr(i) = ilaggr(icol(ip))
& 'Phase 1: number of aggregates ',naggr end if
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 1: nodes aggregated ',sum(ils)
end if end if
end do step2
recovery=.false.
do i=1, nr
if (ilaggr(i) < 0) then
! !
! Now some silly rule to break ties: ! Phase three: sweep over leftovers, if any
! Group with adjacent aggregate.
! !
isz = nr+1 step3: do ii=1,nr
ia = -1 i = idxs(ii)
cpling = zzero
if (ilaggr(i) == -(nr+1)) then
call a%csget(i,i,nz,irow,icol,val,info) call a%csget(i,i,nz,irow,icol,val,info)
if (info /= psb_success_) then if (info /= psb_success_) then
info=psb_err_from_subroutine_ info=psb_err_from_subroutine_
call psb_errpush(info,name,a_err='psb_sp_getrow') call psb_errpush(info,name,a_err='psb_sp_getrow')
goto 9999 goto 9999
end if end if
!
do j=1, nz ! Find the most strongly connected neighbour that is
k = icol(j) ! already aggregated, if any, and join its aggregate
if ((1<=k).and.(k<=nr).and.(k /= i)) then !
tcl = abs(val(j)) / sqrt(abs(diag(i)*diag(k))) cpling = dzero
if (abs(val(j)) > theta*sqrt(abs(diag(i)*diag(k)))) then ip = 0
!!$ if (tcl > theta) then do k=1, nz
n = ilaggr(k) j = icol(k)
if (n>0) then if ((1<=j).and.(j<=nr)) then
if (n>naggr) then if ((abs(val(k)) > theta*sqrt(abs(diag(i)*diag(j))))&
info=psb_err_internal_error_ & .and. (ilaggr(j) < 0)) then
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr 2 ?') ip = ip + 1
goto 9999 icol(ip) = icol(k)
end if
if ((abs(val(j))>cpling) .or. &
& ((abs(val(j)) == cpling).and. (ils(n) < isz))) then
!!$ if ((tcl > cpling) .or. ((tcl == cpling).and. (ils(n) < isz))) then
ia = n
isz = ils(n)
cpling = abs(val(j))
!!$ cpling = tcl
endif
endif
end if end if
end if end if
enddo enddo
if (ip > 0) then
if (ia == -1) then icnt = icnt + 1
! At this point, the easiest thing is to start a new aggregate
naggr = naggr + 1 naggr = naggr + 1
ilaggr(i) = naggr ilaggr(i) = naggr
ils(ilaggr(i)) = 1 do k=1, ip
ilaggr(icol(k)) = naggr
end do
else else
!
ilaggr(i) = ia ! This should not happen: we did not even connect with ourselves.
! Create an isolate anyway.
if (ia>naggr) then !
info=psb_err_internal_error_ naggr = naggr + 1
call psb_errpush(info,name,a_err='loc_Aggregate: n > naggr ? ') ilaggr(i) = naggr
goto 9999
end if end if
ils(ia) = ils(ia) + 1
end if end if
end do step3
end if
end do
if (debug_level >= psb_debug_outer_) then
if (recovery) then
write(debug_unit,*) me,' ',trim(name),&
& 'Had to recover from strange situation in loc_aggregate.'
write(debug_unit,*) me,' ',trim(name),&
& 'Perhaps an unsymmetric pattern?'
endif
write(debug_unit,*) me,' ',trim(name),&
& 'Phase 2: number of aggregates ',naggr,sum(ils)
do i=1, naggr
write(debug_unit,*) me,' ',trim(name),&
& 'Size of aggregate ',i,' :',count(ilaggr == i), ils(i)
enddo
write(debug_unit,*) me,' ',trim(name),&
& maxval(ils(1:naggr))
write(debug_unit,*) me,' ',trim(name),&
& 'Leftovers ',count(ilaggr<0), ' in ',nlp,' loops'
end if
if (count(ilaggr<0) >0) then if (count(ilaggr<0) >0) then
info=psb_err_internal_error_ info=psb_err_internal_error_
@ -299,12 +256,6 @@ subroutine mld_z_dec_map_bld(iorder,theta,a,desc_a,nlaggr,ilaggr,info)
goto 9999 goto 9999
endif endif
deallocate(ils,neigh,stat=info)
if (info /= psb_success_) then
info=psb_err_alloc_dealloc_
call psb_errpush(info,name)
goto 9999
end if
if (naggr > ncol) then if (naggr > ncol) then
write(0,*) name,'Error : naggr > ncol',naggr,ncol write(0,*) name,'Error : naggr > ncol',naggr,ncol
info=psb_err_internal_error_ info=psb_err_internal_error_

Loading…
Cancel
Save