我在C中编写了一个MPI程序来测试节点之间的发送/接收消息。
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
int main(int* argc, char*** argv){
MPI_Init(NULL, NULL);
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(size < 2){
fprintf(stderr, "Must have >2 processes.\n");
MPI_Abort(MPI_COMM_WORLD, 1);
}
int number;
if(rank == 0){
number = -1;
MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
else if(rank == 1){
MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Received number %d from process 0.\n", number);
}
MPI_Finalize();
}
当在两台机器上运行时,每台机器都有一个进程,程序提供正确的输出:
Received number -1 from process 0.
但也会抛出错误:
================================================================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= PID 4529 RUNNING AT node0
= EXIT CODE: 2
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
我在错误终端上找到的大多数资源都是处理段错误而不是退出代码2.我尝试在MPI_Finalize之前添加一个MPI_Barrier,这会增加“断言(!关闭)失败”错误。
两个节点都在Raspbian 2015-05-05上使用MPICH 3.1.4。