Home > other >  Mpi4py new people for help
Mpi4py new people for help

Time:10-18

I wrote a piece of code, to try to simulate the parameter server, specify the four processes, process server as a parameter to 0 and 1, 2 and 3 process as a work in progress, when I use the if specified 0,1,2,3 program can be normal, but when I use the if specified process 0 and 1, else the specified process of no. 3 and 4, the program will die card, don't know what the reason, and great god teach
Here is my question code:
Import the random
The from mpi4py import MPI

Comm=MPI.COM M_WORLD
Rank=comm. Get_rank ()
Size=comm. Get_size ()

If rank==0:
Print (" Hello World000000000000000000000 ")
For dest in range (2, the size, 2) :
Data=https://bbs.csdn.net/topics/comm.recv (source=dest, tag=dest)
If rank==1:
Print (" Hello World111111111111111111111 ")
For dest in range (3, size, 2) :
Data=https://bbs.csdn.net/topics/comm.recv (source=dest, tag=dest)
The else:
Data=(1, 10)
https://bbs.csdn.net/topics/random.randintComm. Send (data, dest=rank % 2, tag=rank)
Print (" process {0} sends data {1} to {2} ". The format (rank, data, rank % 2))



When I use two if instead of the else, the program can normal exit:
Import the random
The from mpi4py import MPI

Comm=MPI.COM M_WORLD
Rank=comm. Get_rank ()
Size=comm. Get_size ()

If rank==0:
Print (" Hello World000000000000000000000 ")
For dest in range (2, the size, 2) :
Data=https://bbs.csdn.net/topics/comm.recv (source=dest, tag=dest)
If rank==1:
Print (" Hello World111111111111111111111 ")
For dest in range (3, size, 2) :
Data=https://bbs.csdn.net/topics/comm.recv (source=dest, tag=dest)
If rank==2:
Data=(1, 10)
https://bbs.csdn.net/topics/random.randintComm. Send (data, dest=rank % 2, tag=rank)
Print (" process {0} sends data {1} to {2} ". The format (rank, data, rank % 2))
If rank==3:
Data=(1, 10)
https://bbs.csdn.net/topics/random.randintComm. Send (data, dest=rank % 2, tag=rank)
Print (" process {0} sends data {1} to {2} ". The format (rank, data, rank % 2))
  • Related