MPI陷入执行

时间:2018-12-06 00:43:11

标签: c parallel-processing mpi

我正在尝试制作一个MPI程序,该程序仅在两个进程之间交换整数消息,然后卡住,然后返回一条错误消息:

  

由于进程级别为1,节点上的PID为0,mpirun已退出

我在这里做错了什么

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[])
{
   int numtasks, rank, dest, tag, source, rc;
   int inmsg, outmsg = 100;
   MPI_Status stat;

   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);

   printf("Process %d starting...\n",rank);

   if (rank == 0) {
      dest = 1;
      source = dest;
      tag = 0;
      rc = MPI_Send(&outmsg, 1, MPI_INT, dest, tag, MPI_COMM_WORLD);
      printf("Message sento to process  %d...\n", dest);
      rc = MPI_Recv(&inmsg, 1, MPI_INT, source, tag, MPI_COMM_WORLD, 
&stat);
      printf("Received message from  %d...\n", source);
   }
   else if (rank == 1) {
      dest = 0;
      source = dest;
      tag = 0;
      rc = MPI_Recv(&inmsg, 1, MPI_INT, source, tag, MPI_COMM_WORLD, 
&stat);
      printf("Received from process %d...\n", source);
      rc = MPI_Send(&outmsg, 1, MPI_INT, dest, tag, MPI_COMM_WORLD);
      printf("Message sent to process  %d...\n", dest);
   }

}

0 个答案:

没有答案