如何解决在通信器MPI_COMM_WORLD上进程[135921655,0]报告的MPI_Send中发生的错误

时间:2019-10-09 04:47:58

标签: linux ubuntu mpi

我开始学习MPI,我正在按照教程学习,并用C语言编写了两个文件。第一个文件的编译和运行很好,但是在第二个文件上执行相同的操作时,它将无法正常工作。在遇到错误之后,即使重新编译它们,现在也无法运行两个文件。

我在网络上的任何地方(包括stackoverflow上)都找不到解决我问题的方法。这篇文章是我遇到的最接近的帖子,但没有提供任何解决方案。 Error occurred in MPI_Send on communicator MPI_COMM_WORLD MPI_ERR_RANK:invalid rank

第一个文件:

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

Int main (int argc, char *argv){
//Initialize the MPI environment        
MPI_Init(NULL, NULL);

//find out rank, size
int world_rank;
MPI_Comm_rank (MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size (MPI_COMM_WORLD, &world_size);

int number;
if (world_rank == 0){
    number = -1;
    MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}

else if (world_rank == 1){
    MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    printf("Process 1 received number %d from process 0\n", number);
}

//Finalise the MPI environment
MPI_Finalize();
}

第二个文件:

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

int main (int argc, char **argv){
//Initialize the MPI environment        
MPI_Init(NULL, NULL);

//find out rank, size
int world_rank;
MPI_Comm_rank (MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size (MPI_COMM_WORLD, &world_size);

int X, Y, Z;
if (world_rank == 0){
    scanf("%d", &X);
    scanf("%d", &Y);

    MPI_Send(&X, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
    MPI_Send(&Y, 1, MPI_INT, 1, 1, MPI_COMM_WORLD);

    MPI_Recv(&Z, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    printf("Process 1 received number %d from process 2\n", Z);
}

else if (world_rank == 1){
    MPI_Recv(&X, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    MPI_Recv(&Y, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    Z = X + Y;
    MPI_Send(&Z, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
}

//Finalise the MPI environment
MPI_Finalize();
}

错误消息: [ubuntu:2638] *** MPI_Send中发生错误

[ubuntu:2638] ***由进程[135921665,0]报告

[ubuntu:2638] ***在通讯器MPI_COMM_WORLD上

[ubuntu:2638] *** MPI_ERR_RANK:无效排名

[ubuntu:2638] *** MPI_ERRORS_ARE_FATAL(此通信器中的进程现在将中止,

[ubuntu:2638] ***,可能还有您的MPI工作)

更新:

这是我使用的命令行

mpicc -o 123 file1.c

mpirun 123

这是第一次可以,但在此之后

mpicc -o 123 file2.c

mpirun 123 这是我第一次遇到错误的地方

0 个答案:

没有答案