我一直在MPI項目中的奴隸都發送數據回到主。由於某種原因,如果我連續發送2個連續發送,主人將只收到數據。這很奇怪,我認爲這導致了一些其他奇怪的問題。任何想法會導致這種情況?我認爲第一次發送是發送某種垃圾數據或其他東西。儘管發送的是完全相同的代碼行。必須發送MPI消息兩次,由於某種原因
EDIT:代碼下面...
if (numProcs > 0)
MPI_Barrier(MPI_COMM_WORLD) ; //only wait if there are other processes to wait for
if (rank != 0)
{
MPI_Send(handArray, 10, MPI_DOUBLE, 0, TAG_HAND, MPI_COMM_WORLD);
MPI_Send(handArray, 10, MPI_DOUBLE, 0, TAG_HAND, MPI_COMM_WORLD);
}
//8. After the main loop the master process receives and sums together the hand counts array
// from each slave process.
else
{
int activeProcs = numProcs - 1;
getHandsFromSlaves(activeProcs, handArray);
則主進到打印某些數據...
這裏是getHands FromSlaves方法。請注意我也嘗試過使用阻塞調用以及相同的問題。
void getHandsFromSlaves(int& activeCount, double handTotals[10]){
static MPI_Request request;
static int msgBuff, recvFlag;
static double handBuff[10];
MPI_Status status;
while (activeCount > 0)
{
if(request)
{
// Already listening for a message
// Test to see if message has been received
MPI_Test(&request, &recvFlag, &status);
//cout << "TAG: " << status.MPI_TAG << " SOURCE: "<< status.MPI_SOURCE << " ERROR: " << status.MPI_ERROR << endl;
if(recvFlag)
{
// Message received
if(status.MPI_TAG == TAG_HAND)
{
cout << "Hand Received!" << endl;
for(int m = 0; m < 10; ++m)
{
handTotals[m] += handBuff[m];
}
activeCount--;
}
else
{
//error report... what happened?
cout << "TAG: " << status.MPI_TAG << " SOURCE: "<< status.MPI_SOURCE << " ERROR: " << status.MPI_ERROR << endl;
}
// Reset the request handle
request = 0;
}
}
if(!request && activeCount > 0)
// Start listening again
MPI_Irecv(&handBuff, 10, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &request);
}
}
可以顯示一些代碼? – tune2fs
添加代碼。需要幫助請叫我。 – xxf8xx
任何人都可以幫助嗎?任何幫助是極大的讚賞! – xxf8xx