subroutine ALL_ALL_j(p,ptrans,iaction)
! purpose: do all-to-all communication
! data are only distributed over the j-direction for p
! data are only distributed over the k-direction for ptrans
! NOTE: p (0:imax+1 etc
! ptrans(1:imax etc
use modglobal, only : imax,isen,jmax,jsen,jtot,kmax
use modmpi, only : comm3d,mpierr,my_real,nprocs, barrou
implicit none
integer iaction
real p(0:imax+1,0:jmax+1,0:kmax+1)
real ptrans(1:isen,1:jtot,1:kmax)
! help arrays for sending and receiving
real,allocatable,dimension(:) :: bufin, bufout
! help variables
integer ii, jbegin, jend, proc
integer ibegin, iend
integer i, j, k
allocate(bufin(imax*jmax*kmax),bufout(imax*jmax*kmax))
if(iaction==0)then
ii = 0
do proc=0,nprocs-1
ibegin = (proc)*isen+1
iend = (proc+1)*isen
do i=ibegin,iend
do j=1,jmax
do k=1,kmax
ii = ii + 1
bufin(ii) = p(i,j,k)
enddo
enddo
enddo
enddo
ii = 0
! call barrou()
call MPI_ALLTOALL(bufin, (isen*jsen*kmax),MY_REAL, &
bufout,(isen*jsen*kmax),MY_REAL, &
comm3d,mpierr)
! call barrou()
ii = 0
do proc = 0,nprocs-1
jbegin = proc *jsen + 1
jend = (proc+1)*jsen
do i=1,isen
do j=jbegin,jend
do k=1,kmax
ii = ii + 1
ptrans(i,j,k) = bufout(ii)
enddo
enddo
enddo
enddo
! call barrou()
elseif(iaction==1)then
ii = 0
do proc = 0,nprocs-1
jbegin = proc *jsen + 1
jend = (proc+1)*jsen
do i=1,isen
do j=jbegin,jend
do k=1,kmax
ii = ii + 1
bufin(ii) = ptrans(i,j,k)
enddo
enddo
enddo
enddo
! call barrou()
call MPI_ALLTOALL(bufin, (isen*jsen*kmax),MY_REAL, &
bufout,(isen*jsen*kmax),MY_REAL, &
comm3d,mpierr)
! call barrou()
ii = 0
do proc=0,nprocs-1
ibegin = (proc)*isen+1
iend = (proc+1)*isen
do i=ibegin,iend
do j=1,jmax
do k=1,kmax
ii = ii + 1
p(i,j,k) = bufout(ii)
enddo
enddo
enddo
enddo
! call barrou()
endif
deallocate(bufin,bufout)
return
end subroutine ALL_ALL_j