I have 3 questions related to MPI (in C). I think the first 2 have the same answer, but I'm not sure.
Question 1
When using MPI_Dims_create to create a 2D mesh, is the dimension of the returned dimensions equal to X and which is equal to Y?
For example:
int numProcs = -1, myProcID = -1; MPI_Comm_rank(MPI_COMM_WORLD, &myProcID); MPI_Comm_size(MPI_COMM_WORLD, &numProcs); int size[2]; size[0] = size[1] = 0; MPI_Dims_create(numProcs, 2, size); int numProcs_y = -1, numProcs_x = 1;
Should it be:
numProcs_y = size[0]; numProcs_x = size[1];
Or that:
numProcs_x = size[0]; numProcs_y = size[1];
I tried to run this with a number of processes that seemed to give me an answer (e.g. 6). Using 6 processes, MPI_Dims_create should either create a grid with three rows and two columns, or two rows and three columns (if I misunderstood the documentation). For process 3 (out of 6), I found that size[0] = 1 and size[1] = 0 (I believe this corresponds to x = 0, y = 1). This apparently tells me that MPI_Dims_create creates a grid with 3 rows and 2 columns (because it was 2 rows and 3 columns, process 2 (out of 6) should have x = 2, y = 0). Any confirmation that anyone can provide on this subject would be greatly appreciated.
Question 2
When using MPI_Cart_coords on a two-dimensional Cartesian grid, from the returned dimensions X and which is Y?
For example:
int periodic[2]; periodic[0] = periodic[1] = 0; // no wrap around MPI_Comm cart_comm; int coords[2]; // using size from question 1 MPI_Cart_create(MPI_COMM_WORLD, 2, size, periodic, 1, &cart_comm); MPI_Cart_coords(cart_comm, myProcID, 2, coords);
As in question 1, my question is should it be like this
myProcID_y = coords[0]; myProcID_x = coords[1];
or how is it
myProcID_x = coords[0]; myProcID_y = coords[1];
I looked through the documentation and previous questions here, but I can not find a direct answer to this question.
The documentation seems to indicate that the first of the two approaches is correct, but it does not conclusively indicate it.
Question 3
The main question underlying the first two questions is that I am trying to split a 2D grid into rows and columns. However, when I use MPI_Comm_rank to check the row and column identifiers of each process after that, I get the ordered processes in an order that does not match what, in my opinion, answers the above questions.
Based on the above, I expect the processes to be ordered as follows:
P0 P1 P2 P3 P4 P5
However, using this code (which appears after the above code in my program, so all of the above codes are available from it: I'm trying to allocate my code to simplify the selection of my questions):
MPI_Comm row_comm, col_comm; int row_id = -1, col_id = -1; // ** NOTE: My use of myProcID_y and myProcID_x here are based // on my understanding of the previous 2 questions ... if my // understanding to one/both of those is wrong, then obviously the assignments // here are wrong too. // create row and column communicators based on my location in grid MPI_Comm_split(cart_comm, myProcID_y, myProcID_x, &row_comm); MPI_Comm_split(cart_comm, myProcID_x, myProcID_y, &col_comm); // get row and column ID for each process MPI_Comm_rank(row_comm, &row_id); MPI_Comm_rank(col_comm, &col_id); printf("Process: %d\trowID: %d\tcolID: %d\n", myProcID, row_id, col_id);
I see the following printed:
Process: 0 rowID: 0 colID: 0 Process: 1 rowID: 1 colID: 0 Process: 2 rowID: 0 colID: 1 Process: 3 rowID: 1 colID: 1 Process: 4 rowID: 0 colID: 2 Process: 5 rowID: 1 colID: 2
which, apparently, corresponds to the following order of processes:
P0 P2 P4 P1 P3 P5
which represents the opposite dimensions of the matrix (2 rows, 3 columns) from what I expected from MPI_Dims_create .
Assuming that my understanding of the first two questions is correct (i.e., that Y is the first dimension returned by these functions), why are the processes (apparently) ordered in a different order at this stage?