Проблема с MPI_Irecv - PullRequest
       36

Проблема с MPI_Irecv

0 голосов
/ 05 октября 2018

Я пишу простую программу 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.
...