There's more...

The solution proposed to the deadlock is not the only solution.

There is, for example, a function that unifies the single call that sends a message to a given process and receives another message that comes from another process. This function is called Sendrecv:

Sendrecv(self, sendbuf, int dest=0, int sendtag=0, recvbuf=None, int source=0, int recvtag=0, Status status=None) 

As you can see, the required parameters are the same as the comm.send()  and comm.recv() MPI (in this case, also the function blocks). However, Sendrecv offers the advantage of leaving the communication subsystem responsible for checking the dependencies between sending and receiving, thus avoiding the deadlock.

In this way, the code of the previous example becomes the following:

if rank==1: 
    data_send= "a" 
    destination_process = 5 
    source_process = 5 
    data_received=comm.sendrecv(data_send,dest=
                                destination_process, 
                                source =source_process) 
if rank==5: 
    data_send= "b" 
    destination_process = 1 
    source_process = 1 
    data_received=comm.sendrecv(data_send,dest= 
                                destination_process, 
                                source=source_process) 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.229.113