Exemple #1
0
def bcast(input_list: PList, src_pid: int) -> PList:
    """
    Broadcast the data at source processor to all processors.

    Example::

        >>> from pyske.core import PList, par
        >>> bcast(PList.from_seq([42]), 0).to_seq() == \
                list(map(lambda _: 42, par.procs()))
        True

    :param input_list: a parallel list.
    :param src_pid: the source processor identifier.
        Pre-condition: ``src_pid in par.procs()``
    :return: a parallel list.
    """
    assert src_pid in par.procs()
    size = input_list.distribution[src_pid]
    nprocs = len(par.procs())
    return input_list \
        .get_partition() \
        .mapi(lambda pid, lst: list(map(lambda _: lst, par.procs())) if pid == src_pid else []) \
        .flatten(Distribution([nprocs if pid == src_pid else 0 for pid in par.procs()])) \
        .distribute(Distribution(map(lambda _: 1, par.procs()))) \
        .flatten(Distribution(map(lambda _: size, par.procs())))
def _pyske_bcast(input_list: PList):
    size = input_list.distribution[0]
    nprocs = len(par.procs())
    return input_list\
        .get_partition()\
        .mapi(lambda pid, a_list: list(map(lambda _: a_list, par.procs())) if pid == 0 else []) \
        .flatten(Distribution([nprocs if pid == 0 else 0 for pid in par.procs()])) \
        .distribute(Distribution(map(lambda _: 1, par.procs())))\
        .flatten(Distribution(map(lambda _: size, par.procs())))
Exemple #3
0
def test_balance_distr():
    # pylint: disable=missing-docstring
    data = generate_str_plist()
    size = data.length()
    dst = par.randpid()
    distr = Distribution([0 for _ in par.procs()])
    distr[dst] = size
    res = get_distribution(data.distribute(distr).balance())
    exp = Distribution.balanced(size)
    assert res == exp
Exemple #4
0
def test_scatter_range_distr():
    # pylint: disable=missing-docstring
    data = generate_str_plist()
    min_, max_ = rand_min_max(data.length())
    res = get_distribution(data.scatter_range(range(min_, max_)))
    exp = Distribution.balanced(max_ - min_)
    assert res == exp
Exemple #5
0
def test_distribute_data():
    # pylint: disable=missing-docstring
    data = SList.init(int, 42)
    size = data.length()
    distr = Distribution([size])
    res = data.distribute(distr)
    exp = SList(range(0, size))
    assert res == exp
Exemple #6
0
def test_scatter_distr():
    # pylint: disable=missing-docstring
    data = generate_str_plist()
    src = par.randpid()
    distr = get_distribution(data)
    res = get_distribution(data.scatter(src))
    exp = Distribution.balanced(distr[src])
    assert res == exp
Exemple #7
0
def test_distribute_distr():
    # pylint: disable=missing-docstring
    data = generate_str_plist()
    size = data.length()
    dst = par.randpid()
    exp = Distribution([0 for _ in par.procs()])
    exp[dst] = size
    res = get_distribution(data.distribute(exp))
    assert res == exp
Exemple #8
0
def test_distribute_data():
    # pylint: disable=missing-docstring
    dst = par.randpid()
    data = generate_int_plist()
    size = data.length()
    distr = Distribution([0 for _ in par.procs()])
    distr[dst] = size
    res = data.distribute(distr).to_seq()
    exp = SList(range(0, size))
    assert res == exp