You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1698 lines
48 KiB
Fortran
1698 lines
48 KiB
Fortran
19 years ago
|
!!$
|
||
10 years ago
|
!!$ Parallel Sparse BLAS version 3.4
|
||
|
!!$ (C) Copyright 2006, 2010, 2015
|
||
17 years ago
|
!!$ Salvatore Filippone University of Rome Tor Vergata
|
||
15 years ago
|
!!$ Alfredo Buttari CNRS-IRIT, Toulouse
|
||
19 years ago
|
!!$
|
||
|
!!$ 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 PSBLAS 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 PSBLAS 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.
|
||
|
!!$
|
||
|
!!$
|
||
17 years ago
|
!
|
||
17 years ago
|
! File: psi_dswapdata.F90
|
||
17 years ago
|
!
|
||
17 years ago
|
! Subroutine: psi_dswapdatam
|
||
17 years ago
|
! Does the data exchange among processes. Essentially this is doing
|
||
|
! a variable all-to-all data exchange (ALLTOALLV in MPI parlance), but
|
||
|
! it is capable of pruning empty exchanges, which are very likely in out
|
||
|
! application environment. All the variants have the same structure
|
||
|
! In all these subroutines X may be: I Integer
|
||
13 years ago
|
! S real(psb_spk_)
|
||
17 years ago
|
! D real(psb_dpk_)
|
||
13 years ago
|
! C complex(psb_spk_)
|
||
17 years ago
|
! Z complex(psb_dpk_)
|
||
17 years ago
|
! Basically the operation is as follows: on each process, we identify
|
||
17 years ago
|
! sections SND(Y) and RCV(Y); then we do a send on (PACK(SND(Y)));
|
||
17 years ago
|
! then we receive, and we do an update with Y = UNPACK(RCV(Y)) + BETA * Y
|
||
|
! but only on the elements involved in the UNPACK operation.
|
||
|
! Thus: for halo data exchange, the receive section is confined in the
|
||
|
! halo indices, and BETA=0, whereas for overlap exchange the receive section
|
||
|
! is scattered in the owned indices, and BETA=1.
|
||
|
!
|
||
|
! Arguments:
|
||
|
! flag - integer Choose the algorithm for data exchange:
|
||
|
! this is chosen through bit fields.
|
||
|
! swap_mpi = iand(flag,psb_swap_mpi_) /= 0
|
||
|
! swap_sync = iand(flag,psb_swap_sync_) /= 0
|
||
|
! swap_send = iand(flag,psb_swap_send_) /= 0
|
||
|
! swap_recv = iand(flag,psb_swap_recv_) /= 0
|
||
|
! if (swap_mpi): use underlying MPI_ALLTOALLV.
|
||
|
! if (swap_sync): use PSB_SND and PSB_RCV in
|
||
|
! synchronized pairs
|
||
|
! if (swap_send .and. swap_recv): use mpi_irecv
|
||
|
! and mpi_send
|
||
|
! if (swap_send): use psb_snd (but need another
|
||
|
! call with swap_recv to complete)
|
||
|
! if (swap_recv): use psb_rcv (completing a
|
||
|
! previous call with swap_send)
|
||
|
!
|
||
|
!
|
||
|
! n - integer Number of columns in Y
|
||
|
! beta - X Choose overwrite or sum.
|
||
|
! y(:,:) - X The data area
|
||
17 years ago
|
! desc_a - type(psb_desc_type). The communication descriptor.
|
||
17 years ago
|
! work(:) - X Buffer space. If not sufficient, will do
|
||
|
! our own internal allocation.
|
||
|
! info - integer. return code.
|
||
|
! data - integer which list is to be used to exchange data
|
||
|
! default psb_comm_halo_
|
||
|
! psb_comm_halo_ use halo_index
|
||
|
! psb_comm_ext_ use ext_index
|
||
|
! psb_comm_ovrl_ use ovrl_index
|
||
17 years ago
|
! psb_comm_mov_ use ovr_mst_idx
|
||
17 years ago
|
!
|
||
|
!
|
||
20 years ago
|
subroutine psi_dswapdatam(flag,n,beta,y,desc_a,work,info,data)
|
||
20 years ago
|
|
||
18 years ago
|
use psi_mod, psb_protect_name => psi_dswapdatam
|
||
20 years ago
|
use psb_error_mod
|
||
12 years ago
|
use psb_desc_mod
|
||
19 years ago
|
use psb_penv_mod
|
||
18 years ago
|
#ifdef MPI_MOD
|
||
18 years ago
|
use mpi
|
||
18 years ago
|
#endif
|
||
20 years ago
|
implicit none
|
||
18 years ago
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
20 years ago
|
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: flag, n
|
||
|
integer(psb_ipk_), intent(out) :: info
|
||
17 years ago
|
real(psb_dpk_) :: y(:,:), beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
13 years ago
|
type(psb_desc_type),target :: desc_a
|
||
13 years ago
|
integer(psb_ipk_), optional :: data
|
||
20 years ago
|
|
||
|
! locals
|
||
13 years ago
|
integer(psb_ipk_) :: ictxt, np, me, icomm, idxs, idxr, totxch, data_, err_act
|
||
|
integer(psb_ipk_), pointer :: d_idx(:)
|
||
19 years ago
|
character(len=20) :: name
|
||
20 years ago
|
|
||
15 years ago
|
info=psb_success_
|
||
19 years ago
|
name='psi_swap_data'
|
||
20 years ago
|
call psb_erractionsave(err_act)
|
||
|
|
||
14 years ago
|
ictxt = desc_a%get_context()
|
||
|
icomm = desc_a%get_mpic()
|
||
19 years ago
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
15 years ago
|
info=psb_err_context_error_
|
||
19 years ago
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
20 years ago
|
endif
|
||
|
|
||
18 years ago
|
if (.not.psb_is_asb_desc(desc_a)) then
|
||
15 years ago
|
info=psb_err_invalid_cd_state_
|
||
18 years ago
|
call psb_errpush(info,name)
|
||
19 years ago
|
goto 9999
|
||
18 years ago
|
endif
|
||
|
|
||
20 years ago
|
if(present(data)) then
|
||
18 years ago
|
data_ = data
|
||
20 years ago
|
else
|
||
18 years ago
|
data_ = psb_comm_halo_
|
||
|
end if
|
||
|
|
||
13 years ago
|
call desc_a%get_list(data_,d_idx,totxch,idxr,idxs,info)
|
||
15 years ago
|
if (info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_internal_error_,name,a_err='psb_cd_get_list')
|
||
18 years ago
|
goto 9999
|
||
17 years ago
|
end if
|
||
|
|
||
17 years ago
|
|
||
|
call psi_swapdata(ictxt,icomm,flag,n,beta,y,d_idx,totxch,idxs,idxr,work,info)
|
||
15 years ago
|
if (info /= psb_success_) goto 9999
|
||
17 years ago
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
17 years ago
|
return
|
||
|
end subroutine psi_dswapdatam
|
||
|
|
||
10 years ago
|
subroutine psi_dswapidxm(iictxt,iicomm,flag,n,beta,y,idx, &
|
||
|
& totxch,totsnd,totrcv,work,info)
|
||
17 years ago
|
|
||
|
use psi_mod, psb_protect_name => psi_dswapidxm
|
||
|
use psb_error_mod
|
||
12 years ago
|
use psb_desc_mod
|
||
17 years ago
|
use psb_penv_mod
|
||
|
#ifdef MPI_MOD
|
||
|
use mpi
|
||
|
#endif
|
||
|
implicit none
|
||
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
|
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: iictxt,iicomm,flag,n
|
||
13 years ago
|
integer(psb_ipk_), intent(out) :: info
|
||
17 years ago
|
real(psb_dpk_) :: y(:,:), beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: idx(:),totxch,totsnd, totrcv
|
||
17 years ago
|
|
||
|
! locals
|
||
13 years ago
|
integer(psb_mpik_) :: ictxt, icomm, np, me,&
|
||
|
& proc_to_comm, p2ptag, p2pstat(mpi_status_size), iret
|
||
|
integer(psb_mpik_), allocatable, dimension(:) :: bsdidx, brvidx,&
|
||
17 years ago
|
& sdsz, rvsz, prcid, rvhd, sdhd
|
||
13 years ago
|
integer(psb_ipk_) :: nesd, nerv,&
|
||
|
& err_act, i, idx_pt, totsnd_, totrcv_,&
|
||
|
& snd_pt, rcv_pt, pnti
|
||
|
integer(psb_ipk_) :: ierr(5)
|
||
17 years ago
|
logical :: swap_mpi, swap_sync, swap_send, swap_recv,&
|
||
|
& albf,do_send,do_recv
|
||
|
logical, parameter :: usersend=.false.
|
||
|
|
||
17 years ago
|
real(psb_dpk_), pointer, dimension(:) :: sndbuf, rcvbuf
|
||
17 years ago
|
#ifdef HAVE_VOLATILE
|
||
|
volatile :: sndbuf, rcvbuf
|
||
|
#endif
|
||
17 years ago
|
character(len=20) :: name
|
||
|
|
||
15 years ago
|
info=psb_success_
|
||
17 years ago
|
name='psi_swap_data'
|
||
|
call psb_erractionsave(err_act)
|
||
13 years ago
|
ictxt = iictxt
|
||
|
icomm = iicomm
|
||
17 years ago
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
15 years ago
|
info=psb_err_context_error_
|
||
17 years ago
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
swap_mpi = iand(flag,psb_swap_mpi_) /= 0
|
||
|
swap_sync = iand(flag,psb_swap_sync_) /= 0
|
||
|
swap_send = iand(flag,psb_swap_send_) /= 0
|
||
|
swap_recv = iand(flag,psb_swap_recv_) /= 0
|
||
|
|
||
|
do_send = swap_mpi .or. swap_sync .or. swap_send
|
||
|
do_recv = swap_mpi .or. swap_sync .or. swap_recv
|
||
|
|
||
|
totrcv_ = totrcv * n
|
||
|
totsnd_ = totsnd * n
|
||
20 years ago
|
|
||
18 years ago
|
if (swap_mpi) then
|
||
|
allocate(sdsz(0:np-1), rvsz(0:np-1), bsdidx(0:np-1),&
|
||
|
& brvidx(0:np-1), rvhd(0:np-1), sdhd(0:np-1), prcid(0:np-1),&
|
||
|
& stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
rvhd(:) = mpi_request_null
|
||
|
sdsz(:) = 0
|
||
|
rvsz(:) = 0
|
||
20 years ago
|
|
||
18 years ago
|
! prepare info for communications
|
||
20 years ago
|
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
call psb_get_rank(prcid(proc_to_comm),ictxt,proc_to_comm)
|
||
20 years ago
|
|
||
18 years ago
|
brvidx(proc_to_comm) = rcv_pt
|
||
|
rvsz(proc_to_comm) = n*nerv
|
||
|
|
||
|
bsdidx(proc_to_comm) = snd_pt
|
||
|
sdsz(proc_to_comm) = n*nesd
|
||
18 years ago
|
|
||
18 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
|
||
|
end do
|
||
|
|
||
|
else
|
||
|
allocate(rvhd(totxch),prcid(totxch),stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
|
end if
|
||
20 years ago
|
|
||
17 years ago
|
totrcv_ = max(totrcv_,1)
|
||
|
totsnd_ = max(totsnd_,1)
|
||
|
if((totrcv_+totsnd_) < size(work)) then
|
||
|
sndbuf => work(1:totsnd_)
|
||
|
rcvbuf => work(totsnd_+1:totsnd_+totrcv_)
|
||
18 years ago
|
albf=.false.
|
||
20 years ago
|
else
|
||
17 years ago
|
allocate(sndbuf(totsnd_),rcvbuf(totrcv_), stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
19 years ago
|
goto 9999
|
||
|
end if
|
||
18 years ago
|
albf=.true.
|
||
20 years ago
|
end if
|
||
|
|
||
18 years ago
|
if (do_send) then
|
||
19 years ago
|
|
||
18 years ago
|
! Pack send buffers
|
||
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
idx_pt = 1+pnti+nerv+psb_n_elem_send_
|
||
17 years ago
|
call psi_gth(nesd,n,idx(idx_pt:idx_pt+nesd-1),&
|
||
18 years ago
|
& y,sndbuf(snd_pt:snd_pt+n*nesd-1))
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
19 years ago
|
|
||
18 years ago
|
end if
|
||
19 years ago
|
|
||
|
|
||
18 years ago
|
|
||
|
! Case SWAP_MPI
|
||
|
if (swap_mpi) then
|
||
19 years ago
|
|
||
|
! swap elements using mpi_alltoallv
|
||
|
call mpi_alltoallv(sndbuf,sdsz,bsdidx,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,rcvbuf,rvsz,&
|
||
|
& brvidx,psb_mpi_r_dpk_,icomm,iret)
|
||
19 years ago
|
if(iret /= mpi_success) then
|
||
13 years ago
|
ierr(1) = iret
|
||
15 years ago
|
info=psb_err_mpi_error_
|
||
13 years ago
|
call psb_errpush(info,name,i_err=ierr)
|
||
19 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
else if (swap_sync) then
|
||
|
|
||
18 years ago
|
|
||
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
|
||
19 years ago
|
if (proc_to_comm < me) then
|
||
18 years ago
|
if (nesd>0) call psb_snd(ictxt,&
|
||
|
& sndbuf(snd_pt:snd_pt+n*nesd-1), proc_to_comm)
|
||
|
if (nerv>0) call psb_rcv(ictxt,&
|
||
|
& rcvbuf(rcv_pt:rcv_pt+n*nerv-1), proc_to_comm)
|
||
19 years ago
|
else if (proc_to_comm > me) then
|
||
18 years ago
|
if (nerv>0) call psb_rcv(ictxt,&
|
||
|
& rcvbuf(rcv_pt:rcv_pt+n*nerv-1), proc_to_comm)
|
||
|
if (nesd>0) call psb_snd(ictxt,&
|
||
|
& sndbuf(snd_pt:snd_pt+n*nesd-1), proc_to_comm)
|
||
17 years ago
|
else if (proc_to_comm == me) then
|
||
|
if (nesd /= nerv) then
|
||
13 years ago
|
write(psb_err_unit,*) &
|
||
|
& 'Fatal error in swapdata: mismatch on self send',&
|
||
13 years ago
|
& nerv,nesd
|
||
17 years ago
|
end if
|
||
|
rcvbuf(rcv_pt:rcv_pt+n*nerv-1) = sndbuf(snd_pt:snd_pt+n*nesd-1)
|
||
19 years ago
|
end if
|
||
18 years ago
|
|
||
18 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
20 years ago
|
|
||
19 years ago
|
end do
|
||
|
|
||
20 years ago
|
|
||
|
else if (swap_send .and. swap_recv) then
|
||
|
|
||
18 years ago
|
! First I post all the non blocking receives
|
||
18 years ago
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
call psb_get_rank(prcid(i),ictxt,proc_to_comm)
|
||
15 years ago
|
if ((nerv>0).and.(proc_to_comm /= me)) then
|
||
15 years ago
|
p2ptag = psb_double_swap_tag
|
||
18 years ago
|
call mpi_irecv(rcvbuf(rcv_pt),n*nerv,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
18 years ago
|
& p2ptag, icomm,rvhd(i),iret)
|
||
|
end if
|
||
18 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
|
|
||
18 years ago
|
|
||
19 years ago
|
! Then I post all the blocking sends
|
||
13 years ago
|
if (usersend) call mpi_barrier(icomm,iret)
|
||
19 years ago
|
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
19 years ago
|
|
||
13 years ago
|
p2ptag = psb_double_swap_tag
|
||
15 years ago
|
if ((nesd>0).and.(proc_to_comm /= me)) then
|
||
18 years ago
|
if (usersend) then
|
||
|
call mpi_rsend(sndbuf(snd_pt),n*nesd,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
18 years ago
|
& p2ptag,icomm,iret)
|
||
|
else
|
||
|
call mpi_send(sndbuf(snd_pt),n*nesd,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
13 years ago
|
& p2ptag,icomm,iret)
|
||
18 years ago
|
end if
|
||
18 years ago
|
|
||
18 years ago
|
if(iret /= mpi_success) then
|
||
13 years ago
|
ierr(1) = iret
|
||
15 years ago
|
info=psb_err_mpi_error_
|
||
13 years ago
|
call psb_errpush(info,name,i_err=ierr)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
18 years ago
|
end if
|
||
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
|
||
19 years ago
|
end do
|
||
20 years ago
|
|
||
18 years ago
|
|
||
|
|
||
|
pnti = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
|
||
15 years ago
|
p2ptag = psb_double_swap_tag
|
||
18 years ago
|
|
||
|
if ((proc_to_comm /= me).and.(nerv>0)) then
|
||
18 years ago
|
call mpi_wait(rvhd(i),p2pstat,iret)
|
||
19 years ago
|
if(iret /= mpi_success) then
|
||
13 years ago
|
ierr(1) = iret
|
||
15 years ago
|
info=psb_err_mpi_error_
|
||
13 years ago
|
call psb_errpush(info,name,i_err=ierr)
|
||
19 years ago
|
goto 9999
|
||
20 years ago
|
end if
|
||
17 years ago
|
else if (proc_to_comm == me) then
|
||
|
if (nesd /= nerv) then
|
||
13 years ago
|
write(psb_err_unit,*)&
|
||
|
& 'Fatal error in swapdata: mismatch on self send', &
|
||
13 years ago
|
& nerv,nesd
|
||
17 years ago
|
end if
|
||
|
rcvbuf(rcv_pt:rcv_pt+n*nerv-1) = sndbuf(snd_pt:snd_pt+n*nesd-1)
|
||
18 years ago
|
end if
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
18 years ago
|
|
||
20 years ago
|
|
||
18 years ago
|
else if (swap_send) then
|
||
19 years ago
|
|
||
20 years ago
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
if (nesd>0) call psb_snd(ictxt,&
|
||
|
& sndbuf(snd_pt:snd_pt+n*nesd-1), proc_to_comm)
|
||
|
|
||
18 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
|
||
18 years ago
|
end do
|
||
19 years ago
|
|
||
18 years ago
|
else if (swap_recv) then
|
||
20 years ago
|
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
if (nerv>0) call psb_rcv(ictxt,&
|
||
|
& rcvbuf(rcv_pt:rcv_pt+n*nerv-1), proc_to_comm)
|
||
18 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
20 years ago
|
|
||
18 years ago
|
end if
|
||
20 years ago
|
|
||
19 years ago
|
|
||
20 years ago
|
|
||
18 years ago
|
if (do_recv) then
|
||
20 years ago
|
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
idx_pt = 1+pnti+psb_n_elem_recv_
|
||
17 years ago
|
call psi_sct(nerv,n,idx(idx_pt:idx_pt+nerv-1),&
|
||
18 years ago
|
& rcvbuf(rcv_pt:rcv_pt+n*nerv-1),beta,y)
|
||
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
20 years ago
|
|
||
|
end if
|
||
|
|
||
18 years ago
|
|
||
|
if (swap_mpi) then
|
||
|
deallocate(sdsz,rvsz,bsdidx,brvidx,rvhd,prcid,sdhd,&
|
||
|
& stat=info)
|
||
|
else
|
||
|
deallocate(rvhd,prcid,stat=info)
|
||
|
end if
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
17 years ago
|
if(albf) deallocate(sndbuf,rcvbuf,stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
17 years ago
|
goto 9999
|
||
|
end if
|
||
19 years ago
|
|
||
20 years ago
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
19 years ago
|
return
|
||
17 years ago
|
end subroutine psi_dswapidxm
|
||
20 years ago
|
|
||
17 years ago
|
!
|
||
|
!
|
||
17 years ago
|
! Subroutine: psi_dswapdatav
|
||
17 years ago
|
! Does the data exchange among processes. Essentially this is doing
|
||
|
! a variable all-to-all data exchange (ALLTOALLV in MPI parlance), but
|
||
|
! it is capable of pruning empty exchanges, which are very likely in out
|
||
|
! application environment. All the variants have the same structure
|
||
|
! In all these subroutines X may be: I Integer
|
||
13 years ago
|
! S real(psb_spk_)
|
||
17 years ago
|
! D real(psb_dpk_)
|
||
13 years ago
|
! C complex(psb_spk_)
|
||
17 years ago
|
! Z complex(psb_dpk_)
|
||
17 years ago
|
! Basically the operation is as follows: on each process, we identify
|
||
|
! sections SND(Y) and RCV(Y); then we do a SEND(PACK(SND(Y)));
|
||
|
! then we receive, and we do an update with Y = UNPACK(RCV(Y)) + BETA * Y
|
||
|
! but only on the elements involved in the UNPACK operation.
|
||
|
! Thus: for halo data exchange, the receive section is confined in the
|
||
|
! halo indices, and BETA=0, whereas for overlap exchange the receive section
|
||
|
! is scattered in the owned indices, and BETA=1.
|
||
|
!
|
||
|
! Arguments:
|
||
|
! flag - integer Choose the algorithm for data exchange:
|
||
|
! this is chosen through bit fields.
|
||
|
! swap_mpi = iand(flag,psb_swap_mpi_) /= 0
|
||
|
! swap_sync = iand(flag,psb_swap_sync_) /= 0
|
||
|
! swap_send = iand(flag,psb_swap_send_) /= 0
|
||
|
! swap_recv = iand(flag,psb_swap_recv_) /= 0
|
||
|
! if (swap_mpi): use underlying MPI_ALLTOALLV.
|
||
|
! if (swap_sync): use PSB_SND and PSB_RCV in
|
||
|
! synchronized pairs
|
||
|
! if (swap_send .and. swap_recv): use mpi_irecv
|
||
|
! and mpi_send
|
||
|
! if (swap_send): use psb_snd (but need another
|
||
|
! call with swap_recv to complete)
|
||
|
! if (swap_recv): use psb_rcv (completing a
|
||
|
! previous call with swap_send)
|
||
|
!
|
||
|
!
|
||
|
! n - integer Number of columns in Y
|
||
|
! beta - X Choose overwrite or sum.
|
||
|
! y(:) - X The data area
|
||
17 years ago
|
! desc_a - type(psb_desc_type). The communication descriptor.
|
||
17 years ago
|
! work(:) - X Buffer space. If not sufficient, will do
|
||
|
! our own internal allocation.
|
||
|
! info - integer. return code.
|
||
|
! data - integer which list is to be used to exchange data
|
||
|
! default psb_comm_halo_
|
||
|
! psb_comm_halo_ use halo_index
|
||
|
! psb_comm_ext_ use ext_index
|
||
|
! psb_comm_ovrl_ use ovrl_index
|
||
17 years ago
|
! psb_comm_mov_ use ovr_mst_idx
|
||
17 years ago
|
!
|
||
13 years ago
|
!
|
||
20 years ago
|
subroutine psi_dswapdatav(flag,beta,y,desc_a,work,info,data)
|
||
20 years ago
|
|
||
18 years ago
|
use psi_mod, psb_protect_name => psi_dswapdatav
|
||
20 years ago
|
use psb_error_mod
|
||
12 years ago
|
use psb_desc_mod
|
||
19 years ago
|
use psb_penv_mod
|
||
18 years ago
|
#ifdef MPI_MOD
|
||
20 years ago
|
use mpi
|
||
18 years ago
|
#endif
|
||
20 years ago
|
implicit none
|
||
18 years ago
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
20 years ago
|
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: flag
|
||
|
integer(psb_ipk_), intent(out) :: info
|
||
17 years ago
|
real(psb_dpk_) :: y(:), beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
13 years ago
|
type(psb_desc_type),target :: desc_a
|
||
13 years ago
|
integer(psb_ipk_), optional :: data
|
||
20 years ago
|
|
||
|
! locals
|
||
13 years ago
|
integer(psb_ipk_) :: ictxt, np, me, icomm, idxs, idxr, totxch, data_, err_act
|
||
|
integer(psb_ipk_), pointer :: d_idx(:)
|
||
19 years ago
|
character(len=20) :: name
|
||
20 years ago
|
|
||
15 years ago
|
info=psb_success_
|
||
18 years ago
|
name='psi_swap_datav'
|
||
20 years ago
|
call psb_erractionsave(err_act)
|
||
|
|
||
14 years ago
|
ictxt=desc_a%get_context()
|
||
19 years ago
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
15 years ago
|
info=psb_err_context_error_
|
||
19 years ago
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
20 years ago
|
endif
|
||
|
|
||
18 years ago
|
if (.not.psb_is_asb_desc(desc_a)) then
|
||
15 years ago
|
info=psb_err_invalid_cd_state_
|
||
18 years ago
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
20 years ago
|
|
||
14 years ago
|
icomm = desc_a%get_mpic()
|
||
20 years ago
|
|
||
|
if(present(data)) then
|
||
18 years ago
|
data_ = data
|
||
20 years ago
|
else
|
||
18 years ago
|
data_ = psb_comm_halo_
|
||
|
end if
|
||
|
|
||
13 years ago
|
call desc_a%get_list(data_,d_idx,totxch,idxr,idxs,info)
|
||
15 years ago
|
if (info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_internal_error_,name,a_err='psb_cd_get_list')
|
||
18 years ago
|
goto 9999
|
||
17 years ago
|
end if
|
||
20 years ago
|
|
||
17 years ago
|
call psi_swapdata(ictxt,icomm,flag,beta,y,d_idx,totxch,idxs,idxr,work,info)
|
||
15 years ago
|
if (info /= psb_success_) goto 9999
|
||
17 years ago
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
17 years ago
|
return
|
||
|
end subroutine psi_dswapdatav
|
||
|
|
||
|
|
||
10 years ago
|
|
||
|
!
|
||
|
!
|
||
|
! Subroutine: psi_dswapdataidxv
|
||
|
! Does the data exchange among processes.
|
||
|
!
|
||
|
! The real workhorse: the outer routines will only choose the index list
|
||
|
! this one takes the index list and does the actual exchange.
|
||
|
!
|
||
|
!
|
||
|
!
|
||
10 years ago
|
subroutine psi_dswapidxv(iictxt,iicomm,flag,beta,y,idx, &
|
||
|
& totxch,totsnd,totrcv,work,info)
|
||
17 years ago
|
|
||
|
use psi_mod, psb_protect_name => psi_dswapidxv
|
||
|
use psb_error_mod
|
||
12 years ago
|
use psb_desc_mod
|
||
17 years ago
|
use psb_penv_mod
|
||
|
#ifdef MPI_MOD
|
||
|
use mpi
|
||
|
#endif
|
||
|
implicit none
|
||
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
|
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: iictxt,iicomm,flag
|
||
13 years ago
|
integer(psb_ipk_), intent(out) :: info
|
||
17 years ago
|
real(psb_dpk_) :: y(:), beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: idx(:),totxch,totsnd, totrcv
|
||
17 years ago
|
|
||
|
! locals
|
||
13 years ago
|
integer(psb_mpik_) :: ictxt, icomm, np, me,&
|
||
|
& proc_to_comm, p2ptag, p2pstat(mpi_status_size), iret
|
||
|
integer(psb_mpik_), allocatable, dimension(:) :: bsdidx, brvidx,&
|
||
17 years ago
|
& sdsz, rvsz, prcid, rvhd, sdhd
|
||
13 years ago
|
integer(psb_ipk_) :: nesd, nerv,&
|
||
|
& err_act, i, idx_pt, totsnd_, totrcv_,&
|
||
|
& snd_pt, rcv_pt, pnti, n
|
||
|
integer(psb_ipk_) :: ierr(5)
|
||
17 years ago
|
logical :: swap_mpi, swap_sync, swap_send, swap_recv,&
|
||
|
& albf,do_send,do_recv
|
||
|
logical, parameter :: usersend=.false.
|
||
|
|
||
17 years ago
|
real(psb_dpk_), pointer, dimension(:) :: sndbuf, rcvbuf
|
||
17 years ago
|
#ifdef HAVE_VOLATILE
|
||
|
volatile :: sndbuf, rcvbuf
|
||
|
#endif
|
||
17 years ago
|
character(len=20) :: name
|
||
|
|
||
15 years ago
|
info=psb_success_
|
||
17 years ago
|
name='psi_swap_datav'
|
||
|
call psb_erractionsave(err_act)
|
||
13 years ago
|
ictxt = iictxt
|
||
|
icomm = iicomm
|
||
17 years ago
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
15 years ago
|
info=psb_err_context_error_
|
||
17 years ago
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
n=1
|
||
|
|
||
|
swap_mpi = iand(flag,psb_swap_mpi_) /= 0
|
||
|
swap_sync = iand(flag,psb_swap_sync_) /= 0
|
||
|
swap_send = iand(flag,psb_swap_send_) /= 0
|
||
|
swap_recv = iand(flag,psb_swap_recv_) /= 0
|
||
|
do_send = swap_mpi .or. swap_sync .or. swap_send
|
||
|
do_recv = swap_mpi .or. swap_sync .or. swap_recv
|
||
|
|
||
|
totrcv_ = totrcv * n
|
||
|
totsnd_ = totsnd * n
|
||
18 years ago
|
|
||
|
if (swap_mpi) then
|
||
|
allocate(sdsz(0:np-1), rvsz(0:np-1), bsdidx(0:np-1),&
|
||
|
& brvidx(0:np-1), rvhd(0:np-1), sdhd(0:np-1), prcid(0:np-1),&
|
||
|
& stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
rvhd(:) = mpi_request_null
|
||
|
sdsz(:) = 0
|
||
|
rvsz(:) = 0
|
||
20 years ago
|
|
||
18 years ago
|
! prepare info for communications
|
||
20 years ago
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
call psb_get_rank(prcid(proc_to_comm),ictxt,proc_to_comm)
|
||
|
|
||
|
brvidx(proc_to_comm) = rcv_pt
|
||
|
rvsz(proc_to_comm) = nerv
|
||
|
|
||
|
bsdidx(proc_to_comm) = snd_pt
|
||
|
sdsz(proc_to_comm) = nesd
|
||
|
|
||
|
rcv_pt = rcv_pt + nerv
|
||
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
|
||
|
end do
|
||
|
|
||
|
else
|
||
|
allocate(rvhd(totxch),prcid(totxch),stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
|
end if
|
||
20 years ago
|
|
||
|
|
||
17 years ago
|
totrcv_ = max(totrcv_,1)
|
||
|
totsnd_ = max(totsnd_,1)
|
||
|
if((totrcv_+totsnd_) < size(work)) then
|
||
|
sndbuf => work(1:totsnd_)
|
||
|
rcvbuf => work(totsnd_+1:totsnd_+totrcv_)
|
||
18 years ago
|
albf=.false.
|
||
20 years ago
|
else
|
||
17 years ago
|
allocate(sndbuf(totsnd_),rcvbuf(totrcv_), stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
19 years ago
|
goto 9999
|
||
|
end if
|
||
18 years ago
|
albf=.true.
|
||
20 years ago
|
end if
|
||
|
|
||
19 years ago
|
|
||
18 years ago
|
if (do_send) then
|
||
19 years ago
|
|
||
18 years ago
|
! Pack send buffers
|
||
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
idx_pt = 1+pnti+nerv+psb_n_elem_send_
|
||
17 years ago
|
call psi_gth(nesd,idx(idx_pt:idx_pt+nesd-1),&
|
||
19 years ago
|
& y,sndbuf(snd_pt:snd_pt+nesd-1))
|
||
18 years ago
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
|
|
||
18 years ago
|
end if
|
||
|
|
||
|
! Case SWAP_MPI
|
||
|
if (swap_mpi) then
|
||
|
|
||
19 years ago
|
! swap elements using mpi_alltoallv
|
||
|
call mpi_alltoallv(sndbuf,sdsz,bsdidx,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,rcvbuf,rvsz,&
|
||
|
& brvidx,psb_mpi_r_dpk_,icomm,iret)
|
||
19 years ago
|
if(iret /= mpi_success) then
|
||
13 years ago
|
ierr(1) = iret
|
||
15 years ago
|
info=psb_err_mpi_error_
|
||
13 years ago
|
call psb_errpush(info,name,i_err=ierr)
|
||
19 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
else if (swap_sync) then
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
|
||
19 years ago
|
if (proc_to_comm < me) then
|
||
18 years ago
|
if (nesd>0) call psb_snd(ictxt,&
|
||
|
& sndbuf(snd_pt:snd_pt+nesd-1), proc_to_comm)
|
||
|
if (nerv>0) call psb_rcv(ictxt,&
|
||
|
& rcvbuf(rcv_pt:rcv_pt+nerv-1), proc_to_comm)
|
||
19 years ago
|
else if (proc_to_comm > me) then
|
||
18 years ago
|
if (nerv>0) call psb_rcv(ictxt,&
|
||
|
& rcvbuf(rcv_pt:rcv_pt+nerv-1), proc_to_comm)
|
||
|
if (nesd>0) call psb_snd(ictxt,&
|
||
|
& sndbuf(snd_pt:snd_pt+nesd-1), proc_to_comm)
|
||
17 years ago
|
else if (proc_to_comm == me) then
|
||
|
if (nesd /= nerv) then
|
||
13 years ago
|
write(psb_err_unit,*) &
|
||
|
& 'Fatal error in swapdata: mismatch on self send', &
|
||
13 years ago
|
& nerv,nesd
|
||
17 years ago
|
end if
|
||
|
rcvbuf(rcv_pt:rcv_pt+nerv-1) = sndbuf(snd_pt:snd_pt+nesd-1)
|
||
19 years ago
|
end if
|
||
18 years ago
|
rcv_pt = rcv_pt + nerv
|
||
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
|
|
||
20 years ago
|
|
||
19 years ago
|
else if (swap_send .and. swap_recv) then
|
||
20 years ago
|
|
||
18 years ago
|
! First I post all the non blocking receives
|
||
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
|
||
18 years ago
|
call psb_get_rank(prcid(i),ictxt,proc_to_comm)
|
||
17 years ago
|
if ((nerv>0).and.(proc_to_comm /= me)) then
|
||
15 years ago
|
p2ptag = psb_double_swap_tag
|
||
18 years ago
|
call mpi_irecv(rcvbuf(rcv_pt),nerv,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
18 years ago
|
& p2ptag, icomm,rvhd(i),iret)
|
||
|
end if
|
||
18 years ago
|
rcv_pt = rcv_pt + nerv
|
||
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
|
|
||
18 years ago
|
|
||
19 years ago
|
! Then I post all the blocking sends
|
||
13 years ago
|
if (usersend) call mpi_barrier(icomm,iret)
|
||
18 years ago
|
|
||
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
19 years ago
|
|
||
13 years ago
|
p2ptag = psb_double_swap_tag
|
||
18 years ago
|
|
||
17 years ago
|
if ((nesd>0).and.(proc_to_comm /= me)) then
|
||
18 years ago
|
if (usersend) then
|
||
|
call mpi_rsend(sndbuf(snd_pt),nesd,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
18 years ago
|
& p2ptag,icomm,iret)
|
||
|
else
|
||
|
call mpi_send(sndbuf(snd_pt),nesd,&
|
||
12 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
18 years ago
|
& p2ptag,icomm,iret)
|
||
|
end if
|
||
18 years ago
|
|
||
18 years ago
|
if(iret /= mpi_success) then
|
||
13 years ago
|
ierr(1) = iret
|
||
15 years ago
|
info=psb_err_mpi_error_
|
||
13 years ago
|
call psb_errpush(info,name,i_err=ierr)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
18 years ago
|
end if
|
||
|
rcv_pt = rcv_pt + nerv
|
||
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
20 years ago
|
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
|
||
13 years ago
|
p2ptag = psb_double_swap_tag
|
||
18 years ago
|
|
||
18 years ago
|
if ((proc_to_comm /= me).and.(nerv>0)) then
|
||
18 years ago
|
call mpi_wait(rvhd(i),p2pstat,iret)
|
||
19 years ago
|
if(iret /= mpi_success) then
|
||
13 years ago
|
ierr(1) = iret
|
||
15 years ago
|
info=psb_err_mpi_error_
|
||
13 years ago
|
call psb_errpush(info,name,i_err=ierr)
|
||
19 years ago
|
goto 9999
|
||
|
end if
|
||
17 years ago
|
else if (proc_to_comm == me) then
|
||
|
if (nesd /= nerv) then
|
||
13 years ago
|
write(psb_err_unit,*) &
|
||
|
& 'Fatal error in swapdata: mismatch on self send', &
|
||
13 years ago
|
& nerv,nesd
|
||
17 years ago
|
end if
|
||
|
rcvbuf(rcv_pt:rcv_pt+nerv-1) = sndbuf(snd_pt:snd_pt+nesd-1)
|
||
18 years ago
|
end if
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
20 years ago
|
|
||
|
|
||
|
else if (swap_send) then
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
if (nesd>0) call psb_snd(ictxt,&
|
||
|
& sndbuf(snd_pt:snd_pt+nesd-1), proc_to_comm)
|
||
18 years ago
|
rcv_pt = rcv_pt + nerv
|
||
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
20 years ago
|
|
||
|
else if (swap_recv) then
|
||
|
|
||
18 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
if (nerv>0) call psb_rcv(ictxt,&
|
||
|
& rcvbuf(rcv_pt:rcv_pt+nerv-1), proc_to_comm)
|
||
18 years ago
|
rcv_pt = rcv_pt + nerv
|
||
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
|
||
|
end if
|
||
20 years ago
|
|
||
18 years ago
|
if (do_recv) then
|
||
|
|
||
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
17 years ago
|
proc_to_comm = idx(pnti+psb_proc_id_)
|
||
|
nerv = idx(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx(pnti+nerv+psb_n_elem_send_)
|
||
18 years ago
|
idx_pt = 1+pnti+psb_n_elem_recv_
|
||
17 years ago
|
call psi_sct(nerv,idx(idx_pt:idx_pt+nerv-1),&
|
||
18 years ago
|
& rcvbuf(rcv_pt:rcv_pt+nerv-1),beta,y)
|
||
|
rcv_pt = rcv_pt + nerv
|
||
|
snd_pt = snd_pt + nesd
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
19 years ago
|
end do
|
||
20 years ago
|
|
||
|
end if
|
||
|
|
||
18 years ago
|
if (swap_mpi) then
|
||
|
deallocate(sdsz,rvsz,bsdidx,brvidx,rvhd,prcid,sdhd,&
|
||
|
& stat=info)
|
||
|
else
|
||
|
deallocate(rvhd,prcid,stat=info)
|
||
|
end if
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
18 years ago
|
goto 9999
|
||
|
end if
|
||
|
if(albf) deallocate(sndbuf,rcvbuf,stat=info)
|
||
15 years ago
|
if(info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
19 years ago
|
goto 9999
|
||
|
end if
|
||
|
|
||
20 years ago
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
19 years ago
|
return
|
||
17 years ago
|
end subroutine psi_dswapidxv
|
||
10 years ago
|
!
|
||
|
!
|
||
|
! Subroutine: psi_dswapdata_vect
|
||
|
! Data exchange among processes.
|
||
|
!
|
||
|
! Takes care of Y an exanspulated vector.
|
||
|
!
|
||
|
!
|
||
|
!
|
||
13 years ago
|
subroutine psi_dswapdata_vect(flag,beta,y,desc_a,work,info,data)
|
||
|
|
||
|
use psi_mod, psb_protect_name => psi_dswapdata_vect
|
||
|
use psb_d_base_vect_mod
|
||
|
use psb_error_mod
|
||
12 years ago
|
use psb_desc_mod
|
||
13 years ago
|
use psb_penv_mod
|
||
|
#ifdef MPI_MOD
|
||
|
use mpi
|
||
|
#endif
|
||
|
implicit none
|
||
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
|
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: flag
|
||
|
integer(psb_ipk_), intent(out) :: info
|
||
13 years ago
|
class(psb_d_base_vect_type) :: y
|
||
13 years ago
|
real(psb_dpk_) :: beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
10 years ago
|
type(psb_desc_type), target :: desc_a
|
||
13 years ago
|
integer(psb_ipk_), optional :: data
|
||
13 years ago
|
|
||
|
! locals
|
||
13 years ago
|
integer(psb_ipk_) :: ictxt, np, me, icomm, idxs, idxr, totxch, data_, err_act
|
||
12 years ago
|
class(psb_i_base_vect_type), pointer :: d_vidx
|
||
13 years ago
|
character(len=20) :: name
|
||
|
|
||
|
info=psb_success_
|
||
|
name='psi_swap_datav'
|
||
|
call psb_erractionsave(err_act)
|
||
|
|
||
|
ictxt=desc_a%get_context()
|
||
10 years ago
|
icomm = desc_a%get_mpic()
|
||
|
|
||
13 years ago
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
|
info=psb_err_context_error_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
if (.not.psb_is_asb_desc(desc_a)) then
|
||
|
info=psb_err_invalid_cd_state_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
if(present(data)) then
|
||
|
data_ = data
|
||
|
else
|
||
|
data_ = psb_comm_halo_
|
||
|
end if
|
||
|
|
||
12 years ago
|
call desc_a%get_list(data_,d_vidx,totxch,idxr,idxs,info)
|
||
13 years ago
|
if (info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_internal_error_,name,a_err='psb_cd_get_list')
|
||
|
goto 9999
|
||
|
end if
|
||
|
|
||
12 years ago
|
call psi_swapdata(ictxt,icomm,flag,beta,y,d_vidx,totxch,idxs,idxr,work,info)
|
||
13 years ago
|
if (info /= psb_success_) goto 9999
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
13 years ago
|
return
|
||
|
end subroutine psi_dswapdata_vect
|
||
|
|
||
|
|
||
10 years ago
|
!
|
||
|
!
|
||
10 years ago
|
! Subroutine: psi_dswap_vidx_vect
|
||
10 years ago
|
! Data exchange among processes.
|
||
|
!
|
||
|
! Takes care of Y an exanspulated vector. Relies on the gather/scatter methods
|
||
|
! of vectors.
|
||
|
!
|
||
10 years ago
|
! The real workhorse: the outer routine will only choose the index list
|
||
10 years ago
|
! this one takes the index list and does the actual exchange.
|
||
|
!
|
||
|
!
|
||
|
!
|
||
10 years ago
|
subroutine psi_dswap_vidx_vect(iictxt,iicomm,flag,beta,y,idx, &
|
||
|
& totxch,totsnd,totrcv,work,info)
|
||
12 years ago
|
|
||
|
use psi_mod, psb_protect_name => psi_dswap_vidx_vect
|
||
|
use psb_error_mod
|
||
10 years ago
|
use psb_realloc_mod
|
||
12 years ago
|
use psb_desc_mod
|
||
|
use psb_penv_mod
|
||
|
use psb_d_base_vect_mod
|
||
|
#ifdef MPI_MOD
|
||
|
use mpi
|
||
|
#endif
|
||
|
implicit none
|
||
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
|
|
||
|
integer(psb_ipk_), intent(in) :: iictxt,iicomm,flag
|
||
|
integer(psb_ipk_), intent(out) :: info
|
||
|
class(psb_d_base_vect_type) :: y
|
||
|
real(psb_dpk_) :: beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
10 years ago
|
class(psb_i_base_vect_type), intent(inout) :: idx
|
||
|
integer(psb_ipk_), intent(in) :: totxch,totsnd, totrcv
|
||
12 years ago
|
|
||
|
! locals
|
||
|
integer(psb_mpik_) :: ictxt, icomm, np, me,&
|
||
|
& proc_to_comm, p2ptag, p2pstat(mpi_status_size), iret
|
||
10 years ago
|
integer(psb_mpik_), allocatable :: prcid(:)
|
||
12 years ago
|
integer(psb_ipk_) :: nesd, nerv,&
|
||
|
& err_act, i, idx_pt, totsnd_, totrcv_,&
|
||
|
& snd_pt, rcv_pt, pnti, n
|
||
|
integer(psb_ipk_) :: ierr(5)
|
||
|
logical :: swap_mpi, swap_sync, swap_send, swap_recv,&
|
||
|
& albf,do_send,do_recv
|
||
10 years ago
|
logical, parameter :: usersend=.false., debug=.false.
|
||
12 years ago
|
character(len=20) :: name
|
||
|
|
||
|
info=psb_success_
|
||
|
name='psi_swap_datav'
|
||
|
call psb_erractionsave(err_act)
|
||
|
ictxt = iictxt
|
||
|
icomm = iicomm
|
||
10 years ago
|
|
||
12 years ago
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
|
info=psb_err_context_error_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
n=1
|
||
|
|
||
|
swap_mpi = iand(flag,psb_swap_mpi_) /= 0
|
||
|
swap_sync = iand(flag,psb_swap_sync_) /= 0
|
||
|
swap_send = iand(flag,psb_swap_send_) /= 0
|
||
|
swap_recv = iand(flag,psb_swap_recv_) /= 0
|
||
|
do_send = swap_mpi .or. swap_sync .or. swap_send
|
||
|
do_recv = swap_mpi .or. swap_sync .or. swap_recv
|
||
|
|
||
|
totrcv_ = totrcv * n
|
||
|
totsnd_ = totsnd * n
|
||
10 years ago
|
call idx%sync()
|
||
|
|
||
|
if (debug) write(*,*) me,'Internal buffer'
|
||
|
if (do_send) then
|
||
|
if (allocated(y%comid)) then
|
||
|
!
|
||
|
! Unfinished communication? Something is wrong....
|
||
|
!
|
||
12 years ago
|
info=psb_err_mpi_error_
|
||
10 years ago
|
ierr(1) = -2
|
||
12 years ago
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
10 years ago
|
if (debug) write(*,*) me,'do_send start'
|
||
|
call y%new_buffer(size(idx%v),info)
|
||
|
call y%new_comid(totxch,info)
|
||
|
call psb_realloc(totxch,prcid,info)
|
||
|
! First I post all the non blocking receives
|
||
12 years ago
|
pnti = 1
|
||
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
|
|
||
10 years ago
|
rcv_pt = 1+pnti+psb_n_elem_recv_
|
||
|
call psb_get_rank(prcid(i),ictxt,proc_to_comm)
|
||
|
if ((nerv>0).and.(proc_to_comm /= me)) then
|
||
|
if (debug) write(*,*) me,'Posting receive from',prcid(i),rcv_pt
|
||
|
p2ptag = psb_double_swap_tag
|
||
|
call mpi_irecv(y%combuf(rcv_pt),nerv,&
|
||
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
|
& p2ptag, icomm,y%comid(i,2),iret)
|
||
12 years ago
|
end if
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
10 years ago
|
if (debug) write(*,*) me,' Gather '
|
||
|
!
|
||
|
! Then gather for sending.
|
||
|
!
|
||
12 years ago
|
pnti = 1
|
||
|
do i=1, totxch
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
10 years ago
|
snd_pt = 1+pnti+nerv+psb_n_elem_send_
|
||
|
rcv_pt = 1+pnti+psb_n_elem_recv_
|
||
|
idx_pt = snd_pt
|
||
10 years ago
|
call y%gth(idx_pt,nesd,idx)
|
||
12 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
|
||
10 years ago
|
!
|
||
|
! Then wait
|
||
|
!
|
||
|
call y%device_wait()
|
||
12 years ago
|
|
||
10 years ago
|
if (debug) write(*,*) me,' isend'
|
||
|
!
|
||
|
! Then send
|
||
|
!
|
||
12 years ago
|
|
||
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
10 years ago
|
p2ptag = psb_double_swap_tag
|
||
12 years ago
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
10 years ago
|
snd_pt = 1+pnti+nerv+psb_n_elem_send_
|
||
|
rcv_pt = 1+pnti+psb_n_elem_recv_
|
||
12 years ago
|
|
||
|
if ((nesd>0).and.(proc_to_comm /= me)) then
|
||
10 years ago
|
call mpi_isend(y%combuf(snd_pt),nesd,&
|
||
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
|
& p2ptag,icomm,y%comid(i,1),iret)
|
||
|
end if
|
||
12 years ago
|
|
||
10 years ago
|
if(iret /= mpi_success) then
|
||
|
ierr(1) = iret
|
||
|
info=psb_err_mpi_error_
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
12 years ago
|
end if
|
||
10 years ago
|
|
||
12 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
10 years ago
|
end if
|
||
12 years ago
|
|
||
10 years ago
|
if (do_recv) then
|
||
|
if (debug) write(*,*) me,' do_Recv'
|
||
|
if (.not.allocated(y%comid)) then
|
||
|
!
|
||
|
! No matching send? Something is wrong....
|
||
|
!
|
||
|
info=psb_err_mpi_error_
|
||
|
ierr(1) = -2
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
|
call psb_realloc(totxch,prcid,info)
|
||
12 years ago
|
|
||
10 years ago
|
if (debug) write(*,*) me,' wait'
|
||
12 years ago
|
pnti = 1
|
||
10 years ago
|
p2ptag = psb_double_swap_tag
|
||
12 years ago
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
10 years ago
|
snd_pt = 1+pnti+nerv+psb_n_elem_send_
|
||
|
rcv_pt = 1+pnti+psb_n_elem_recv_
|
||
12 years ago
|
|
||
10 years ago
|
if (proc_to_comm /= me)then
|
||
|
if (nesd>0) then
|
||
|
call mpi_wait(y%comid(i,1),p2pstat,iret)
|
||
|
if(iret /= mpi_success) then
|
||
|
ierr(1) = iret
|
||
|
info=psb_err_mpi_error_
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
|
end if
|
||
|
if (nerv>0) then
|
||
|
call mpi_wait(y%comid(i,2),p2pstat,iret)
|
||
|
if(iret /= mpi_success) then
|
||
|
ierr(1) = iret
|
||
|
info=psb_err_mpi_error_
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
12 years ago
|
end if
|
||
|
else if (proc_to_comm == me) then
|
||
|
if (nesd /= nerv) then
|
||
|
write(psb_err_unit,*) &
|
||
|
& 'Fatal error in swapdata: mismatch on self send',&
|
||
|
& nerv,nesd
|
||
|
end if
|
||
10 years ago
|
y%combuf(rcv_pt:rcv_pt+nerv-1) = y%combuf(snd_pt:snd_pt+nesd-1)
|
||
12 years ago
|
end if
|
||
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
|
||
10 years ago
|
if (debug) write(*,*) me,' scatter'
|
||
12 years ago
|
pnti = 1
|
||
|
snd_pt = 1
|
||
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
10 years ago
|
idx_pt = 1+pnti+psb_n_elem_recv_
|
||
|
snd_pt = 1+pnti+nerv+psb_n_elem_send_
|
||
|
rcv_pt = 1+pnti+psb_n_elem_recv_
|
||
12 years ago
|
|
||
10 years ago
|
if (debug) write(0,*)me,' Received from: ',prcid(i),&
|
||
|
& y%combuf(rcv_pt:rcv_pt+nerv-1)
|
||
10 years ago
|
call y%sct(rcv_pt,nerv,idx,beta)
|
||
12 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
|
||
|
|
||
10 years ago
|
!
|
||
|
! Then wait
|
||
|
!
|
||
|
if (debug) write(*,*) me,' wait'
|
||
|
call y%device_wait()
|
||
|
if (debug) write(*,*) me,' free buffer'
|
||
|
call y%free_buffer(info)
|
||
|
if (info == 0) call y%free_comid(info)
|
||
|
if (info /= 0) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
|
goto 9999
|
||
|
end if
|
||
|
if (debug) write(*,*) me,' done'
|
||
12 years ago
|
end if
|
||
|
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
10 years ago
|
return
|
||
12 years ago
|
end subroutine psi_dswap_vidx_vect
|
||
|
|
||
10 years ago
|
!
|
||
|
!
|
||
|
! Subroutine: psi_dswapdata_multivect
|
||
|
! Data exchange among processes.
|
||
|
!
|
||
|
! Takes care of Y an exanspulated multivector.
|
||
|
!
|
||
|
!
|
||
|
!
|
||
|
subroutine psi_dswapdata_multivect(flag,beta,y,desc_a,work,info,data)
|
||
|
|
||
|
use psi_mod, psb_protect_name => psi_dswapdata_multivect
|
||
|
use psb_d_base_multivect_mod
|
||
|
use psb_error_mod
|
||
|
use psb_desc_mod
|
||
|
use psb_penv_mod
|
||
|
#ifdef MPI_MOD
|
||
|
use mpi
|
||
|
#endif
|
||
|
implicit none
|
||
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
|
|
||
|
integer(psb_ipk_), intent(in) :: flag
|
||
|
integer(psb_ipk_), intent(out) :: info
|
||
|
class(psb_d_base_multivect_type) :: y
|
||
|
real(psb_dpk_) :: beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
|
type(psb_desc_type), target :: desc_a
|
||
|
integer(psb_ipk_), optional :: data
|
||
|
|
||
|
! locals
|
||
|
integer(psb_ipk_) :: ictxt, np, me, icomm, idxs, idxr, totxch, data_, err_act
|
||
|
class(psb_i_base_vect_type), pointer :: d_vidx
|
||
|
character(len=20) :: name
|
||
|
|
||
|
info=psb_success_
|
||
|
name='psi_swap_datav'
|
||
|
call psb_erractionsave(err_act)
|
||
|
|
||
|
ictxt=desc_a%get_context()
|
||
|
icomm = desc_a%get_mpic()
|
||
|
|
||
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
|
info=psb_err_context_error_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
if (.not.psb_is_asb_desc(desc_a)) then
|
||
|
info=psb_err_invalid_cd_state_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
if(present(data)) then
|
||
|
data_ = data
|
||
|
else
|
||
|
data_ = psb_comm_halo_
|
||
|
end if
|
||
|
|
||
|
call desc_a%get_list(data_,d_vidx,totxch,idxr,idxs,info)
|
||
|
if (info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_internal_error_,name,a_err='psb_cd_get_list')
|
||
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
call psi_swapdata(ictxt,icomm,flag,beta,y,d_vidx,totxch,idxs,idxr,work,info)
|
||
|
if (info /= psb_success_) goto 9999
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
|
return
|
||
|
end subroutine psi_dswapdata_multivect
|
||
|
|
||
|
|
||
|
!
|
||
|
!
|
||
|
! Subroutine: psi_dswap_vidx_multivect
|
||
|
! Data exchange among processes.
|
||
|
!
|
||
|
! Takes care of Y an exanspulated multivector. Relies on the gather/scatter methods
|
||
|
! of multivectors.
|
||
|
!
|
||
|
! The real workhorse: the outer routine will only choose the index list
|
||
|
! this one takes the index list and does the actual exchange.
|
||
|
!
|
||
|
!
|
||
|
!
|
||
|
subroutine psi_dswap_vidx_multivect(iictxt,iicomm,flag,beta,y,idx, &
|
||
|
& totxch,totsnd,totrcv,work,info)
|
||
|
|
||
|
use psi_mod, psb_protect_name => psi_dswap_vidx_multivect
|
||
|
use psb_error_mod
|
||
|
use psb_realloc_mod
|
||
|
use psb_desc_mod
|
||
|
use psb_penv_mod
|
||
|
use psb_d_base_multivect_mod
|
||
|
#ifdef MPI_MOD
|
||
|
use mpi
|
||
|
#endif
|
||
|
implicit none
|
||
|
#ifdef MPI_H
|
||
|
include 'mpif.h'
|
||
|
#endif
|
||
|
|
||
|
integer(psb_ipk_), intent(in) :: iictxt,iicomm,flag
|
||
|
integer(psb_ipk_), intent(out) :: info
|
||
|
class(psb_d_base_multivect_type) :: y
|
||
|
real(psb_dpk_) :: beta
|
||
|
real(psb_dpk_), target :: work(:)
|
||
|
class(psb_i_base_vect_type), intent(inout) :: idx
|
||
|
integer(psb_ipk_), intent(in) :: totxch,totsnd, totrcv
|
||
|
|
||
|
! locals
|
||
|
integer(psb_mpik_) :: ictxt, icomm, np, me,&
|
||
|
& proc_to_comm, p2ptag, p2pstat(mpi_status_size), iret
|
||
|
integer(psb_mpik_), allocatable :: prcid(:)
|
||
|
integer(psb_ipk_) :: nesd, nerv,&
|
||
|
& err_act, i, idx_pt, totsnd_, totrcv_,&
|
||
|
& snd_pt, rcv_pt, pnti, n
|
||
|
integer(psb_ipk_) :: ierr(5)
|
||
|
logical :: swap_mpi, swap_sync, swap_send, swap_recv,&
|
||
|
& albf,do_send,do_recv
|
||
|
logical, parameter :: usersend=.false., debug=.false.
|
||
|
character(len=20) :: name
|
||
|
|
||
|
info=psb_success_
|
||
|
name='psi_swap_datav'
|
||
|
call psb_erractionsave(err_act)
|
||
|
ictxt = iictxt
|
||
|
icomm = iicomm
|
||
|
|
||
|
call psb_info(ictxt,me,np)
|
||
|
if (np == -1) then
|
||
|
info=psb_err_context_error_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
endif
|
||
|
|
||
10 years ago
|
n = y%get_ncols()
|
||
10 years ago
|
|
||
|
swap_mpi = iand(flag,psb_swap_mpi_) /= 0
|
||
|
swap_sync = iand(flag,psb_swap_sync_) /= 0
|
||
|
swap_send = iand(flag,psb_swap_send_) /= 0
|
||
|
swap_recv = iand(flag,psb_swap_recv_) /= 0
|
||
|
do_send = swap_mpi .or. swap_sync .or. swap_send
|
||
|
do_recv = swap_mpi .or. swap_sync .or. swap_recv
|
||
|
|
||
|
totrcv_ = totrcv * n
|
||
|
totsnd_ = totsnd * n
|
||
|
call idx%sync()
|
||
|
|
||
|
if (debug) write(*,*) me,'Internal buffer'
|
||
|
if (do_send) then
|
||
|
if (allocated(y%comid)) then
|
||
|
!
|
||
|
! Unfinished communication? Something is wrong....
|
||
|
!
|
||
|
info=psb_err_mpi_error_
|
||
|
ierr(1) = -2
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
|
if (debug) write(*,*) me,'do_send start'
|
||
|
call y%new_buffer(size(idx%v),info)
|
||
|
call y%new_comid(totxch,info)
|
||
|
call psb_realloc(totxch,prcid,info)
|
||
|
! First I post all the non blocking receives
|
||
|
pnti = 1
|
||
10 years ago
|
snd_pt = totrcv_+1
|
||
|
rcv_pt = 1
|
||
10 years ago
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
|
call psb_get_rank(prcid(i),ictxt,proc_to_comm)
|
||
|
if ((nerv>0).and.(proc_to_comm /= me)) then
|
||
|
if (debug) write(*,*) me,'Posting receive from',prcid(i),rcv_pt
|
||
|
p2ptag = psb_double_swap_tag
|
||
10 years ago
|
call mpi_irecv(y%combuf(rcv_pt),n*nerv,&
|
||
10 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
|
& p2ptag, icomm,y%comid(i,2),iret)
|
||
|
end if
|
||
10 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
10 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
if (debug) write(*,*) me,' Gather '
|
||
|
!
|
||
|
! Then gather for sending.
|
||
|
!
|
||
|
pnti = 1
|
||
10 years ago
|
snd_pt = totrcv_+1
|
||
|
rcv_pt = 1
|
||
10 years ago
|
do i=1, totxch
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
10 years ago
|
idx_pt = 1+pnti+nerv+psb_n_elem_send_
|
||
|
call y%gth(idx_pt,snd_pt,nesd,idx)
|
||
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
10 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
|
||
|
!
|
||
|
! Then wait
|
||
|
!
|
||
|
call y%device_wait()
|
||
|
|
||
|
if (debug) write(*,*) me,' isend'
|
||
|
!
|
||
|
! Then send
|
||
|
!
|
||
|
|
||
|
pnti = 1
|
||
10 years ago
|
snd_pt = totrcv_+1
|
||
10 years ago
|
rcv_pt = 1
|
||
|
p2ptag = psb_double_swap_tag
|
||
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
|
|
||
|
if ((nesd>0).and.(proc_to_comm /= me)) then
|
||
10 years ago
|
call mpi_isend(y%combuf(snd_pt),n*nesd,&
|
||
10 years ago
|
& psb_mpi_r_dpk_,prcid(i),&
|
||
|
& p2ptag,icomm,y%comid(i,1),iret)
|
||
|
end if
|
||
|
|
||
|
if(iret /= mpi_success) then
|
||
|
ierr(1) = iret
|
||
|
info=psb_err_mpi_error_
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
10 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
10 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
end if
|
||
|
|
||
|
if (do_recv) then
|
||
|
if (debug) write(*,*) me,' do_Recv'
|
||
|
if (.not.allocated(y%comid)) then
|
||
|
!
|
||
|
! No matching send? Something is wrong....
|
||
|
!
|
||
|
info=psb_err_mpi_error_
|
||
|
ierr(1) = -2
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
|
call psb_realloc(totxch,prcid,info)
|
||
|
|
||
|
if (debug) write(*,*) me,' wait'
|
||
|
pnti = 1
|
||
10 years ago
|
snd_pt = totrcv_+1
|
||
|
rcv_pt = 1
|
||
10 years ago
|
p2ptag = psb_double_swap_tag
|
||
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
|
if (proc_to_comm /= me)then
|
||
|
if (nesd>0) then
|
||
|
call mpi_wait(y%comid(i,1),p2pstat,iret)
|
||
|
if(iret /= mpi_success) then
|
||
|
ierr(1) = iret
|
||
|
info=psb_err_mpi_error_
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
|
end if
|
||
|
if (nerv>0) then
|
||
|
call mpi_wait(y%comid(i,2),p2pstat,iret)
|
||
|
if(iret /= mpi_success) then
|
||
|
ierr(1) = iret
|
||
|
info=psb_err_mpi_error_
|
||
|
call psb_errpush(info,name,i_err=ierr)
|
||
|
goto 9999
|
||
|
end if
|
||
|
end if
|
||
|
else if (proc_to_comm == me) then
|
||
|
if (nesd /= nerv) then
|
||
|
write(psb_err_unit,*) &
|
||
|
& 'Fatal error in swapdata: mismatch on self send',&
|
||
|
& nerv,nesd
|
||
|
end if
|
||
10 years ago
|
y%combuf(rcv_pt:rcv_pt+n*nerv-1) = y%combuf(snd_pt:snd_pt+n*nesd-1)
|
||
10 years ago
|
end if
|
||
10 years ago
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
10 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
10 years ago
|
|
||
10 years ago
|
end do
|
||
|
|
||
|
if (debug) write(*,*) me,' scatter'
|
||
|
pnti = 1
|
||
10 years ago
|
snd_pt = totrcv_+1
|
||
10 years ago
|
rcv_pt = 1
|
||
|
do i=1, totxch
|
||
|
proc_to_comm = idx%v(pnti+psb_proc_id_)
|
||
|
nerv = idx%v(pnti+psb_n_elem_recv_)
|
||
|
nesd = idx%v(pnti+nerv+psb_n_elem_send_)
|
||
|
idx_pt = 1+pnti+psb_n_elem_recv_
|
||
|
|
||
|
if (debug) write(0,*)me,' Received from: ',prcid(i),&
|
||
10 years ago
|
& y%combuf(rcv_pt:rcv_pt+n*nerv-1)
|
||
|
call y%sct(idx_pt,rcv_pt,nerv,idx,beta)
|
||
|
rcv_pt = rcv_pt + n*nerv
|
||
|
snd_pt = snd_pt + n*nesd
|
||
10 years ago
|
pnti = pnti + nerv + nesd + 3
|
||
|
end do
|
||
|
|
||
|
|
||
|
!
|
||
|
! Then wait
|
||
|
!
|
||
|
if (debug) write(*,*) me,' wait'
|
||
|
call y%device_wait()
|
||
|
if (debug) write(*,*) me,' free buffer'
|
||
|
call y%free_buffer(info)
|
||
|
if (info == 0) call y%free_comid(info)
|
||
|
if (info /= 0) then
|
||
|
call psb_errpush(psb_err_alloc_dealloc_,name)
|
||
|
goto 9999
|
||
|
end if
|
||
|
if (debug) write(*,*) me,' done'
|
||
|
end if
|
||
|
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
|
9999 call psb_error_handler(ictxt,err_act)
|
||
|
|
||
|
return
|
||
|
end subroutine psi_dswap_vidx_multivect
|
||
|
|