import collections


def _make_shuffle_pcols(n, grid):
  """
  Generates a list of integers instructing `pshuffle` to have each processor
  n units downward.

  Returns e.g.
    (4, 5, 6, 7, 0, 1, 2, 3)
  For n=1, grid=(2, 2, 2), "shift hor"
  """
  Ncore, Nrow, Ncol = grid
  chips_per_pcol = Ncore * Nrow
  out = collections.deque()
  for i in range(Ncol):
    col = tuple(list(range(i * chips_per_pcol, (i + 1) * chips_per_pcol)))
    out.append(col)
  out.rotate(n)
  out = list(out)
  to_return = []
  for tup in out:
    to_return += list(tup)
  return tuple(to_return)