MPI_Test

时间:2016-05-24 10:35:46

标签: mpi openmpi

我在以下代码中收到MPI_Test上的分段错误。该代码涉及发送者进程和接收者进程。发送方进程使用非阻塞发送将整数值发送到接收方进程1000000次。这只是一个测试代码。我在发件人流程中收到了MPI_Test的分段错误,但我无法弄清楚原因。

int main(int argc, char* argv[]){
    MPI_Init(&argc,&argv);
    int rank,nodes;
    int i,j;
    MPI_Status stat;
    int size,wait;
    int msgs = atoi(argv[1]);
    MPI_Comm_size(MPI_COMM_WORLD, &nodes);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    MPI_Request req[msgs][nodes-1],req1;
    if(rank==0){
        size=2;
        for(i=0;i<msgs;i++){
            for(j=1;j<nodes;j++){
                MPI_Isend(&size,1,MPI_INT,
                            j,0,MPI_COMM_WORLD,&(req[i][j-1]));             
            }
        }
        wait = 1;
        i=0,j=0;
        while(wait){
            printf("at i=%d j=%d\n",i,j);
            MPI_Test(&req[i][j], &wait, &stat);
            wait = 1-wait;
            if(!wait){
                j++;
                if(j==nodes-1){
                    j=0;
                    i++;
                    wait=1;
                }
                else{
                    wait=1;
                }
                if(i==msgs){
                    wait=0;
                }
            }
        }
        printf("Finished\n");
    }
    else{
        for(i=0;i<msgs;i++){
            MPI_Irecv (&size,1,MPI_INT,0,0,MPI_COMM_WORLD,&req1);
            wait = 1;
            while(wait){
                MPI_Test(&req1, &wait, &stat);
                wait = 1-wait;
            }
            if(size!=2){
                printf("Received size=%d rank=%d\n",size,rank);
            }
            size=0;
        }
        printf("Finished rank=%d\n",rank);
    }
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Finalize();
}

上述程序的输出是: -

Finished
OK
OK
OK
OK
OK

之后它会给出分段错误

mpirun noticed that process rank 0 with PID 4576 exited on signal 11 (Segmentation fault).

0 个答案:

没有答案