【发布时间】:2017-01-20 09:56:30
【问题描述】:
我有一个简单的 MPI 代码,它运行成功,但在终止之前显示以下错误。
===
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= EXIT CODE: 139
= CLEANING UP REMAINING PROCESSES
= YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
===================================================================================
YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
This typically refers to a problem with your application.
下面是我的源代码。
/*
AUTHOR ::: KHAYAM ANJAM
*/
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int main (int argc, char *argv[])
{
int rank, size, ball_value, ball_present;
MPI_Init (&argc, &argv);
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
MPI_Comm_size (MPI_COMM_WORLD, &size);
srandom(rank);
int delta = rand() % 13;
int random = rand() % 5;
if (random == 0) delta = -1*delta;
if (rank == 0) {
ball_present = 1;
ball_value = 0;
}
else ball_present = 0;
while (1) {
if(ball_present == 0)
MPI_Recv(&ball_value, 30, MPI_INT, MPI_ANY_SOURCE, 10, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
ball_present = 1;
printf("Task %d has Ball with value %d\n", rank, ball_value);
if (ball_value == 1000) break;
if (abs(ball_value) > 100) {
int send_1000 = 1000;
int i;
for (i = 0; i < size; i++)
if (i != rank) MPI_Send(&send_1000, 30, MPI_INT, i, 10, MPI_COMM_WORLD); //Broadcast to all others
break;
}
ball_value += delta;
int next_to_send = rand() % size;
if (next_to_send != rank) {
printf("Sending ball to %d\n", next_to_send);
MPI_Send(&ball_value, 30, MPI_INT, next_to_send, 10, MPI_COMM_WORLD);
ball_present = 0;
}
}
MPI_Finalize();
return 0;
}
【问题讨论】:
-
我不是 MPI 用户,但我注意到您没有检查 any 的
MPI_xxx()函数的返回值,这是为了您的利益而提供的。奇怪的是,在我用谷歌搜索的几个网页中,只有MS page 特别提到了返回值。其他人似乎都在抄袭别人写的东西。
标签: c parallel-processing segmentation-fault mpi