I have a Cartesian process topology in 3D. However, I describe my problem in 2D to simplify it.
For the collective nearest neighbor communication (left image) I use MPI_Neighbor_alltoallw() which allows send and receive of different datatypes. However this function does not work for diagonal neighbors (right image) and I need another function for diagonal neighbors.
Left: nearest neighbors are green neighbors. Right: red grids are nearest diagonal neighbor.
What I have in my mind to implement diagonal neighbor communication is:
int main_rank; // rank of the gray process
int main_coords[2]; // coordinates of the gray process
MPI_Comm_rank (comm_cart, &main_rank);
MPI_Cart_coords (comm_cart, main_rank, 2, main_coords);
// finding the rank of the top-right neighbor
int top_right_rank;
int top_right_coords[2] = {main_coords[0]+1, main_coords[1]+1};
MPI_Cart_rank (comm_cart, top_right_coords, &top_right_rank);
// SEND DATA: MPI_Isend(...);
// RECEIVE DATA: MPI_Irecv(...);
// MPI_Waitall(...);
// REPEAT FOR OTHER DIAGONAL NEIGHBORS
Question
- Is there any collective diagonal neighborhood communication in MPI standard?
- What is the efficient and less error-prone implementation?
- Do you have any suggestion to make my implementation better?