subroutine receive_group_assignment_matrix(world_comm, ids, matrix)
!! Receive shard-assignment ids and polymer matrix from rank 0.
type(comm_t), intent(in) :: world_comm
integer(int64), allocatable, intent(out) :: ids(:)
integer, allocatable, intent(out) :: matrix(:, :)
integer(int64) :: n_rows
integer(int32) :: n_cols
integer, allocatable :: buf(:)
type(MPI_Status) :: status
type(request_t) :: req
call irecv(world_comm, n_rows, 0, TAG_GROUP_ASSIGN, req)
call wait(req)
allocate (ids(n_rows))
call recv(world_comm, ids, 0, TAG_GROUP_ASSIGN, status)
call irecv(world_comm, n_cols, 0, TAG_GROUP_POLYMERS, req)
call wait(req)
allocate (matrix(int(n_rows), n_cols))
if (n_rows > 0_int64 .and. n_cols > 0) then
allocate (buf(n_rows*n_cols))
call recv(world_comm, buf, 0, TAG_GROUP_POLYMERS, status)
matrix = reshape(buf, [int(n_rows), n_cols])
deallocate (buf)
else
allocate (buf(0))
call recv(world_comm, buf, 0, TAG_GROUP_POLYMERS, status)
deallocate (buf)
end if
end subroutine receive_group_assignment_matrix