Пример #1
0
def test_distribute():
    class MyComm(object):
        def __init__(self, rank, size):
            self.rank = rank
            self.size = size

    if size > 1:
        return

    def func(a, r, shape, shapes):
        assert_equal(a[r], shape[0])
        assert_equal(shapes[r], shape)

    for n in range(10):
        for sz in range(1, 7):
            work = np.zeros(n, int)
            for i in range(n):
                work[i] = i % sz
            a = np.zeros(sz, int)
            for r in range(sz):
                a[r] = sum(work == r)
            stop = tuple(np.cumsum(a))
            start = (0, ) + stop[:-1]
            comm = MyComm(0, sz)
            for s in [(), (1, ), (3, 4)]:
                shapes = distribute_shapes((n, ) + s, comm=comm)
                for r in range(sz):
                    shape = distribute_shape((n, ) + s, rank=r, size=sz)
                    yield func, a, r, shape, shapes
                    if len(s) > 0:
                        continue
                    sl = slice(start[r], stop[r])
                    yield assert_eq, sl, split(n, sz, r)
Пример #2
0
def test_distribute():
    class MyComm(object):
        def __init__(self, rank, size):
            self.rank = rank
            self.size = size
    if size > 1:
        return

    def func(a, r, shape, shapes):
        assert_equal(a[r], shape[0])
        assert_equal(shapes[r], shape)

    for n in range(10):
        for sz in range(1, 7):
            work = np.zeros(n, int)
            for i in range(n):
                work[i] = i % sz
            a = np.zeros(sz, int)
            for r in range(sz):
                a[r] = sum(work == r)
            stop = tuple(np.cumsum(a))
            start = (0,) + stop[:-1]
            comm = MyComm(0, sz)
            for s in [(), (1,), (3, 4)]:
                shapes = distribute_shapes((n,) + s, comm=comm)
                for r in range(sz):
                    shape = distribute_shape((n,) + s, rank=r, size=sz)
                    yield func, a, r, shape, shapes
                    if len(s) > 0:
                        continue
                    sl = slice(start[r], stop[r])
                    yield assert_eq, sl, split(n, sz, r)
Пример #3
0
def test_read():
    shape_global = ref.shape
    shape_local = distribute_shape(shape_global)
    assert_equal(shape_local, lmap.shape)

    lmaps = MPI.COMM_WORLD.allgather(lmap)
    gmap = np.concatenate(lmaps, axis=0).magnitude

    assert_all_eq(ref, gmap)
Пример #4
0
def test_read():
    shape_global = ref.shape
    shape_local = distribute_shape(shape_global)
    assert_equal(shape_local, lmap.shape)

    lmaps = MPI.COMM_WORLD.allgather(lmap)
    gmap = np.concatenate(lmaps, axis=0).magnitude

    assert_all_eq(ref, gmap)
Пример #5
0
 def __init__(self, mask, operator=MPI.SUM, commin=MPI.COMM_WORLD,
              **keywords):
     commout = commin
     shapeout = mask.size - int(np.sum(mask))
     shapein = distribute_shape(mask.shape, comm=commin)
     Operator.__init__(self, shapein=shapein, shapeout=shapeout,
                       commin=commin, commout=commout, **keywords)
     self.mask = mask
     self.chunk_size = product(mask.shape[1:])
     self.operator = operator
Пример #6
0
 def __init__(self,
              mask,
              operator=MPI.SUM,
              commin=MPI.COMM_WORLD,
              **keywords):
     commout = commin
     shapeout = mask.size - int(np.sum(mask))
     shapein = distribute_shape(mask.shape, comm=commin)
     Operator.__init__(self,
                       shapein=shapein,
                       shapeout=shapeout,
                       commin=commin,
                       commout=commout,
                       **keywords)
     self.mask = mask
     self.chunk_size = product(mask.shape[1:])
     self.operator = operator
Пример #7
0
 def func(comm, s1, s2):
     shape_global = (s1,) + s2
     shape_local = distribute_shape(shape_global, comm=comm)
     shape_global2 = combine_shape(shape_local, comm=comm)
     assert shape_global == shape_global2
Пример #8
0
 def func(comm, s1, s2):
     shape_global = (s1, ) + s2
     shape_local = distribute_shape(shape_global, comm=comm)
     shape_global2 = combine_shape(shape_local, comm=comm)
     assert shape_global == shape_global2