psblas2-dev:

base/comm/psb_dscatter.F90
 base/comm/psb_iscatter.F90
 base/comm/psb_zscatter.F90

Cleaned up scatter routines from embarassing bugs.
psblas3-type-indexed
Salvatore Filippone 17 years ago
parent d2bcfbdf95
commit 4e0c233a48

@ -89,20 +89,20 @@ subroutine psb_dscatterm(globx, locx, desc_a, info, iroot)
endif endif
if (present(iroot)) then if (present(iroot)) then
root = iroot root = iroot
if((root < -1).or.(root > np)) then if((root < -1).or.(root > np)) then
info=30 info=30
int_err(1:2)=(/5,root/) int_err(1:2)=(/5,root/)
call psb_errpush(info,name,i_err=int_err) call psb_errpush(info,name,i_err=int_err)
goto 9999 goto 9999
end if end if
else else
root = -1 root = -1
end if end if
if (root == -1) then if (root == -1) then
iiroot = psb_root_ iiroot = psb_root_
endif endif
iglobx = 1 iglobx = 1
jglobx = 1 jglobx = 1
ilocx = 1 ilocx = 1
@ -112,7 +112,7 @@ subroutine psb_dscatterm(globx, locx, desc_a, info, iroot)
m = psb_cd_get_global_rows(desc_a) m = psb_cd_get_global_rows(desc_a)
n = psb_cd_get_global_cols(desc_a) n = psb_cd_get_global_cols(desc_a)
lock=size(locx,2)-jlocx+1 lock=size(locx,2)-jlocx+1
globk=size(globx,2)-jglobx+1 globk=size(globx,2)-jglobx+1
maxk=min(lock,globk) maxk=min(lock,globk)
@ -126,7 +126,7 @@ subroutine psb_dscatterm(globx, locx, desc_a, info, iroot)
m = psb_cd_get_global_rows(desc_a) m = psb_cd_get_global_rows(desc_a)
n = psb_cd_get_global_cols(desc_a) n = psb_cd_get_global_cols(desc_a)
call psb_bcast(ictxt,k,root=iiroot) call psb_bcast(ictxt,k,root=iiroot)
! there should be a global check on k here!!! ! there should be a global check on k here!!!
@ -134,83 +134,85 @@ subroutine psb_dscatterm(globx, locx, desc_a, info, iroot)
call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info) call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info)
if (info == 0) call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx) if (info == 0) call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='psb_chk(glob)vect' ch_err='psb_chk(glob)vect'
call psb_errpush(info,name,a_err=ch_err) call psb_errpush(info,name,a_err=ch_err)
goto 9999 goto 9999
end if end if
if ((ilx /= 1).or.(iglobx /= 1)) then if ((ilx /= 1).or.(iglobx /= 1)) then
info=3040 info=3040
call psb_errpush(info,name) call psb_errpush(info,name)
goto 9999 goto 9999
end if end if
nrow=psb_cd_get_local_rows(desc_a) nrow=psb_cd_get_local_rows(desc_a)
if(root == -1) then if ((root == -1).or.(np==1)) then
! extract my chunk ! extract my chunk
do j=1,k do j=1,k
do i=1, nrow do i=1, nrow
idx=desc_a%loc_to_glob(i) idx=desc_a%loc_to_glob(i)
locx(i,jlocx+j-1)=globx(idx,jglobx+j-1) locx(i,jlocx+j-1)=globx(idx,jglobx+j-1)
end do end do
end do end do
else else
call psb_get_rank(rootrank,ictxt,root) call psb_get_rank(rootrank,ictxt,root)
end if
! root has to gather size information ! root has to gather size information
allocate(displ(np),all_dim(np),stat=info) allocate(displ(np),all_dim(np),stat=info)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='Allocate' ch_err='Allocate'
call psb_errpush(info,name,a_err=ch_err) call psb_errpush(info,name,a_err=ch_err)
goto 9999 goto 9999
end if end if
call mpi_gather(nrow,1,mpi_integer,all_dim,& call mpi_gather(nrow,1,mpi_integer,all_dim,&
& np,mpi_integer,rootrank,icomm,info) & 1,mpi_integer,rootrank,icomm,info)
displ(1)=1 if (me == root) then
displ(2:)=all_dim(1:np-1)+1 displ(1)=0
do i=2,np
! root has to gather loc_glob from each process displ(i)=displ(i-1)+all_dim(i-1)
if(me == root) then end do
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)),stat=info)
if(info /= 0) then ! root has to gather loc_glob from each process
info=4010 allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)),stat=info)
ch_err='Allocate' if(info /= 0) then
call psb_errpush(info,name,a_err=ch_err) info=4010
goto 9999 ch_err='Allocate'
end if call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
end if end if
call mpi_gatherv(desc_a%loc_to_glob,nrow,&
& mpi_integer,l_t_g_all,all_dim,&
& displ,mpi_integer,rootrank,icomm,info)
call mpi_gatherv(desc_a%loc_to_glob,nrow,&
do c=1, k & mpi_integer,l_t_g_all,all_dim,&
! prepare vector to scatter & displ,mpi_integer,rootrank,icomm,info)
if(me == root) then
do c=1, k
! prepare vector to scatter
if(me == root) then
do i=1,np do i=1,np
pos=displ(i) pos=displ(i)
do j=1, all_dim(i) do j=1, all_dim(i)
idx=l_t_g_all(pos+j-1) idx=l_t_g_all(pos+j)
scatterv(pos+j-1)=globx(idx,jglobx+c-1) scatterv(pos+j)=globx(idx,jglobx+c-1)
end do end do
end do end do
end if end if
! scatter !!!
call mpi_scatterv(scatterv,all_dim,displ,&
& mpi_double_precision,locx(1,jlocx+c-1),nrow,&
& mpi_double_precision,rootrank,icomm,info)
end do ! scatter !!!
call mpi_scatterv(scatterv,all_dim,displ,&
deallocate(all_dim, l_t_g_all, displ, scatterv) & mpi_double_precision,locx(1,jlocx+c-1),nrow,&
& mpi_double_precision,rootrank,icomm,info)
end do
if (me==root) deallocate(all_dim, l_t_g_all, displ, scatterv)
end if
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
return return
@ -219,8 +221,8 @@ subroutine psb_dscatterm(globx, locx, desc_a, info, iroot)
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
if (err_act == psb_act_abort_) then if (err_act == psb_act_abort_) then
call psb_error(ictxt) call psb_error(ictxt)
return return
end if end if
return return
@ -299,15 +301,18 @@ subroutine psb_dscatterv(globx, locx, desc_a, info, iroot)
& ilocx, jlocx, lda_locx, lda_globx, root, k, icomm, myrank,& & ilocx, jlocx, lda_locx, lda_globx, root, k, icomm, myrank,&
& rootrank, pos, ilx, jlx & rootrank, pos, ilx, jlx
real(psb_dpk_), allocatable :: scatterv(:) real(psb_dpk_), allocatable :: scatterv(:)
integer, allocatable :: displ(:), l_t_g_all(:), all_dim(:) integer, allocatable :: displ(:), l_t_g_all(:), all_dim(:)
character(len=20) :: name, ch_err character(len=20) :: name, ch_err
integer :: debug_level, debug_unit
name='psb_scatterv' name='psb_scatterv'
if(psb_get_errstatus() /= 0) return if (psb_get_errstatus() /= 0) return
info=0 info=0
call psb_erractionsave(err_act) call psb_erractionsave(err_act)
ictxt=psb_cd_get_context(desc_a) ictxt=psb_cd_get_context(desc_a)
debug_unit = psb_get_debug_unit()
debug_level = psb_get_debug_level()
! check on blacs grid ! check on blacs grid
call psb_info(ictxt, me, np) call psb_info(ictxt, me, np)
@ -332,12 +337,16 @@ subroutine psb_dscatterv(globx, locx, desc_a, info, iroot)
call psb_get_mpicomm(ictxt,icomm) call psb_get_mpicomm(ictxt,icomm)
call psb_get_rank(myrank,ictxt,me) call psb_get_rank(myrank,ictxt,me)
iglobx = 1
jglobx = 1
ilocx = 1
jlocx = 1
lda_globx = size(globx) lda_globx = size(globx)
lda_locx = size(locx) lda_locx = size(locx)
m = psb_cd_get_global_rows(desc_a) m = psb_cd_get_global_rows(desc_a)
n = psb_cd_get_global_cols(desc_a) n = psb_cd_get_global_cols(desc_a)
k = 1 k = 1
! there should be a global check on k here!!! ! there should be a global check on k here!!!
@ -357,51 +366,59 @@ subroutine psb_dscatterv(globx, locx, desc_a, info, iroot)
goto 9999 goto 9999
end if end if
nrow=psb_cd_get_local_rows(desc_a) nrow = psb_cd_get_local_rows(desc_a)
if(root == -1) then if ((root == -1).or.(np==1)) then
! extract my chunk ! extract my chunk
do i=1, nrow do i=1, nrow
idx=desc_a%loc_to_glob(i) idx=desc_a%loc_to_glob(i)
locx(i)=globx(idx) locx(i)=globx(idx)
end do end do
else else
call psb_get_rank(rootrank,ictxt,root) call psb_get_rank(rootrank,ictxt,root)
end if
! root has to gather size information
allocate(displ(np),all_dim(np))
call mpi_gather(nrow,1,mpi_integer,all_dim,&
& np,mpi_integer,rootrank,icomm,info)
displ(1)=1
displ(2:)=all_dim(1:np-1)+1
! root has to gather loc_glob from each process ! root has to gather size information
if(me == root) then allocate(displ(np),all_dim(np))
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)))
end if call mpi_gather(nrow,1,mpi_integer,all_dim,&
& 1,mpi_integer,rootrank,icomm,info)
call mpi_gatherv(desc_a%loc_to_glob,nrow,&
& mpi_integer,l_t_g_all,all_dim,& if(me == root) then
& displ,mpi_integer,rootrank,icomm,info) displ(1)=0
do i=2,np
! prepare vector to scatter displ(i)=displ(i-1) + all_dim(i-1)
if(me == root) then end do
do i=1,np if (debug_level >= psb_debug_inner_) then
write(debug_unit,*) me,' ',trim(name),' displ:',displ(1:np), &
&' dim',all_dim(1:np), sum(all_dim)
endif
! root has to gather loc_glob from each process
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)))
end if
call mpi_gatherv(desc_a%loc_to_glob,nrow,&
& mpi_integer,l_t_g_all,all_dim,&
& displ,mpi_integer,rootrank,icomm,info)
! prepare vector to scatter
if (me == root) then
do i=1,np
pos=displ(i) pos=displ(i)
do j=1, all_dim(i) do j=1, all_dim(i)
idx=l_t_g_all(pos+j-1) idx=l_t_g_all(pos+j)
scatterv(pos+j-1)=globx(idx) scatterv(pos+j)=globx(idx)
end do end do
end do end do
end if end if
call mpi_scatterv(scatterv,all_dim,displ,& call mpi_scatterv(scatterv,all_dim,displ,&
& mpi_double_precision,locx,nrow,& & mpi_double_precision,locx,nrow,&
& mpi_double_precision,rootrank,icomm,info) & mpi_double_precision,rootrank,icomm,info)
deallocate(all_dim, l_t_g_all, displ, scatterv) if (me==root) deallocate(all_dim, l_t_g_all, displ, scatterv)
end if
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
return return
@ -410,8 +427,8 @@ subroutine psb_dscatterv(globx, locx, desc_a, info, iroot)
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
if (err_act == psb_act_abort_) then if (err_act == psb_act_abort_) then
call psb_error(ictxt) call psb_error(ictxt)
return return
end if end if
return return

