def partition(n):
    """
    Constructs block and grid arguments for *n* elements.
    """
    max_gx, max_gy = 65535, 65535
    blocksize = 32
    block = blocksize, 1, 1
    num_blocks = int((n + blocksize - 1) / blocksize)
    if num_blocks < max_gx:
        grid = num_blocks, 1
    else:
        gx = max_gx
        gy = (num_blocks + max_gx - 1) / max_gx
        if gy >= max_gy:
            raise ValueError('vector is too large')
        grid = gx, gy
    return dict(block=block, grid=grid)
