示例#1
0
    def fail(self, test, ranks, t0):
        if mpi.rank in ranks:
            if sys.version_info >= (2, 4, 0, 'final', 0):
                tb = traceback.format_exc()
            else:  # Python 2.3! XXX
                tb = ''
                traceback.print_exc()
        else:
            tb = ''
        if mpi.size == 1:
            text = 'FAILED!\n%s\n%s%s' % ('#' * 77, tb, '#' * 77)
            self.write_result(test, text, t0)
        else:
            tbs = {tb: [0]}
            for r in range(1, mpi.size):
                if mpi.rank == r:
                    mpi.send_string(tb, 0)
                elif mpi.rank == 0:
                    tb = mpi.receive_string(r)
                    if tb in tbs:
                        tbs[tb].append(r)
                    else:
                        tbs[tb] = [r]
            if mpi.rank == 0:
                text = ('FAILED! (rank %s)\n%s' %
                        (','.join([str(r) for r in ranks]), '#' * 77))
                for tb, ranks in tbs.items():
                    if tb:
                        text += ('\nRANK %s:\n' %
                                 ','.join([str(r) for r in ranks]))
                        text += '%s%s' % (tb, '#' * 77)
                self.write_result(test, text, t0)

        self.failed.append(test)
示例#2
0
    def fail(self, test, ranks, tb, t0):
        if mpi.size == 1:
            text = 'FAILED!\n%s\n%s%s' % ('#' * 77, tb, '#' * 77)
            self.write_result(test, text, t0)
        else:
            tbs = {tb: [0]}
            for r in range(1, mpi.size):
                if mpi.rank == r:
                    mpi.send_string(tb, 0)
                elif mpi.rank == 0:
                    tb = mpi.receive_string(r)
                    if tb in tbs:
                        tbs[tb].append(r)
                    else:
                        tbs[tb] = [r]
            if mpi.rank == 0:
                text = ('FAILED! (rank %s)\n%s' %
                        (','.join([str(r) for r in ranks]), '#' * 77))
                for tb, ranks in tbs.items():
                    if tb:
                        text += ('\nRANK %s:\n' %
                                 ','.join([str(r) for r in ranks]))
                        text += '%s%s' % (tb, '#' * 77)
                self.write_result(test, text, t0)

        self.failed.append(test)
示例#3
0
    def fail(self, test, ranks, t0):
        if mpi.rank in ranks:
            if sys.version_info >= (2, 4, 0, 'final', 0):
                tb = traceback.format_exc()
            else:  # Python 2.3! XXX
                tb = ''
                traceback.print_exc()
        else:
            tb = ''
        if mpi.size == 1:
            text = 'FAILED!\n%s\n%s%s' % ('#' * 77, tb, '#' * 77)
            self.write_result(test, text, t0)
        else:
            tbs = {tb: [0]}
            for r in range(1, mpi.size):
                if mpi.rank == r:
                    mpi.send_string(tb, 0)
                elif mpi.rank == 0:
                    tb = mpi.receive_string(r)
                    if tb in tbs:
                        tbs[tb].append(r)
                    else:
                        tbs[tb] = [r]
            if mpi.rank == 0:
                text = ('FAILED! (rank %s)\n%s' %
                        (','.join([str(r) for r in ranks]), '#' * 77))
                for tb, ranks in tbs.items():
                    if tb:
                        text += ('\nRANK %s:\n' %
                                 ','.join([str(r) for r in ranks]))
                        text += '%s%s' % (tb, '#' * 77)
                self.write_result(test, text, t0)

        self.failed.append(test)
