
I need to create a communicator with a cube topology, and then select a cube face using MPI_Cart_Shift, implemented messaging between processes on the edge. For example, I am a process with a rank of 0 (R0), my neighborhood is R2, R4, R6 (the bottom face of the cube). I can find R2 and R4, but I can not figure out how to find R6. My code is:
#include<mpi.h> #include<stdio.h> int main(int argc, char *argv[]) { int rank, k; int size; int ndims = 3; int source, dest; int up,down,right,left,up3, down3; int edges[6][4] = {{0,1,5,4}, {4,5,7,6}, {2,3,1,0}, {6,7,3,2}, {1,3,7,5}, {0,2,6,7}}; int t, incep=0; char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Comm comm, comm3d; int dims[3]={0,0,0}, coords[3]={0,0,0}, periods[3]={1,1,1}, reorder = 0; MPI_Status status; int user_edge; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Dims_create(size, ndims, dims); MPI_Cart_create(MPI_COMM_WORLD, ndims, dims, periods, reorder, &comm); MPI_Cart_coords(comm, rank, 3, coords); fflush(stdout); printf("Rank %d coordinates are %d %d %d\n", rank, coords[0], coords[1], coords[2]); MPI_Barrier(comm); int leftrank, rightrank; int downrank, uprank; MPI_Comm_rank(comm, &rank); MPI_Cart_coords(comm, rank, 2, coords); MPI_Cart_shift(comm, 0, -1, &downrank, &uprank); MPI_Sendrecv(buffer, 10, MPI_INT, downrank, 123, buffer2, 10, MPI_INT, uprank, 123, comm, &status); MPI_Cart_shift(comm, 1, -1, &rightrank, &leftrank); MPI_Sendrecv(buffer, 10, MPI_INT, leftrank, 123, buffer2, 10, MPI_INT, rightrank, 123, comm, &status); printf("P:%d My neighbors are rightRank: %d downRank:%d leftRank:%d upRank:%d diagonal:%d diagonalX:%d\n", rank,rightrank,downrank,leftrank,uprank,diagonal,diagonalX); MPI_Finalize(); return 0; }
I will try to add something like this MPI_Cart_shift (comm, 2, 1, & diagonal and diagonal X); But for R0, he shows me R1, and I understand ... How can I get angular neighborhoods?