|
|
@ -16,23 +16,9 @@ subroutine psb_dneigh(a,idx,neigh,n,info,lev)
|
|
|
|
integer, pointer :: neigh(:) ! the neighbours
|
|
|
|
integer, pointer :: neigh(:) ! the neighbours
|
|
|
|
integer, optional :: lev ! level of neighbours to find
|
|
|
|
integer, optional :: lev ! level of neighbours to find
|
|
|
|
|
|
|
|
|
|
|
|
interface psb_spgtrow
|
|
|
|
|
|
|
|
subroutine psb_dspgtrow(irw,a,b,info,append,iren,lrw)
|
|
|
|
|
|
|
|
use psb_spmat_type
|
|
|
|
|
|
|
|
type(psb_dspmat_type), intent(in) :: a
|
|
|
|
|
|
|
|
integer, intent(in) :: irw
|
|
|
|
|
|
|
|
type(psb_dspmat_type), intent(inout) :: b
|
|
|
|
|
|
|
|
logical, intent(in), optional :: append
|
|
|
|
|
|
|
|
integer, intent(in), target, optional :: iren(:)
|
|
|
|
|
|
|
|
integer, intent(in), optional :: lrw
|
|
|
|
|
|
|
|
integer, intent(out) :: info
|
|
|
|
|
|
|
|
end subroutine psb_dspgtrow
|
|
|
|
|
|
|
|
end interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type(psb_dspmat_type) :: atmp
|
|
|
|
|
|
|
|
integer, pointer :: tmpn(:)
|
|
|
|
integer, pointer :: tmpn(:)
|
|
|
|
integer :: level, dim, i, j, k, r, c, brow,&
|
|
|
|
integer :: level, dim, i, j, k, r, c, brow,&
|
|
|
|
& elem_pt, ii, n1, col_idx, ne, err_act
|
|
|
|
& elem_pt, ii, n1, col_idx, ne, err_act, nn, nidx
|
|
|
|
character(len=20) :: name, ch_err
|
|
|
|
character(len=20) :: name, ch_err
|
|
|
|
|
|
|
|
|
|
|
|
name='psb_dneigh'
|
|
|
|
name='psb_dneigh'
|
|
|
@ -52,105 +38,245 @@ subroutine psb_dneigh(a,idx,neigh,n,info,lev)
|
|
|
|
level=1
|
|
|
|
level=1
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
if ((a%fida /= 'CSR')) then
|
|
|
|
call psb_dneigh1l(a,idx,neigh,n)
|
|
|
|
|
|
|
|
|
|
|
|
call psb_spall(atmp,1,info)
|
|
|
|
|
|
|
|
if(info.ne.0) then
|
|
|
|
|
|
|
|
call psb_errpush(4010,name)
|
|
|
|
|
|
|
|
goto 9999
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
call psb_spgtrow(idx,a,atmp,info)
|
|
|
|
|
|
|
|
if(info.ne.0) then
|
|
|
|
|
|
|
|
call psb_errpush(4010,name)
|
|
|
|
|
|
|
|
goto 9999
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
dim=atmp%infoa(psb_nnz_)
|
|
|
|
|
|
|
|
allocate(tmpn(dim))
|
|
|
|
|
|
|
|
tmpn(1:dim)=atmp%ia2(1:dim)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(level.eq.2) then
|
|
|
|
if(level.eq.2) then
|
|
|
|
do i=1,dim
|
|
|
|
allocate(tmpn(1))
|
|
|
|
if ((1<=tmpn(i)).and.(tmpn(i)<=a%m).and.(tmpn(i).ne.idx)) then
|
|
|
|
n1=n
|
|
|
|
call psb_spgtrow(tmpn(i),a,atmp,info,append=.true.)
|
|
|
|
do i=1,n1
|
|
|
|
if(info.ne.0) then
|
|
|
|
nidx=neigh(i)
|
|
|
|
call psb_errpush(4010,name)
|
|
|
|
if((nidx.ne.idx).and.(nidx.gt.0).and.(nidx.le.a%m)) then
|
|
|
|
goto 9999
|
|
|
|
call psb_dneigh1l(a,nidx,tmpn,nn)
|
|
|
|
end if
|
|
|
|
if((n+nn).gt.size(neigh)) call psb_realloc(n+nn,neigh,info)
|
|
|
|
|
|
|
|
neigh(n+1:n+nn)=tmpn(1:nn)
|
|
|
|
|
|
|
|
n=n+nn
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
call psb_erractionrestore(err_act)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
dim=atmp%infoa(psb_nnz_)
|
|
|
|
9999 continue
|
|
|
|
if(dim.gt.size(neigh)) &
|
|
|
|
call psb_erractionrestore(err_act)
|
|
|
|
& call psb_realloc(dim,neigh,info)
|
|
|
|
if (err_act.eq.act_abort) then
|
|
|
|
if(info.ne.0) then
|
|
|
|
call psb_error()
|
|
|
|
call psb_errpush(4010,name)
|
|
|
|
return
|
|
|
|
goto 9999
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
call psb_spfree(atmp,info)
|
|
|
|
|
|
|
|
if(info.ne.0) then
|
|
|
|
|
|
|
|
call psb_errpush(4010,name)
|
|
|
|
|
|
|
|
goto 9999
|
|
|
|
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
call psb_nullify_sp(atmp)
|
|
|
|
return
|
|
|
|
deallocate(tmpn)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if(a%fida.eq.'CSR') then
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dim=0
|
|
|
|
contains
|
|
|
|
if(level.eq.1) dim=(a%ia2(idx+1)-a%ia2(idx))
|
|
|
|
|
|
|
|
if(dim >size(neigh)) call psb_realloc(dim,neigh,info)
|
|
|
|
subroutine psb_dneigh1l(a,idx,neigh,n)
|
|
|
|
if(info.ne.izero) then
|
|
|
|
|
|
|
|
info=4010
|
|
|
|
use psb_realloc_mod
|
|
|
|
ch_err='psrealloc'
|
|
|
|
use psb_const_mod
|
|
|
|
call psb_errpush(info,name,a_err=ch_err)
|
|
|
|
use psb_spmat_type
|
|
|
|
goto 9999
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type(psb_dspmat_type), intent(in) :: a ! the sparse matrix
|
|
|
|
|
|
|
|
integer, intent(in) :: idx ! the index whose neighbours we want to find
|
|
|
|
|
|
|
|
integer, intent(out) :: n ! the number of neighbours and the info
|
|
|
|
|
|
|
|
integer, pointer :: neigh(:) ! the neighbours
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select case(a%fida(1:3))
|
|
|
|
|
|
|
|
case('CSR')
|
|
|
|
|
|
|
|
call csr_dneigh1l(a,idx,neigh,n)
|
|
|
|
|
|
|
|
case('COO')
|
|
|
|
|
|
|
|
call coo_dneigh1l(a,idx,neigh,n)
|
|
|
|
|
|
|
|
case('JAD')
|
|
|
|
|
|
|
|
call jad_dneigh1l(a,idx,neigh,n)
|
|
|
|
|
|
|
|
end select
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end subroutine psb_dneigh1l
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subroutine csr_dneigh1l(a,idx,neigh,n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use psb_realloc_mod
|
|
|
|
|
|
|
|
use psb_const_mod
|
|
|
|
|
|
|
|
use psb_spmat_type
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type(psb_dspmat_type), intent(in) :: a ! the sparse matrix
|
|
|
|
|
|
|
|
integer, intent(in) :: idx ! the index whose neighbours we want to find
|
|
|
|
|
|
|
|
integer, intent(out) :: n ! the number of neighbours and the info
|
|
|
|
|
|
|
|
integer, pointer :: neigh(:) ! the neighbours
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
integer :: dim, i, iidx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(a%pl(1).ne.0) then
|
|
|
|
|
|
|
|
iidx=a%pl(idx)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
iidx=idx
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dim=a%ia2(iidx+1)-a%ia2(iidx)
|
|
|
|
|
|
|
|
if(dim.gt.size(neigh)) call psb_realloc(dim,neigh,info)
|
|
|
|
|
|
|
|
|
|
|
|
n=0
|
|
|
|
n=0
|
|
|
|
if(level.eq.1) then
|
|
|
|
do i=a%ia2(iidx), a%ia2(iidx+1)-1
|
|
|
|
do i=a%ia2(idx), a%ia2(idx+1)-1
|
|
|
|
|
|
|
|
n=n+1
|
|
|
|
n=n+1
|
|
|
|
neigh(n)=a%ia1(i)
|
|
|
|
neigh(n)=a%ia1(i)
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
end subroutine csr_dneigh1l
|
|
|
|
|
|
|
|
|
|
|
|
do i=a%ia2(idx), a%ia2(idx+1)-1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
j=a%ia1(i)
|
|
|
|
subroutine coo_dneigh1l(a,idx,neigh,n)
|
|
|
|
if ((1<=j).and.(j<=a%m).and.(j.ne.idx)) then
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dim=dim+ a%ia2(j+1)-a%ia2(j)
|
|
|
|
use psb_realloc_mod
|
|
|
|
if(dim.gt.size(neigh)) call psb_realloc(dim,neigh,info)
|
|
|
|
use psb_const_mod
|
|
|
|
if(info.ne.izero) then
|
|
|
|
use psb_spmat_type
|
|
|
|
info=4010
|
|
|
|
implicit none
|
|
|
|
ch_err='psrealloc'
|
|
|
|
|
|
|
|
call psb_errpush(info,name,a_err=ch_err)
|
|
|
|
|
|
|
|
goto 9999
|
|
|
|
type(psb_dspmat_type), intent(in) :: a ! the sparse matrix
|
|
|
|
|
|
|
|
integer, intent(in) :: idx ! the index whose neighbours we want to find
|
|
|
|
|
|
|
|
integer, intent(out) :: n ! the number of neighbours and the info
|
|
|
|
|
|
|
|
integer, pointer :: neigh(:) ! the neighbours
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
integer :: dim, i, iidx, ip, nza
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(a%pl(1).ne.0) then
|
|
|
|
|
|
|
|
iidx=a%pl(idx)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
iidx=idx
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
do k=a%ia2(j), a%ia2(j+1)-1
|
|
|
|
nza=a%infoa(psb_nnz_)
|
|
|
|
n=n+1
|
|
|
|
|
|
|
|
neigh(n)=a%ia1(k)
|
|
|
|
if (a%infoa(psb_srtd_) == psb_isrtdcoo_) then
|
|
|
|
|
|
|
|
call ibsrch(ip,iidx,nza,a%ia1)
|
|
|
|
|
|
|
|
if (ip /= -1) then
|
|
|
|
|
|
|
|
! bring ip backward to the beginning of the row
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
if (ip < 2) exit
|
|
|
|
|
|
|
|
if (a%ia1(ip-1) == iidx) then
|
|
|
|
|
|
|
|
ip = ip -1
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
exit
|
|
|
|
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dim=0
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
if(a%ia1(ip).eq.iidx) then
|
|
|
|
|
|
|
|
dim=dim+1
|
|
|
|
|
|
|
|
if(dim.gt.size(neigh)) call psb_realloc(dim*3/2,neigh,info)
|
|
|
|
|
|
|
|
neigh(dim)=a%ia2(ip)
|
|
|
|
|
|
|
|
ip=ip+1
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
exit
|
|
|
|
|
|
|
|
end if
|
|
|
|
end do
|
|
|
|
end do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dim=0
|
|
|
|
|
|
|
|
do i=1,nza
|
|
|
|
|
|
|
|
if(a%ia1(i).eq.iidx) then
|
|
|
|
|
|
|
|
dim=dim+1
|
|
|
|
|
|
|
|
if(dim.gt.size(neigh)) call psb_realloc(dim*3/2,neigh,info)
|
|
|
|
|
|
|
|
neigh(dim)=a%ia2(ip)
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
end do
|
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n=dim
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end subroutine coo_dneigh1l
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subroutine jad_dneigh1l(a,idx,neigh,n)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use psb_realloc_mod
|
|
|
|
|
|
|
|
use psb_const_mod
|
|
|
|
|
|
|
|
use psb_spmat_type
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type(psb_dspmat_type), intent(in) :: a ! the sparse matrix
|
|
|
|
|
|
|
|
integer, intent(in) :: idx ! the index whose neighbours we want to find
|
|
|
|
|
|
|
|
integer, intent(out) :: n ! the number of neighbours and the info
|
|
|
|
|
|
|
|
integer, pointer :: neigh(:) ! the neighbours
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
integer :: dim, i, iidx, ip, nza
|
|
|
|
|
|
|
|
integer, pointer :: ia1(:), ia2(:), ia3(:),&
|
|
|
|
|
|
|
|
& ja(:), ka(:)
|
|
|
|
|
|
|
|
integer :: png, pia, pja, ipx, blk, rb, row, k_pt, npg, col, ng
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(a%pl(1).ne.0) then
|
|
|
|
|
|
|
|
iidx=a%pl(idx)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
iidx=idx
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
|
|
|
call psb_erractionrestore(err_act)
|
|
|
|
nza=a%infoa(psb_nnz_)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9999 continue
|
|
|
|
png = a%ia2(1) ! points to the number of blocks
|
|
|
|
call psb_erractionrestore(err_act)
|
|
|
|
pia = a%ia2(2) ! points to the beginning of ia(3,png)
|
|
|
|
if (err_act.eq.act_abort) then
|
|
|
|
pja = a%ia2(3) ! points to the beginning of ja(:)
|
|
|
|
call psb_error()
|
|
|
|
|
|
|
|
return
|
|
|
|
ng = a%ia2(png) ! the number of blocks
|
|
|
|
|
|
|
|
ja => a%ia2(pja:) ! the array containing the pointers to ka and aspk
|
|
|
|
|
|
|
|
ka => a%ia1(:) ! the array containing the column indices
|
|
|
|
|
|
|
|
ia1 => a%ia2(pia:pja-1:3) ! the array containing the first row index of each block
|
|
|
|
|
|
|
|
ia2 => a%ia2(pia+1:pja-1:3) ! the array containing a pointer to the pos. in ja to the first jad column
|
|
|
|
|
|
|
|
ia3 => a%ia2(pia+2:pja-1:3) ! the array containing a pointer to the pos. in ja to the first csr column
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i=0
|
|
|
|
|
|
|
|
dim=0
|
|
|
|
|
|
|
|
blkfnd: do
|
|
|
|
|
|
|
|
i=i+1
|
|
|
|
|
|
|
|
if(ia1(i).eq.iidx) then
|
|
|
|
|
|
|
|
blk=i
|
|
|
|
|
|
|
|
dim=dim+ia3(i)-ia2(i)
|
|
|
|
|
|
|
|
ipx = ia1(i) ! the first row index of the block
|
|
|
|
|
|
|
|
rb = iidx-ipx ! the row offset within the block
|
|
|
|
|
|
|
|
row = ia3(i)+rb
|
|
|
|
|
|
|
|
dim = dim+ja(row+1)-ja(row)
|
|
|
|
|
|
|
|
exit blkfnd
|
|
|
|
|
|
|
|
else if(ia1(i).gt.iidx) then
|
|
|
|
|
|
|
|
blk=i-1
|
|
|
|
|
|
|
|
dim=dim+ia3(i-1)-ia2(i-1)
|
|
|
|
|
|
|
|
ipx = ia1(i-1) ! the first row index of the block
|
|
|
|
|
|
|
|
rb = iidx-ipx ! the row offset within the block
|
|
|
|
|
|
|
|
row = ia3(i-1)+rb
|
|
|
|
|
|
|
|
dim = dim+ja(row+1)-ja(row)
|
|
|
|
|
|
|
|
exit blkfnd
|
|
|
|
end if
|
|
|
|
end if
|
|
|
|
return
|
|
|
|
end do blkfnd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(dim.gt.size(neigh)) call psb_realloc(dim,neigh,info)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ipx = ia1(blk) ! the first row index of the block
|
|
|
|
|
|
|
|
k_pt= ia2(blk) ! the pointer to the beginning of a column in ja
|
|
|
|
|
|
|
|
rb = iidx-ipx ! the row offset within the block
|
|
|
|
|
|
|
|
npg = ja(k_pt+1)-ja(k_pt) ! the number of rows in the block
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k=0
|
|
|
|
|
|
|
|
do col = ia2(blk), ia3(blk)-1
|
|
|
|
|
|
|
|
k=k+1
|
|
|
|
|
|
|
|
neigh(k) = ka(ja(col)+rb)
|
|
|
|
|
|
|
|
end do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
! extract second part of the row from the csr tail
|
|
|
|
|
|
|
|
row=ia3(blk)+rb
|
|
|
|
|
|
|
|
do j=ja(row), ja(row+1)-1
|
|
|
|
|
|
|
|
k=k+1
|
|
|
|
|
|
|
|
neigh(k) = ka(j)
|
|
|
|
|
|
|
|
end do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n=k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end subroutine jad_dneigh1l
|
|
|
|
|
|
|
|
|
|
|
|
end subroutine psb_dneigh
|
|
|
|
end subroutine psb_dneigh
|
|
|
|
|
|
|
|
|
|
|
|