示例#4
0
def gather_ndarray_dict(data, comm, broadcast=False):
    #data is dict of a numpy array, maybe has different shape in different cpus
    #this function gather them to the all_data in master, all_data is
    # a dict with the lenth world.size
    all_data = {}
    data_len = np.zeros([comm.size], int)
    data_len[comm.rank] = len(data)
    comm.sum(data_len)

    info = np.zeros([np.sum(data_len), 3], int)
    dtypes = [int, float, complex]
    for i, name in enumerate(data):
        base = np.sum(data_len[:comm.rank])
        info[base + i, 0] = len(data[name].shape)
        info[base + i, 1] = comm.rank
        info[base + i, 2] = dtypes.index(data[name].dtype)
    comm.sum(info)

    if comm.rank == 0:
        for name in data:
            all_data[name] = data[name]

        for i in range(1, comm.size):
            base = np.sum(data_len[:i])
            for j in range(data_len[i]):
                shape = np.zeros([info[base + j, 0]], int)
                dtype = dtypes[info[base + j, 2]]
                name = receive_string(i, comm)
                comm.receive(shape, i, 123)
                tmp = np.zeros(shape, dtype)
                comm.receive(tmp, i, 546)
                all_data[name] = tmp

    else:
        for name in data:
            send_string(name, 0, comm)
            shape = np.array(data[name].shape, int)
            comm.ssend(shape, 0, 123)
            comm.ssend(data[name], 0, 546)

    if broadcast:
        num = np.zeros([1], int)
        if comm.rank == 0:
            num[0] = len(all_data)
            comm.broadcast(num, 0)
            for name in all_data:
                broadcast_string(name, 0, comm)
                shape = np.array(all_data[name].shape, int)
                comm.broadcast(shape, 0)
                comm.broadcast(all_data[name], 0)
        else:
            comm.broadcast(num, 0)
            for i in range(num):
                name = broadcast_string(None, 0, comm)
                shape = np.zeros([info[i, 0]], int)
                dtype = dtypes[info[i, 2]]
                comm.broadcast(shape, 0)
                tmp = np.zeros(shape, dtype)
                comm.broadcast(tmp, 0)
                all_data[name] = tmp
    return all_data
示例#5
0
def gather_ndarray_dict(data, comm, broadcast=False):
    #data is dict of a numpy array, maybe has different shape in different cpus
    #this function gather them to the all_data in master, all_data is
    # a dict with the lenth world.size
    all_data = {}
    data_len = np.zeros([comm.size], int)
    data_len[comm.rank] = len(data)
    comm.sum(data_len)
    
    info = np.zeros([np.sum(data_len), 3], int)
    dtypes = [int, float, complex]
    for i, name in enumerate(data):
        base = np.sum(data_len[:comm.rank])
        info[base + i, 0] = len(data[name].shape)
        info[base + i, 1] = comm.rank
        info[base + i, 2] = dtypes.index(data[name].dtype)
    comm.sum(info)
    
    if comm.rank == 0:
        for name in data:
            all_data[name] = data[name]
 
        for i in range(1, comm.size):
            base = np.sum(data_len[:i])
            for j in range(data_len[i]):
                shape = np.zeros([info[base + j, 0]], int)
                dtype = dtypes[info[base + j, 2]]
                name = receive_string(i, comm)
                comm.receive(shape, i, 123)
                tmp = np.zeros(shape, dtype)
                comm.receive(tmp, i, 546)
                all_data[name] = tmp

    else:
        for name in data:
            send_string(name, 0, comm)
            shape = np.array(data[name].shape, int)
            comm.ssend(shape, 0, 123)
            comm.ssend(data[name], 0, 546)
    
    if broadcast:
        num = np.zeros([1], int)
        if comm.rank == 0:
            num[0] = len(all_data)
            comm.broadcast(num, 0)
            for name in all_data:
                broadcast_string(name, 0, comm)
                shape = np.array(all_data[name].shape, int)
                comm.broadcast(shape, 0)
                comm.broadcast(all_data[name], 0)
        else:
            comm.broadcast(num, 0)              
            for i in range(num):
                name = broadcast_string(None, 0, comm)
                shape = np.zeros([info[i, 0]], int)
                dtype = dtypes[info[i, 2]]
                comm.broadcast(shape, 0)
                tmp = np.zeros(shape, dtype)
                comm.broadcast(tmp, 0)
                all_data[name] = tmp
    return all_data