[Python] Issue with MPI Communication in Python (using MPI.COMM_WORLD.isend and...

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I'm working on a parallelized program using mpi4py in Python, and I'm encountering an issue where data is being sent using MPI.COMM_WORLD.isend, but when the receiving process attempts to get the data using MPI.COMM_WORLD.irecv, it ends up receiving None. I’m unsure if the communication is happening correctly or if there’s an issue with my logic.

    Here’s the part of my code where the communication happens:


    if self.color == 0:
    current_point = self.run_MD(self.atoms, self.dyn)
    i += 1
    logging.info(f"Sampled point {i}.")
    for dest in range(1, MPI.COMM_WORLD.Get_size()):
    MPI.COMM_WORLD.isend(current_point, dest=dest, tag=0)

    if req is None:
    req = MPI.COMM_WORLD.irecv(source=1, tag=1)

    if req.Test():
    sampled_points = req.wait()
    logging.info(f"Received {sampled_points}.")
    req = None

    elif self.color == 1:
    if req is None:
    req = MPI.COMM_WORLD.irecv(source=0, tag=0)

    # Get the current point (blocking)
    current_point = req.wait()
    i += 1

    if RANK == 1:
    logging.info(f"Recalculating point {i} with DFT.")
    sampled_points.append(self.recalc_aims(current_point))

    if RANK == 1:
    logging.info(f'len(sampled_points): {len(sampled_points)}')
    req_send = MPI.COMM_WORLD.isend(sampled_points, dest=0, tag=1)
    req_send.wait()
    req = None



    If I don't check using .test(), i.e. using blocking communication, everything works as intended. But somehow, even though .test() evaluates to True, color 0 only receives None for sampled_points. BTW, the communication going in this example from 0 to 1 (sending current_point) works fine.

    Continue reading...

Compartilhe esta Página