Exemplo n.º 1
0
def main():
    comm = MPI.COMM_WORLD
    print_mpi = common.create_print_mpi(comm)
    print_mpi('Hello World!')

    if comm.rank == 0 or comm.rank == 1:
        intracomm = comm.Split(color=0, key=comm.rank)
    else:
        intracomm = comm.Split(color=1, key=comm.rank)

    print_mpi('Hello Intra World!: [{}/{}]'.format(intracomm.rank,
                                                   intracomm.size))

    if comm.rank == 0 or comm.rank == 1:
        remote_leader = 2  # Rank in MPI_COMM_WORLD
        local_leader = 1  # Rank in intracomm
    else:
        remote_leader = 1  # Rank in MPI_COMM_WORLD
        local_leader = 0  # Rank in intracomm

    intercomm = intracomm.Create_intercomm(local_leader, MPI.COMM_WORLD,
                                           remote_leader)

    print_mpi('Hello Inter World!: [{}/{}]'.format(intercomm.rank,
                                                   intercomm.size))

    if comm.rank == 0 or comm.rank == 1:
        send_buf = 0
        root = MPI.ROOT if intercomm.rank == local_leader else MPI.PROC_NULL
    else:
        send_buf = 16
        root = 1

    recv_buf = intercomm.reduce(send_buf, root=root)
    print(recv_buf)
Exemplo n.º 2
0
def main():
    comm = MPI.COMM_WORLD
    rank = comm.rank
    size = comm.size

    print_mpi = common.create_print_mpi(comm)

    send_buf = np.array([1, 2], dtype=np.float32)
    print_mpi(send_buf)
    if rank == 1:
        comm.send(send_buf, dest=0, tag=11)

    if rank == 0:
        req = comm.irecv(source=1, tag=11)
        flag, status = req.test()
        if not flag:
            print('sleeping...')
            time.sleep(10)
            print('woke up')
            flag, status = req.test()
            if not flag:
                print('nothing comming..., canceling')
                req.Cancel()
            else:
                print(status)
        else:
            print(status)
Exemplo n.º 3
0
def bcast(comm):
    n = 8192

    print_mpi = common.create_print_mpi(comm)

    # Allocate buffer and set value
    if comm.rank == 0:
        buf = numpy.arange(n).astype(numpy.float32)
    else:
        buf = numpy.empty(n).astype(numpy.float32)

    # Broadcast
    print_mpi('B: {}'.format(buf), 1)
    print_mpi('Bcast ...')
    comm.Bcast([buf, MPI.FLOAT], root=0)
    print_mpi('Bcast done')
    print_mpi('A: {}'.format(buf), 1)

    print_mpi('========', 0)

    if comm.rank == 0:
        buf = numpy.arange(n).astype(numpy.float32)
    else:
        buf = numpy.array([])

    # Broadcast
    print_mpi('B: {}'.format(buf), 1)
    print_mpi('Bcast ...')
    buf = comm.bcast(buf, root=0)
    print_mpi('Bcast done')
    print_mpi('A: {}'.format(buf), 1)
Exemplo n.º 4
0
def main():
    comm = MPI.COMM_WORLD
    print_mpi = common.create_print_mpi(comm)

    # ================================================================

    if comm.rank == 0:
        send_buf = 0
    else:
        send_buf = 1

    recv_buf = comm.allgather(send_buf)
    print(recv_buf)

    # ================================================================

    if comm.rank == 0:
        send_buf = [0, 0, 0]
    else:
        send_buf = [1, 1, 1]

    recv_buf = comm.allgather(send_buf)
    print(recv_buf)

    # ================================================================

    if comm.rank == 0:
        send_buf = np.zeros((2, ))
    else:
        send_buf = np.arange(3)

    recv_buf = comm.allgather(send_buf)
    print(recv_buf)
Exemplo n.º 5
0
def main():
    comm = MPI.COMM_WORLD
    rank = comm.rank
    size = comm.size
    print_mpi = common.create_print_mpi(comm)

    if comm.rank == 0:
        buf = np.array([1, 2], dtype=np.float32)
    else:
        buf = np.array([0, 0], dtype=np.float32)

    win = MPI.Win.Create(buf, comm=comm)

    print_mpi(buf)

    window_owner_rank = 1
    win.Fence()
    if comm.rank == 0:
        win.Lock(window_owner_rank)
        win.Put(buf, window_owner_rank)
        win.Unlock(window_owner_rank)
    win.Fence()

    print_mpi(buf)