我需要使用多维数据集拓扑创建一个通信器,然后选择多维数据集的面,使用MPI_Cart_Shift在边缘处理的进程之间实现消息传递.例如,我处理等级0(R0)我的邻居是R2,R4,R6(立方体的下面).我可以找到R2和R4,但我无法理解如何找到R6.我的代码:
#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, …Run Code Online (Sandbox Code Playgroud)