在测试我的并行程序期间,我曾一度陷入困境。每当我创建“pS”数组时,我的程序都会在 MPI_Gather() 函数上崩溃,并出现错误“MPIDI_CH3_Receive_data_found(129) ... 4998 字节已接收但缓冲区大小为 4996”。这些值是示例性的,但第一个数字总是高于第二个。我想 MPI_Bcast 会导致这个错误,但我不知道如何解决它。此外,当“pS”数组在每个进程上具有相同大小时,程序完全可以正常工作。
编辑。
删除 MPI_Bcast 后问题仍然存在。
编辑。
当我定义的常量 recvcount 大于最大的 sendcnt 大小时,它可以正常工作,但我不知道为什么我的主要概念不起作用。
int main(int argc, char *argv[]){
MPI_Init (&argc, &argv);
//Start the timer
MPI_Barrier(MPI_COMM_WORLD);
int myRank = 0;
int numProcs = 1;
MPI_Comm_rank (MPI_COMM_WORLD, &myRank);
MPI_Comm_size (MPI_COMM_WORLD, &numProcs);
int size_s = atoi(argv[1]);
bool *S;
if(myRank == 0){
S = new bool[size_s+1];
}
unsigned long lowValue = BlockLow (myRank, numProcs, maxNumber);
unsigned long highValue = BlockHigh (myRank, numProcs, maxNumber);
...
unsigned long size = (highValue - lowValue)/2 + 1;
...
bool *pS = new bool[size];
...
while(...){
...
MPI_Bcast(&var, 1, MPI_INT, 0, MPI_COMM_WORLD);
}
//here I've been getting pS array with diffrent size because I create in processes 'pS' arrays with diffrent sizes
MPI_Gather(pS, size, MPI_C_BOOL, S, size, MPI_C_BOOL, 0, MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
unsigned long BlockLow(unsigned int procId, unsigned int numProcs, unsigned long maxNumber){
unsigned long low = ((maxNumber-1) / numProcs)*procId + 3;
if((low & 1) == 0) low--;
return low;
}
unsigned long BlockHigh(unsigned int procId, unsigned int numProcs, unsigned long maxNumber){
return((BlockLow(procId+1,numProcs,maxNumber)) - 2);
}