Search code examples
c++parallel-processingmpidistributed-computing

How do we compute the `MPI_graph_create` index array?


Can anyone use plain simple English to explain how index in function MPI_Graph_create(MPI_Comm comm_old, int nnodes, const int index[], const int edges[], int reorder, MPI_Comm *comm_graph)

I have been analyzing the MPI_Graph_create function as specified in the MPI man pages. I miss the way index[] is computed. The standard specifies that index variable refers to the degree of the nodes which means a count of edges incident from the particular node . For the adjacency matrix below, the standard has index = 2, 3, 4, 6 . I was expecting 2 , 1 ,1 ,2 based on the edges specified n the adjacency matrix.

Process  Neighbors
0         1,3
1         0
2         3
3         0,2

Correct answers from the MPI standard are :-

nnodes = 4
index  = 2,  3,  4,  6 
edges  = 1 ,3, 0, 3,  0 ,2

Solution

  • You understand it correctly, but are writing the indices incorrectly. That is, the "answer" index= 2, 3, 4, 6 is identical to index= 2, 1, 1, 2.

    Simply notice that

    2 = 2
    3 = 2 + 1
    4 = 2 + 1 + 1
    6 = 2 + 1 + 1 + 2
    

    and you can see how your understanding of the problem matches up with the specification's answer. All you have to do is sum up your version in order to give MPI_Graph_create() the indices it wants.