代码之家  ›  专栏  ›  技术社区  ›  Maxxx

MPI\U Irecv问题

  •  0
  • Maxxx  · 技术社区  · 6 年前

    我正在编写一个简单的MPI程序,它允许进程向下一个列发送一个随机数,并使用非阻塞通信接收下一个列的随机数。

    Process 0 sends 1 to process 1
    Process 1 received 1 from Process 0
    Process 1 sends 3 to process 0
    Process 0 received 3 from Process 1
    

    我试过:

    #include <stdio.h>
    #include "mpi.h"
    #include <time.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        int rank,size; //rank and size of the process.
        int value; //the random value generated.
    
        int nreq;
        int buf[1]; //receiving buffer
    
        MPI_Init(&argc,&argv); //initialize MPI environment
    
        MPI_Request req[2];
        MPI_Status stat[2];
    
        MPI_Comm_rank(MPI_COMM_WORLD,&rank); //processes rank
        MPI_Comm_size(MPI_COMM_WORLD,&size); //total size of process
    
        if (rank < 2) { //if process rank is less than 2, means we want those to generate random numbers.
            nreq = 0;
            srand(time(NULL)+rank); //seed for the random number generator.
            value = rand() % 10; //generate the random number based of the seed value
            //printf("Process of rank %d generated the value 
              //%d\n",rank,value);
    
          MPI_Isend(&value,1,MPI_INT,rank+1,0,MPI_COMM_WORLD,&req[nreq++]);
          printf("Node %d sent %d to node %d\n",rank,value,rank+1);
    
         MPI_Irecv(&buf[0],1,MPI_INT,rank+1,1,MPI_COMM_WORLD,&req[nreq++]);
         printf("Node %d received %d from node %d\n",rank+1,buf[0],rank);
    
         MPI_Waitall(nreq,req,stat);
     }
    
    MPI_Finalize();
    return 0;
    

    但我得到的错误是

    mpirun detected that one or more processes exited with non-zero status,thus causing the job to be terminated.
    
    0 回复  |  直到 6 年前