MPI_Gather错误缓冲区溢出 - 改变缓冲区的大小

时间:2013-10-13 15:19:51

标签: c++ c mpi

在测试我的并行程序时,我一直坚持下去。每当我创建'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);
}

0 个答案:

没有答案