subroutine MAPL_CollectiveWait(request, DstArray, rc)
type (MAPL_COMMRequest), intent(INOUT) :: request
real, pointer, optional :: DstArray(:,:)
integer, optional, intent( OUT) :: rc
integer :: status
integer :: i,j,k,n
integer :: count
REQUEST_TYPE: if(request%RequestType==MAPL_IsGather) then
ROOT_GATH: if(request%amRoot) then
k = 0
PE_GATH: do n=0,request%nDEs-1
count = request%IM(n)*request%JM(n)
if(request%mype/=n) then
if(request%IsPrePosted) then
call MPI_Wait(request%recv(n),MPI_STATUS_IGNORE,status)
_VERIFY(STATUS)
else
call MPI_Recv(request%var(k), count, MPI_REAL, &
n, request%tag, request%comm, MPI_STATUS_IGNORE, status)
_VERIFY(STATUS)
endif
do J=request%J1(n),request%JN(n)
do I=request%I1(n),request%IN(n)
request%DstArray(I,J) = request%var(k)
k = k+1
end do
end do
else
k = k + count
end if
end do PE_GATH
if(present(DstArray)) DstArray => request%DstArray
else
call MPI_WAIT(request%send(0),MPI_STATUS_IGNORE,status)
_VERIFY(STATUS)
endif ROOT_GATH
elseif(request%RequestType==MAPL_IsScatter) then
ROOT_SCAT: if(.not.request%amRoot) then
if(request%IsPrePosted) then
call MPI_Wait(request%recv(0),MPI_STATUS_IGNORE,status)
_VERIFY(STATUS)
else
call MPI_Recv(request%Var, size(request%Var), MPI_REAL, &
request%Root, request%tag, request%comm, &
MPI_STATUS_IGNORE, status)
_VERIFY(status)
endif
k=0
do J=1,request%JM0
do I=1,request%IM0
request%DstArray(I,J) = request%var(k)
k = k+1
end do
end do
else
PE_SCAT: do n=0,request%nDEs-1
if(n /= request%mype) then
call MPI_Wait(request%send(n),MPI_STATUS_IGNORE,status)
_VERIFY(STATUS)
deallocate(request%buff(n)%A)
end if
end do PE_SCAT
deallocate(request%Buff)
end if ROOT_SCAT
if(present(DstArray)) DstArray => request%DstArray
end if REQUEST_TYPE
! Destroy the request
!--------------------
deallocate(request%var )
deallocate(request%recv)
deallocate(request%send)
deallocate(request%i1 )
deallocate(request%in )
deallocate(request%j1 )
deallocate(request%jn )
deallocate(request%im )
deallocate(request%jm )
nullify(request%var )
nullify(request%send )
nullify(request%recv )
nullify(request%DstArray)
if(associated(request%Local_Array)) deallocate(request%Local_Array)
nullify(request%Local_Array)
request%active = .false.
_RETURN(ESMF_SUCCESS)
end subroutine MAPL_CollectiveWait