0

I`m pretty new in MPI programming and got stuck in the middle of my project.

I want to write an MPI code for the following problem. I am not sure which functions from MPI is appropriate. Here is the problem:

Processor 0 has a 2D vector or array of Edges={(0,4),(1,5)}. It needs to get some information from the other processors, which is not always a fixed processor, it depends on set Edges. Therefore, I need a for loop as follows:

if(my_rank==0)
{
    for(all pairs (i,j) in Edges)
    {
        send i (or j) to Processor r (r depends on the index i)
        recieve L_r from Processor r
        create (L_i, L_j, min(L_i,L_j)) // want to broadcast to all later.
    }
}

Now, I am not sure how to do it for processor r, should I do in a for loop? Note that I can not do it in an if statement since I dont know which processor would be and so based on the number of processors I need an if statement which I don`t think is a right way. I might have so many processors which each holds some part of a matrix.

Need to point that I cannot communicate with a subgroup of communicators, since it all depends on the indices, basically, I want the labels for example indices (0,4) which need to communicate with P4 that holds it.

Any ideas are appreciated.

Sarah
  • 133
  • 11
  • Custom communicator, perhaps? If you don't communicate with MPI_COMM_WORLD, you have to look at subgroups. http://mpitutorial.com/tutorials/introduction-to-groups-and-communicators/ – Severin Pappadeux Apr 01 '18 at 17:13
  • @SeverinPappadeux No, I cannot, it all depends on the indices, basically, I want the labels for example indices (0,4) which need to communicate with P4 that holds it. – Sarah Apr 01 '18 at 17:16
  • I would guess if you don't know which node will have the data, you'll have to design run-time discovery around short (specific integer) messages and non-blocking I/O (MPI_Isend() and MPI_Irecv() plus MPI_Wait). Perhaps https://stackoverflow.com/questions/10017301/mpi-blocking-vs-non-blocking ? – Severin Pappadeux Apr 01 '18 at 18:07
  • Could you at start-up link job specific (i,j) to the node rank ? – Severin Pappadeux Apr 01 '18 at 18:10
  • 1
    Looks to me as if you should be looking into MPI's *distributed graph topology*. – High Performance Mark Apr 01 '18 at 18:42
  • @SeverinPappadeux I know which processor contains the data, the problem is a graph, initially, I distributed row-wise, so once based on some conditions in root I need some information for (i,j), I know I need to go to processor j. But the problem is that the Edge set might contain one pair or more, If it was one, I knew how to handle it, but I don`t know how to do back and forth, I don`t know how to do it. – Sarah Apr 01 '18 at 23:33
  • @SeverinPappadeux To answer your second comment, each pair (i,j) is a weight of an edge. So at start-up I know pair (i,j) belongs to the processors i and j (since the graph is undirected, (i,j)=(j,i)). – Sarah Apr 02 '18 at 00:12

1 Answers1

0

I would do it as follow:

1) Proc 0 construct a list of every processes it has to comunicate with.

2) Proc 0 broadcast this list to all processes (or only to the one he have to communicate with, but that will be more complicated, can be done once you got a version which works)

3) You perform your comm:

If(rank==0){...}

else if (rank in the list){...}

David Daverio
  • 323
  • 1
  • 11