def _alltoall_subproblem(local_nodes, num_copies):
    remote_node = local_nodes
    local_end = (local_nodes * local_nodes)
    num_remote_pairs = (((num_copies - 1) * local_nodes) * local_nodes)
    remote_out_end = (local_end + num_remote_pairs)
    num_chunks = (remote_out_end + num_remote_pairs)

    def cases(chunk, local, remote_out, remote_in):
        if (chunk < local_end):
            return local(chunk)
        elif (chunk < remote_out_end):
            return remote_out((chunk - local_end))
        else:
            return remote_in((chunk - remote_out_end))

    def pre(rank, chunk):
        return cases(chunk, (lambda c: (rank == (c % local_nodes))), (lambda c: (rank == ((c // (num_copies - 1)) % local_nodes))), (lambda c: (rank == remote_node)))

    def post(rank, chunk):
        return cases(chunk, (lambda c: (rank == (c // local_nodes))), (lambda c: (rank == remote_node)), (lambda c: (rank == ((c // (num_copies - 1)) // local_nodes))))

    def trigger(rank, chunk):
        if (rank == remote_node):
            return cases(chunk, (lambda c: None), (lambda c: (chunk + num_remote_pairs)), (lambda c: (chunk - num_remote_pairs)))
        else:
            return None
    return build_collective(f'AlltoallSubproblem(n={local_nodes},copies={num_copies})', (local_nodes + 1), num_chunks, pre, post, trigger=trigger)
def _alltoall_subproblem(local_nodes, num_copies):
    remote_node = local_nodes
    local_end = (local_nodes * local_nodes)
    num_remote_pairs = (((num_copies - 1) * local_nodes) * local_nodes)
    remote_out_end = (local_end + num_remote_pairs)
    num_chunks = (remote_out_end + num_remote_pairs)

    def cases(chunk, local, remote_out, remote_in):
        if (chunk < local_end):
            return local(chunk)
        elif (chunk < remote_out_end):
            return remote_out((chunk - local_end))
        else:
            return remote_in((chunk - remote_out_end))

    def pre(rank, chunk):
        return cases(chunk, (lambda c: (rank == (c % local_nodes))), (lambda c: (rank == ((c // (num_copies - 1)) % local_nodes))), (lambda c: (rank == remote_node)))

    def post(rank, chunk):
        return cases(chunk, (lambda c: (rank == (c // local_nodes))), (lambda c: (rank == remote_node)), (lambda c: (rank == ((c // (num_copies - 1)) // local_nodes))))

    def trigger(rank, chunk):
        if (rank == remote_node):
            return cases(chunk, (lambda c: None), (lambda c: (chunk + num_remote_pairs)), (lambda c: (chunk - num_remote_pairs)))
        else:
            return None
    return build_collective(f'AlltoallSubproblem(n={local_nodes},copies={num_copies})', (local_nodes + 1), num_chunks, pre, post, trigger=trigger)