글쎄, 그것은
그래서 4 차원 하이퍼 큐브를위한 것입니다 발견 .. 패턴이 꽤 솔직하다. n 차원 하이퍼 큐브에서 각 점은 N 개의 이웃을 가지며이 코드에서 표현됩니다. MPI는 클러스터의 실제 레이아웃에 맞게 프로세스를 재정렬 할 수 있기 때문에이 코드는 비트 마스크를 xoring하는 대신 사용해야합니다.
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";
mmm 좋은 작품, 나는 큐브와 작업이 있고 꼭지점 간의 프로세스 통신을해야합니다. MPI_Sendrecv()를 사용하려고했으나 작동하지 않습니다. 작업에 통신이 있습니까? – Sergey
MPI_Cart_shift (nthCube, nDim-1-s, 1, & rank_source, & rank_dest); – matdumsa
(nDim-1-s) - 무엇을 의미합니까? 잠겨 있기 때문에 MPI_Sendrecv()를 사용하는 것이 맞습니다. – Sergey