2016-04-24 7 views
2

ちょっと、MPI_IScatterv()関数の変位配列の設定に問題があります。MPI_IScatterv()での変位配列の設定

画像の一部を別のプロセスに分散する必要があります。私は、変位の配列を渡す必要がある関数の引数として構造ピクセルの

private: MPI_Datatype createMPI_PixelType(){ 
MPI_Datatype new_type; 

int count = 3; 
int blocklens[] = { 1,1,1 }; 

MPI_Aint indices[3]; 
indices[0] = (MPI_Aint)offsetof(struct Pixel, Red); 
indices[1] = (MPI_Aint)offsetof(struct Pixel, Green); 
indices[2] = (MPI_Aint)offsetof(struct Pixel, Blue); 

MPI_Datatype old_types[] = { MPI_INT, MPI_INT, MPI_INT }; 

MPI_Type_create_struct(count, blocklens, indices, old_types, &new_type); 
MPI_Type_commit(&new_type); 

return new_type;} 

struct Pixel { 
int Red; 
int Green; 
int Blue; } 

:私は私自身のMPI_Datatypeをしました。 それは、各プロセスがdisp [proc_id]として指定された別の場所からsendBufferの読み取りを開始するということです。例えば、プロセス0 DISP = 0、 工程1 DISP =はsizeof 0素子、 工程2 DISP =はsizeof 1 + 0素子等 ここコード

... 
    //specify arrays for scathering 
    sendCountArray = calcSendCounts(workTable); 
    displacementArray = calcDisplacementArray(workTable); 

    Pixel *fullPicture = pictureToPixelsArray(); 
    cout << endl; 
    for (int i = 0; i < pixelsOnPicture; i++) { 
     cout << 
      " r:" << fullPicture[i].Red << 
      " g:" << fullPicture[i].Green << 
      " b:" << fullPicture[i].Blue << endl; 
    } 

    cout << endl << "sendArray:" << endl; 
    for (int i = 0; i < worldSize; i++) { 
     cout << "i:" << i << " " << sendCountArray[i] << endl; 
    } 
    cout << endl << "displacementArray:" << endl; 
    for (int i = 0; i < worldSize; i++) { 
     cout << "i:" << i << " " << displacementArray[i] << endl; 
    } 
} 
cout << endl; 
// 
MPI_Scatter(sendCountArray, 1, MPI_INT, &pixelsSizeBuffer, 1, MPI_INT, 0, MPI_COMM_WORLD); 

//sending part of picture 
MPI_Request request; 
MPI_Datatype mMPI_PIXEL = createMPI_PixelType(); 
partPicture = new Pixel[pixelsSizeBuffer]; 
MPI_Iscatterv(pictureToPixelsArray(), sendCountArray, displacementArray, mMPI_PIXEL, partPicture, pixelsSizeBuffer, mMPI_PIXEL, 0, MPI_COMM_WORLD, &request); 
for (int i = 0; i < pixelsSizeBuffer; i++) { 
    cout << "proc:" << procID << 
     " r:" << partPicture[i].Red << 
     " g:" << partPicture[i].Green << 
     " b:" << partPicture[i].Blue << endl; 
} 

ここ

(6つのプロセス)出力をテストしてありますIscattervは、あなたが出力をチェックする時点で完了しているという保証はありませんので、最初の2つの要素が正しく送信され
pixelsOnPicture:9 
workTableSize: 6 

r:255 g:242 b:0 
r:63 g:72 b:204 
r:237 g:28 b:36 
r:0 g:162 b:232 
r:163 g:73 b:164 
r:63 g:11 b:15 
r:34 g:177 b:76 
r:255 g:242 b:0 
r:63 g:10 b:16 

sendArray: 
i:0 2 
i:1 2 
i:2 2 
i:3 1 
i:4 1 
i:5 1 

displacementArray: 
i:0 0 
i:1 2 
i:2 4 
i:3 6 
i:4 7 
i:5 8 

proc:4 r:-842150451 g:-842150451 b:-842150451 
proc:0 r:255 g:242 b:0 
proc:2 r:-842150451 g:-842150451 b:-842150451 
proc:5 r:-842150451 g:-842150451 b:-842150451 
proc:0 r:63 g:72 b:204 
proc:2 r:-842150451 g:-842150451 b:-842150451 
proc:1 r:-842150451 g:-842150451 b:-842150451 
proc:3 r:-842150451 g:-842150451 b:-842150451 
proc:1 r:-842150451 g:-842150451 b:-842150451 

..

答えて

2

あなたはまだ要求に待っていません。普通の古いScattervを呼び出すと、呼び出し後に完全なものになるので、すべてのパラメータとデータ型が正しく設定されているかどうかを確認できます。または、Iscattervの呼び出しの後にMPI_Wait(&要求)を追加します。ただし、ここで行ったことはすべて、ブロッキング呼び出しを再実装することだけであることに注意してください。

関連する問題