2

MPIを使用してCannonsアルゴリズムを実装しようとしていますが、次のサンプルコードを使用しています。

http://siber.cankaya.edu.tr/ozdogan/GraduateParallelComputing.old/ceng505/node133.html

わからない部分があります。これがサンプルコードです。

37    /* Perform the initial matrix alignment. First for A and then for B */ 
38    MPI_Cart_shift(comm_2d, 0, -mycoords[0], &shiftsource, &shiftdest); 
39    MPI_Sendrecv_replace(a, nlocal*nlocal, MPI_DOUBLE, shiftdest, 
40        1, shiftsource, 1, comm_2d, &status); 
41 
42    MPI_Cart_shift(comm_2d, 1, -mycoords[1], &shiftsource, &shiftdest); 
43    MPI_Sendrecv_replace(b, nlocal*nlocal, MPI_DOUBLE, 
44        shiftdest, 1, shiftsource, 1, comm_2d, &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);
MPI_Cart_shift(comm, 1, -1, &downrank, &uprank); 

MPI_Cart_shift(comm, 0, -coordinates[0], &shiftsource, &shiftdest); 
printf("coordinates[0] = %d for a shiftsource = %d, shiftdest = %d\n", coordinates[0], shiftsource, shiftdest);
//MPI_Sendrecv_replace(a, a->rowNum * a->colNum, MPI_INT, shiftdest, 
    //1, shiftsource, 1, comm, &status); 

MPI_Cart_shift(comm, 1, -coordinates[1], &shiftsource, &shiftdest); 
printf("coordinates[1] = %d for b shiftsource = %d, shiftdest = %d\n", coordinates[1], shiftsource, shiftdest);
//MPI_Sendrecv_replace(b, b->rowNum * b->colNum, MPI_INT, 
  //  shiftdest, 1, shiftsource, 1, comm, &status); 

別の関数でMPI_Cart_createを呼び出しますが、これはサンプルコードと同じ基本的な呼び出しです。

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;
}
MPI_Cart_create(MPI_COMM_WORLD, 2, dim_size, periods, 1, &CannonsCart);

今、私はshiftsourceとshiftdestのポイントが何であるかを理解しようとしています。私はそれが最初のシフトのためであると思います、しかし私がこのコードを実行するとき、私のprintfステートメントはこれを言います。

coordinates[0] = 0 for a shiftsource = 0, shiftdest = 0
coordinates[1] = 0 for b shiftsource = 0, shiftdest = 0

coordinates[0] = 1 for a shiftsource = 1, shiftdest = 1
coordinates[1] = 1 for b shiftsource = 2, shiftdest = 2

coordinates[0] = 1 for a shiftsource = 0, shiftdest = 0
coordinates[1] = 0 for b shiftsource = 2, shiftdest = 2

coordinates[0] = 0 for a shiftsource = 1, shiftdest = 1
coordinates[1] = 1 for b shiftsource = 0, shiftdest = 0

なぜshiftsourceとshiftdestが同じなのかわかりません。行列aとbの場合は、左に1つ、上に1つある必要があります。

このテストケースでは、この呼び出しのプロセス数(IEサイズ)は4です。必要に応じて、すべてのコードをホストします。

4

1 に答える 1

2

の3番目の引数MPI_Cart_shiftは、2番目の引数で指定された寸法(方向)に沿った変位です。指定された次元に沿って座標を持つすべてのプロセス0の場合、変位も0(として指定されているため-coordinate[i])、ソースと宛先のランクは呼び出し元のプロセスのランクと一致します。

トポロジが2x2であり、両方の次元に周期境界条件があるため、変位も同じshiftsourceになります。前のランクの選択された次元に沿った座標は次のようになります(ここではモジュロを計算します)。しかし、これは、まさに次のランクの座標であるに等しくなります。したがって、前のプロセスと次のプロセスの座標が一致するため、ランクは同じになります。shiftdest1(coordinates[i] - 1 + 2) % 2(a - m + k) % ka - mk(coordinate[i] + 1) % 2

于 2013-02-22T12:11:12.737 に答える