@ -88,20 +88,20 @@ subroutine psb_iscatterm(globx, locx, desc_a, info, iroot)
endif endif
if (present(iroot)) then if (present(iroot)) then
root = iroot root = iroot
if((root < -1).or.(root > np)) then if((root < -1).or.(root > np)) then
info=30 info=30
int_err(1:2)=(/5,root/) int_err(1:2)=(/5,root/)
call psb_errpush(info,name,i_err=int_err) call psb_errpush(info,name,i_err=int_err)
goto 9999 goto 9999
end if end if
else else
root = -1 root = -1
end if end if
if (root == -1) then if (root == -1) then
iiroot = psb_root_ iiroot = psb_root_
endif endif
iglobx = 1 iglobx = 1
jglobx = 1 jglobx = 1
ilocx = 1 ilocx = 1
@ -111,7 +111,7 @@ subroutine psb_iscatterm(globx, locx, desc_a, info, iroot)
m = psb_cd_get_global_rows(desc_a) m = psb_cd_get_global_rows(desc_a)
n = psb_cd_get_global_cols(desc_a) n = psb_cd_get_global_cols(desc_a)
lock=size(locx,2)-jlocx+1 lock=size(locx,2)-jlocx+1
globk=size(globx,2)-jglobx+1 globk=size(globx,2)-jglobx+1
maxk=min(lock,globk) maxk=min(lock,globk)
@ -125,90 +125,93 @@ subroutine psb_iscatterm(globx, locx, desc_a, info, iroot)
m = psb_cd_get_global_rows(desc_a) m = psb_cd_get_global_rows(desc_a)
n = psb_cd_get_global_cols(desc_a) n = psb_cd_get_global_cols(desc_a)
call psb_bcast(ictxt,k,root=iiroot) call psb_bcast(ictxt,k,root=iiroot)
! there should be a global check on k here!!! ! there should be a global check on k here!!!
call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info) call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info)
if (info == 0) call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx) if (info == 0) call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='psb_chk(glob)vect' ch_err='psb_chk(glob)vect'
call psb_errpush(info,name,a_err=ch_err) call psb_errpush(info,name,a_err=ch_err)
goto 9999 goto 9999
end if end if
if ((ilx /= 1).or.(iglobx /= 1)) then if ((ilx /= 1).or.(iglobx /= 1)) then
info=3040 info=3040
call psb_errpush(info,name) call psb_errpush(info,name)
goto 9999 goto 9999
end if end if
nrow=psb_cd_get_local_rows(desc_a) nrow=psb_cd_get_local_rows(desc_a)
if(root == -1) then if ((root == -1).or.(np==1)) then
! extract my chunk ! extract my chunk
do j=1,k do j=1,k
do i=1, nrow do i=1, nrow
idx=desc_a%loc_to_glob(i) idx=desc_a%loc_to_glob(i)
locx(i,jlocx+j-1)=globx(idx,jglobx+j-1) locx(i,jlocx+j-1)=globx(idx,jglobx+j-1)
end do end do
end do end do
else else
call psb_get_rank(rootrank,ictxt,root) call psb_get_rank(rootrank,ictxt,root)
end if
! root has to gather size information ! root has to gather size information
allocate(displ(np),all_dim(np),stat=info) allocate(displ(np),all_dim(np),stat=info)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='Allocate' ch_err='Allocate'
call psb_errpush(info,name,a_err=ch_err) call psb_errpush(info,name,a_err=ch_err)
goto 9999 goto 9999
end if end if
call mpi_gather(nrow,1,mpi_integer,all_dim,& call mpi_gather(nrow,1,mpi_integer,all_dim,&
& np,mpi_integer,rootrank,icomm,info) & 1,mpi_integer,rootrank,icomm,info)
displ(1)=1 if (me == root) then
displ(2:)=all_dim(1:np-1)+1 displ(1)=0
do i=2,np
! root has to gather loc_glob from each process displ(i)=displ(i-1)+all_dim(i-1)
if(me == root) then end do
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)),stat=info)
if(info /= 0) then ! root has to gather loc_glob from each process
info=4010 allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)),stat=info)
ch_err='Allocate' if(info /= 0) then
call psb_errpush(info,name,a_err=ch_err) info=4010
goto 9999 ch_err='Allocate'
end if call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
end if end if
call mpi_gatherv(desc_a%loc_to_glob,nrow,& call mpi_gatherv(desc_a%loc_to_glob,nrow,&
& mpi_integer,l_t_g_all,all_dim,& & mpi_integer,l_t_g_all,all_dim,&
& displ,mpi_integer,rootrank,icomm,info) & displ,mpi_integer,rootrank,icomm,info)
do c=1, k do c=1, k
! prepare vector to scatter ! prepare vector to scatter
if(me == root) then if(me == root) then
do i=1,np do i=1,np
pos=displ(i) pos=displ(i)
do j=1, all_dim(i) do j=1, all_dim(i)
idx=l_t_g_all(pos+j-1) idx=l_t_g_all(pos+j)
scatterv(pos+j-1)=globx(idx,jglobx+c-1) scatterv(pos+j)=globx(idx,jglobx+c-1)
end do end do
end do end do
end if end if
! scatter !!! ! scatter !!!
call mpi_scatterv(scatterv,all_dim,displ,& call mpi_scatterv(scatterv,all_dim,displ,&
& mpi_integer,locx(1,jlocx+c-1),nrow,& & mpi_integer,locx(1,jlocx+c-1),nrow,&
& mpi_integer,rootrank,icomm,info) & mpi_integer,rootrank,icomm,info)
end do end do
deallocate(all_dim, l_t_g_all, displ, scatterv) if (me==root) deallocate(all_dim, l_t_g_all, displ, scatterv)
end if
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
return return
@ -217,8 +220,8 @@ subroutine psb_iscatterm(globx, locx, desc_a, info, iroot)
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
if (err_act == psb_act_abort_) then if (err_act == psb_act_abort_) then
call psb_error(ictxt) call psb_error(ictxt)
return return
end if end if
return return
@ -299,13 +302,16 @@ subroutine psb_iscatterv(globx, locx, desc_a, info, iroot)
integer, allocatable :: scatterv(:) integer, allocatable :: scatterv(:)
integer, allocatable :: displ(:), l_t_g_all(:), all_dim(:) integer, allocatable :: displ(:), l_t_g_all(:), all_dim(:)
character(len=20) :: name, ch_err character(len=20) :: name, ch_err
integer :: debug_level, debug_unit
name='psb_scatterv' name='psb_scatterv'
if(psb_get_errstatus() /= 0) return if (psb_get_errstatus() /= 0) return
info=0 info=0
call psb_erractionsave(err_act) call psb_erractionsave(err_act)
ictxt=psb_cd_get_context(desc_a) ictxt=psb_cd_get_context(desc_a)
debug_unit = psb_get_debug_unit()
debug_level = psb_get_debug_level()
! check on blacs grid ! check on blacs grid
call psb_info(ictxt, me, np) call psb_info(ictxt, me, np)
@ -316,91 +322,102 @@ subroutine psb_iscatterv(globx, locx, desc_a, info, iroot)
endif endif
if (present(iroot)) then if (present(iroot)) then
root = iroot root = iroot
if((root < -1).or.(root > np)) then if((root < -1).or.(root > np)) then
info=30 info=30
int_err(1:2)=(/5,root/) int_err(1:2)=(/5,root/)
call psb_errpush(info,name,i_err=int_err) call psb_errpush(info,name,i_err=int_err)
goto 9999 goto 9999
end if end if
else else
root = -1 root = -1
end if end if
call psb_get_mpicomm(ictxt,icomm) call psb_get_mpicomm(ictxt,icomm)
call psb_get_rank(myrank,ictxt,me) call psb_get_rank(myrank,ictxt,me)
iglobx = 1
jglobx = 1
ilocx = 1
jlocx = 1
lda_globx = size(globx) lda_globx = size(globx)
lda_locx = size(locx) lda_locx = size(locx)
m = psb_cd_get_global_rows(desc_a) m = psb_cd_get_global_rows(desc_a)
n = psb_cd_get_global_cols(desc_a) n = psb_cd_get_global_cols(desc_a)
k = 1
k = 1
! there should be a global check on k here!!! ! there should be a global check on k here!!!
call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info) call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info)
if (info == 0) & if (info == 0) &
& call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx) & call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='psb_chk(glob)vect' ch_err='psb_chk(glob)vect'
call psb_errpush(info,name,a_err=ch_err) call psb_errpush(info,name,a_err=ch_err)
goto 9999 goto 9999
end if end if
if ((ilx /= 1).or.(iglobx /= 1)) then if ((ilx /= 1).or.(iglobx /= 1)) then
info=3040 info=3040
call psb_errpush(info,name) call psb_errpush(info,name)
goto 9999 goto 9999
end if end if
nrow=psb_cd_get_local_rows(desc_a) nrow = psb_cd_get_local_rows(desc_a)
if(root == -1) then if ((root == -1).or.(np==1)) then
! extract my chunk ! extract my chunk
do i=1, nrow do i=1, nrow
idx=desc_a%loc_to_glob(i) idx=desc_a%loc_to_glob(i)
locx(i)=globx(idx) locx(i)=globx(idx)
end do end do
else else
call psb_get_rank(rootrank,ictxt,root) call psb_get_rank(rootrank,ictxt,root)
end if
! root has to gather size information ! root has to gather size information
allocate(displ(np),all_dim(np)) allocate(displ(np),all_dim(np))
call mpi_gather(nrow,1,mpi_integer,all_dim,&
& np,mpi_integer,rootrank,icomm,info) call mpi_gather(nrow,1,mpi_integer,all_dim,&
& 1,mpi_integer,rootrank,icomm,info)
displ(1)=1
displ(2:)=all_dim(1:np-1)+1 if(me == root) then
displ(1)=0
! root has to gather loc_glob from each process do i=2,np
if(me == root) then displ(i)=displ(i-1) + all_dim(i-1)
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim))) end do
end if if (debug_level >= psb_debug_inner_) then
write(debug_unit,*) me,' ',trim(name),' displ:',displ(1:np), &
call mpi_gatherv(desc_a%loc_to_glob,nrow,& &' dim',all_dim(1:np), sum(all_dim)
& mpi_integer,l_t_g_all,all_dim,& endif
& displ,mpi_integer,rootrank,icomm,info)
! root has to gather loc_glob from each process
! prepare vector to scatter allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)))
if(me == root) then end if
do i=1,np
call mpi_gatherv(desc_a%loc_to_glob,nrow,&
& mpi_integer,l_t_g_all,all_dim,&
& displ,mpi_integer,rootrank,icomm,info)
! prepare vector to scatter
if (me == root) then
do i=1,np
pos=displ(i) pos=displ(i)
do j=1, all_dim(i) do j=1, all_dim(i)
idx=l_t_g_all(pos+j-1) idx=l_t_g_all(pos+j)
scatterv(pos+j-1)=globx(idx) scatterv(pos+j)=globx(idx)
end do end do
end do end do
end if end if
call mpi_scatterv(scatterv,all_dim,displ,& call mpi_scatterv(scatterv,all_dim,displ,&
& mpi_integer,locx,nrow,& & mpi_integer,locx,nrow,&
& mpi_integer,rootrank,icomm,info) & mpi_integer,rootrank,icomm,info)
deallocate(all_dim, l_t_g_all, displ, scatterv) if (me==root) deallocate(all_dim, l_t_g_all, displ, scatterv)
end if
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
return return
@ -409,8 +426,8 @@ subroutine psb_iscatterv(globx, locx, desc_a, info, iroot)
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
if (err_act == psb_act_abort_) then if (err_act == psb_act_abort_) then
call psb_error(ictxt) call psb_error(ictxt)
return return
end if end if
return return

