嗯,找到了
所以这将是一个 4-d 超立方体.. 模式非常简单。在 n 维超立方体中,每个点都有 N 个邻居,它们在此代码中表示。请注意,应该使用此代码而不是 xoring 位掩码,因为 MPI 可以重新排序进程以适应集群的物理布局。
int rank, size; //I am process RANK and we are a total of SIZE
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
myFairShareOfNumber = totalNumber / size;
MPI_Comm nthCube;
int nDim=4;
int processPerDim [4]= {2,2,2,2};
int period [4]= {1,1,1,1};
MPI_Cart_create(MPI_COMM_WORLD, nDim, processPerDim, period, true, &nthCube);
int rankInDim;
MPI_Comm_rank(nthCube, &rankInDim);
int rank_source, rank_desta, rank_destb, rank_destc, rank_destd;
MPI_Cart_shift(nthCube, 0,1,&rank_source, &rank_desta);
MPI_Cart_shift(nthCube, 1,1,&rank_source, &rank_destb);
MPI_Cart_shift(nthCube, 2,1,&rank_source, &rank_destc);
MPI_Cart_shift(nthCube, 3,1,&rank_source, &rank_destd);
cerr << "I am known in the world as " << rankInDim << " my adjacents are -> " << rank_desta << "-" << rank_destb << "-" << rank_destc << "-" << rank_destd <<"\n";