subroutine ArrDescrCreateReaderComm(arrdes, full_comm, num_readers, rc)
type(ArrDescr), intent(inout) :: arrdes
integer, intent(in) :: full_comm
integer, intent(in) :: num_readers
integer, optional, intent(out) :: rc
integer :: status, nx, ny, color, ny_by_readers, myid, j
nx = size(arrdes%i1)
ny = size(arrdes%j1)
_ASSERT(num_readers <= ny,'num readers must be less than or equal to NY')
_ASSERT(mod(ny,num_readers)==0,'num readers must evenly divide NY')
call mpi_comm_rank(full_comm,myid, status)
_VERIFY(status)
color = arrdes%NX0
call MPI_COMM_SPLIT(full_comm, color, MYID, arrdes%Ycomm, status)
_VERIFY(status)
color = arrdes%NY0
call MPI_COMM_SPLIT(full_comm, color, MYID, arrdes%Xcomm, status)
_VERIFY(status)
ny_by_readers = ny/num_readers
if (mod(myid,nx*ny/num_readers) == 0) then
color = 0
else
color = MPI_UNDEFINED
endif
call MPI_COMM_SPLIT(full_comm, color, MYID, arrdes%readers_comm, status)
_VERIFY(status)
if (num_readers==ny) then
arrdes%IOscattercomm = arrdes%Xcomm
else
j = arrdes%NY0 - mod(arrdes%NY0-1,ny_by_readers)
call MPI_COMM_SPLIT(full_comm, j, MYID, arrdes%IOscattercomm, status)
_VERIFY(status)
endif
_RETURN(_SUCCESS)
end subroutine ArrDescrCreateReaderComm