@ -65,7 +65,7 @@ subroutine psb_zscatterm(globx, locx, desc_a, info, iroot)
! locals ! locals
integer :: int_err(5), ictxt, np, me, & integer :: int_err(5), ictxt, np, me,&
& err_act, m, n, i, j, idx, nrow, iiroot, iglobx, jglobx,& & err_act, m, n, i, j, idx, nrow, iiroot, iglobx, jglobx,&
& ilocx, jlocx, lda_locx, lda_globx, lock, globk, icomm, k, maxk, root, ilx,& & ilocx, jlocx, lda_locx, lda_globx, lock, globk, icomm, k, maxk, root, ilx,&
& jlx, myrank, rootrank, c, pos & jlx, myrank, rootrank, c, pos
@ -103,12 +103,10 @@ subroutine psb_zscatterm(globx, locx, desc_a, info, iroot)
iiroot = psb_root_ iiroot = psb_root_
endif endif
iglobx = 1 iglobx = 1
jglobx = 1 jglobx = 1
ilocx = 1 ilocx = 1
jlocx = 1 jlocx = 1
lda_globx = size(globx,1) lda_globx = size(globx,1)
lda_locx = size(locx, 1) lda_locx = size(locx, 1)
@ -119,10 +117,10 @@ subroutine psb_zscatterm(globx, locx, desc_a, info, iroot)
globk=size(globx,2)-jglobx+1 globk=size(globx,2)-jglobx+1
maxk=min(lock,globk) maxk=min(lock,globk)
k = maxk k = maxk
call psb_get_mpicomm(ictxt,icomm) call psb_get_mpicomm(ictxt,icomm)
call psb_get_rank(myrank,ictxt,me) call psb_get_rank(myrank,ictxt,me)
lda_globx = size(globx) lda_globx = size(globx)
lda_locx = size(locx) lda_locx = size(locx)
@ -134,8 +132,7 @@ subroutine psb_zscatterm(globx, locx, desc_a, info, iroot)
! there should be a global check on k here!!! ! there should be a global check on k here!!!
call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info) call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info)
if (info == 0) & if (info == 0) call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx)
& call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='psb_chk(glob)vect' ch_err='psb_chk(glob)vect'
@ -151,7 +148,7 @@ subroutine psb_zscatterm(globx, locx, desc_a, info, iroot)
nrow=psb_cd_get_local_rows(desc_a) nrow=psb_cd_get_local_rows(desc_a)
if(root == -1) then if ((root == -1).or.(np==1)) then
! extract my chunk ! extract my chunk
do j=1,k do j=1,k
do i=1, nrow do i=1, nrow
@ -161,59 +158,61 @@ subroutine psb_zscatterm(globx, locx, desc_a, info, iroot)
end do end do
else else
call psb_get_rank(rootrank,ictxt,root) call psb_get_rank(rootrank,ictxt,root)
end if
! root has to gather size information ! root has to gather size information
allocate(displ(np),all_dim(np),stat=info) allocate(displ(np),all_dim(np),stat=info)
if(info /= 0) then
info=4010
ch_err='Allocate'
call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
call mpi_gather(nrow,1,mpi_integer,all_dim,&
& np,mpi_integer,rootrank,icomm,info)
displ(1)=1
displ(2:)=all_dim(1:np-1)+1
! root has to gather loc_glob from each process
if(me == root) then
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)),stat=info)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='Allocate' ch_err='Allocate'
call psb_errpush(info,name,a_err=ch_err) call psb_errpush(info,name,a_err=ch_err)
goto 9999 goto 9999
end if end if
call mpi_gather(nrow,1,mpi_integer,all_dim,&
& 1,mpi_integer,rootrank,icomm,info)
end if if (me == root) then
displ(1)=0
do i=2,np
displ(i)=displ(i-1)+all_dim(i-1)
end do
call mpi_gatherv(desc_a%loc_to_glob,nrow,& ! root has to gather loc_glob from each process
& mpi_integer,l_t_g_all,all_dim,& allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)),stat=info)
& displ,mpi_integer,rootrank,icomm,info) if(info /= 0) then
info=4010
ch_err='Allocate'
call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
end if
do c=1, k call mpi_gatherv(desc_a%loc_to_glob,nrow,&
! prepare vector to scatter & mpi_integer,l_t_g_all,all_dim,&
if(me == root) then & displ,mpi_integer,rootrank,icomm,info)
do i=1,np
pos=displ(i)
do j=1, all_dim(i) do c=1, k
idx=l_t_g_all(pos+j-1) ! prepare vector to scatter
scatterv(pos+j-1)=globx(idx,jglobx+c-1) if(me == root) then
do i=1,np
pos=displ(i)
do j=1, all_dim(i)
idx=l_t_g_all(pos+j)
scatterv(pos+j)=globx(idx,jglobx+c-1)
end do
end do end do
end do end if
end if
! scatter !!! ! scatter !!!
call mpi_scatterv(scatterv,all_dim,displ,& call mpi_scatterv(scatterv,all_dim,displ,&
& mpi_double_complex,locx(1,jlocx+c-1),nrow,& & mpi_double_complex,locx(1,jlocx+c-1),nrow,&
& mpi_double_complex,rootrank,icomm,info) & mpi_double_complex,rootrank,icomm,info)
end do end do
deallocate(all_dim, l_t_g_all, displ, scatterv) if (me==root) deallocate(all_dim, l_t_g_all, displ, scatterv)
end if
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
return return
@ -304,13 +303,16 @@ subroutine psb_zscatterv(globx, locx, desc_a, info, iroot)
complex(psb_dpk_), allocatable :: scatterv(:) complex(psb_dpk_), allocatable :: scatterv(:)
integer, allocatable :: displ(:), l_t_g_all(:), all_dim(:) integer, allocatable :: displ(:), l_t_g_all(:), all_dim(:)
character(len=20) :: name, ch_err character(len=20) :: name, ch_err
integer :: debug_level, debug_unit
name='psb_scatterv' name='psb_scatterv'
if(psb_get_errstatus() /= 0) return if (psb_get_errstatus() /= 0) return
info=0 info=0
call psb_erractionsave(err_act) call psb_erractionsave(err_act)
ictxt=psb_cd_get_context(desc_a) ictxt=psb_cd_get_context(desc_a)
debug_unit = psb_get_debug_unit()
debug_level = psb_get_debug_level()
! check on blacs grid ! check on blacs grid
call psb_info(ictxt, me, np) call psb_info(ictxt, me, np)
@ -321,20 +323,24 @@ subroutine psb_zscatterv(globx, locx, desc_a, info, iroot)
endif endif
if (present(iroot)) then if (present(iroot)) then
root = iroot root = iroot
if((root < -1).or.(root > np)) then if((root < -1).or.(root > np)) then
info=30 info=30
int_err(1:2)=(/5,root/) int_err(1:2)=(/5,root/)
call psb_errpush(info,name,i_err=int_err) call psb_errpush(info,name,i_err=int_err)
goto 9999 goto 9999
end if end if
else else
root = -1 root = -1
end if end if
call psb_get_mpicomm(ictxt,icomm) call psb_get_mpicomm(ictxt,icomm)
call psb_get_rank(myrank,ictxt,me) call psb_get_rank(myrank,ictxt,me)
iglobx = 1
jglobx = 1
ilocx = 1
jlocx = 1
lda_globx = size(globx) lda_globx = size(globx)
lda_locx = size(locx) lda_locx = size(locx)
@ -342,28 +348,27 @@ subroutine psb_zscatterv(globx, locx, desc_a, info, iroot)
n = psb_cd_get_global_cols(desc_a) n = psb_cd_get_global_cols(desc_a)
k = 1 k = 1
! there should be a global check on k here!!! ! there should be a global check on k here!!!
call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info) call psb_chkglobvect(m,n,size(globx),iglobx,jglobx,desc_a,info)
if (info == 0) & if (info == 0) &
& call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx) & call psb_chkvect(m,n,size(locx),ilocx,jlocx,desc_a,info,ilx,jlx)
if(info /= 0) then if(info /= 0) then
info=4010 info=4010
ch_err='psb_chk(glob)vect' ch_err='psb_chk(glob)vect'
call psb_errpush(info,name,a_err=ch_err) call psb_errpush(info,name,a_err=ch_err)
goto 9999 goto 9999
end if end if
if ((ilx /= 1).or.(iglobx /= 1)) then if ((ilx /= 1).or.(iglobx /= 1)) then
info=3040 info=3040
call psb_errpush(info,name) call psb_errpush(info,name)
goto 9999 goto 9999
end if end if
nrow=psb_cd_get_local_rows(desc_a) nrow = psb_cd_get_local_rows(desc_a)
if(root == -1) then if ((root == -1).or.(np==1)) then
! extract my chunk ! extract my chunk
do i=1, nrow do i=1, nrow
idx=desc_a%loc_to_glob(i) idx=desc_a%loc_to_glob(i)
@ -371,41 +376,49 @@ subroutine psb_zscatterv(globx, locx, desc_a, info, iroot)
end do end do
else else
call psb_get_rank(rootrank,ictxt,root) call psb_get_rank(rootrank,ictxt,root)
end if
! root has to gather size information ! root has to gather size information
allocate(displ(np),all_dim(np)) allocate(displ(np),all_dim(np))
call mpi_gather(nrow,1,mpi_integer,all_dim,&
& np,mpi_integer,rootrank,icomm,info)
displ(1)=1 call mpi_gather(nrow,1,mpi_integer,all_dim,&
displ(2:)=all_dim(1:np-1)+1 & 1,mpi_integer,rootrank,icomm,info)
! root has to gather loc_glob from each process if(me == root) then
if(me == root) then displ(1)=0
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim))) do i=2,np
end if displ(i)=displ(i-1) + all_dim(i-1)
end do
if (debug_level >= psb_debug_inner_) then
write(debug_unit,*) me,' ',trim(name),' displ:',displ(1:np), &
&' dim',all_dim(1:np), sum(all_dim)
endif
! root has to gather loc_glob from each process
allocate(l_t_g_all(sum(all_dim)),scatterv(sum(all_dim)))
end if
call mpi_gatherv(desc_a%loc_to_glob,nrow,&
& mpi_integer,l_t_g_all,all_dim,&
& displ,mpi_integer,rootrank,icomm,info)
! prepare vector to scatter
if (me == root) then
do i=1,np
pos=displ(i)
do j=1, all_dim(i)
idx=l_t_g_all(pos+j)
scatterv(pos+j)=globx(idx)
call mpi_gatherv(desc_a%loc_to_glob,nrow,& end do
& mpi_integer,l_t_g_all,all_dim,&
& displ,mpi_integer,rootrank,icomm,info)
! prepare vector to scatter
if(me == root) then
do i=1,np
pos=displ(i)
do j=1, all_dim(i)
idx=l_t_g_all(pos+j-1)
scatterv(pos+j-1)=globx(idx)
end do end do
end do end if
end if
call mpi_scatterv(scatterv,all_dim,displ,& call mpi_scatterv(scatterv,all_dim,displ,&
& mpi_double_precision,locx,nrow,& & mpi_double_complex,locx,nrow,&
& mpi_double_precision,rootrank,icomm,info) & mpi_double_complex,rootrank,icomm,info)
deallocate(all_dim, l_t_g_all, displ, scatterv) if (me==root) deallocate(all_dim, l_t_g_all, displ, scatterv)
end if
call psb_erractionrestore(err_act) call psb_erractionrestore(err_act)
return return

Loading…
Cancel
Save