少し前にこのプロジェクトについて質問しましたが、新しい問題が発生しました。MPI_cart_shiftを実行して、プロセスの現在のランクに最も近いネイバーを見つけようとすると、正しいターゲットランクが返されません。
このサンプルコードに従おうとしています。 http://siber.cankaya.edu.tr/ozdogan/GraduateParallelComputing.old/ceng505/node133.html
これが座標系を作成するための私のコードです
MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
.
.
.
if(is_perfect_square(size)) dim_size[0] = dim_size[1] = (int) sqrt(size);
else
{ //if size = 2 then dims = 2, 1; size = 4 then 2,2; 8 = 4, 2...
dim_size[0] = (int) sqrt(size + size);
dim_size[1] = dim_size[0] / 2;
}
fprintf(stderr, "%d | %d \n", dim_size[0], dim_size[1]);
MPI_Cart_create(MPI_COMM_WORLD, 2, dim_size, periods, 1, &CannonsCart);
MPI_Barrier(MPI_COMM_WORLD);
.
.
.
runCannon(CannonsCart, &a, &b, &c);
これがrunCannonです。
int runCannon( MPI_Comm comm, Matrix *a, Matrix *b, Matrix *c)
{
int size, rank, coordinates[2];
int uprank, downrank, leftrank, rightrank;
int shiftsource, shiftdest;
int ix, swap;
MPI_Status status;
MPI_Comm_size(comm, &size);
MPI_Comm_rank(comm, &rank);
MPI_Cart_coords(comm, rank, 2, coordinates);
MPI_Cart_shift(comm, 0, -1, &rightrank, &leftrank); //Cart_shift is doing weird stuff that I don't understand.
MPI_Cart_shift(comm, 1, -1, &downrank, &uprank);
printf("rank = %d, rightrank = %d, downrank = %d, leftrank = %d, uprank = %d\n", rank, rightrank, downrank, leftrank, uprank);
それぞれ4、8、16プロセスでプログラムを実行すると、これらの出力が得られます。
rank = 0, rightrank = 2, downrank = 1, leftrank = 2, uprank = 1
rank = 1, rightrank = 3, downrank = 0, leftrank = 3, uprank = 0
rank = 3, rightrank = 1, downrank = 2, leftrank = 1, uprank = 2
rank = 2, rightrank = 0, downrank = 3, leftrank = 0, uprank = 3
0はrightrank=1、downrank = 2、leftrank = 1、uprank = 2などである必要があります。ただし、8つのプロセスがある場合、これが私の出力であるため、MPI_shift呼び出しを単に交換することはできません。
rank = 0, rightrank = 2, downrank = 1, leftrank = 6, uprank = 1
rank = 1, rightrank = 3, downrank = 0, leftrank = 7, uprank = 0
rank = 2, rightrank = 4, downrank = 3, leftrank = 0, uprank = 3
rank = 3, rightrank = 5, downrank = 2, leftrank = 1, uprank = 2
rank = 4, rightrank = 6, downrank = 5, leftrank = 2, uprank = 5
rank = 5, rightrank = 7, downrank = 4, leftrank = 3, uprank = 4
rank = 6, rightrank = 0, downrank = 7, leftrank = 4, uprank = 7
rank = 7, rightrank = 1, downrank = 6, leftrank = 5, uprank = 6
0はrightrank=1、downrank = 4、leftrank = 3、uprank=4である必要があります
データのためだけに16個あります。
rank = 9, rightrank = 13, downrank = 10, leftrank = 5, uprank = 8
rank = 3, rightrank = 7, downrank = 0, leftrank = 15, uprank = 2
rank = 0, rightrank = 4, downrank = 1, leftrank = 12, uprank = 3
rank = 2, rightrank = 6, downrank = 3, leftrank = 14, uprank = 1
rank = 1, rightrank = 5, downrank = 2, leftrank = 13, uprank = 0
rank = 8, rightrank = 12, downrank = 9, leftrank = 4, uprank = 11
rank = 6, rightrank = 10, downrank = 7, leftrank = 2, uprank = 5
rank = 7, rightrank = 11, downrank = 4, leftrank = 3, uprank = 6
rank = 4, rightrank = 8, downrank = 5, leftrank = 0, uprank = 7
rank = 5, rightrank = 9, downrank = 6, leftrank = 1, uprank = 4
rank = 12, rightrank = 0, downrank = 13, leftrank = 8, uprank = 15
rank = 14, rightrank = 2, downrank = 15, leftrank = 10, uprank = 13
rank = 13, rightrank = 1, downrank = 14, leftrank = 9, uprank = 12
rank = 10, rightrank = 14, downrank = 11, leftrank = 6, uprank = 9
rank = 11, rightrank = 15, downrank = 8, leftrank = 7, uprank = 10
rank = 15, rightrank = 3, downrank = 12, leftrank = 11, uprank = 14