1

ネストされたループがあり、ループ内からMPI送信を呼び出します。これにより、受信者に特定の値を送信し、受信者でデータを取得してMPIメッセージを別のCPUセットに送信します...何かを使用しましたこのように見えますが、受信に問題があるようです...どこで間違ったのかわかりません...「マシンはどこかで無限ループに陥ります...

私はそれを次のように動作させようとしています: マスター CPU >> 他の CPU に送信 >> スレーブ CPU に送信

 . 
 . 
 . 

 int currentCombinationsCount; 
 int mp; 

 if (rank == 0)
 {


     for (int pr = 0; pr < combinationsSegmentSize; pr++)
     {
         int CblockBegin = CombinationsSegementsBegin[pr];
         int CblockEnd   = CombinationsSegementsEnd  [pr];
         currentCombinationsCount = numOfCombinationsEachLoop[pr]; 
         prossessNum = 1; //specify which processor we are sending to 

         // now substitute and send to the main Processors 
         for (mp = CblockBegin; mp <= CblockEnd; mp++)
         {

             MPI_Send(&mp , 1, MPI_INT   , prossessNum, TAG, MPI_COMM_WORLD);

             prossessNum ++; 
         }

     }//this loop goes through all the specified blocks for the combinations  
 } // end of rank 0
 else if (rank > currentCombinationsCount)
 {
       // here I want to put other receives that will take values from the else below 
 }
 else 
 {
     MPI_Recv(&mp , 1, MPI_INT   , 0, TAG, MPI_COMM_WORLD, &stat);
     // the code stuck here in infinite loop 
 }
4

1 に答える 1

0

currentCombinationsCountブランチ内で初期化しただけif(rank==0)なので、他のすべての proc には初期化されていない変数が表示されます。その結果、未定義の動作が発生し、結果はコンパイラによって異なります。プログラムがクラッシュするか、値が 0 または未確定の値に設定される可能性があります。

運が良ければ、値が 0に設定される場合があります。その場合、ブランチは次のように縮小されます。

if (rank == 0) {  /* rank == 0 will enter this } 
else if (rank > 0) { /* all other procs enter this }
else { /* never entered! Recvs are never called to match the sends */ }

したがって、どの受信とも一致しない送信が発生します。MPI_Sendは をブロックしている可能性があるため、送信側の proc が無期限に停止する可能性があります。procsが送信をブロックしていると、確かに「...マシンはどこかで無限ループに入る...」と考えているように見えます。

currentCombinationsCountに (0 ではなく) 任意の値を指定すると、procsrank!=0は任意のブランチに入ります (すべてが final に入る可能性が高くなりますelse)。その後、受信の 2 番目のセットが呼び出されず、上記と同じ問題が発生します。

于 2013-01-24T10:05:15.453 に答える