MPI - 分段故障退出代码:139

时间:2016-09-12 21:37:24

标签: c parallel-processing segmentation-fault mpi

我有一个简单的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;
}

1 个答案:

答案 0 :(得分:3)

我对其余的代码不太确定(似乎没问题,但我看起来不太近),但可以肯定的是,你得到了他MPI_Recv() / MPI_Send()对错了。问题是你发送和接收30个整数的数组,而你只为每个整数分配了内存。 尝试在3 301次来电中用MPI_Send()替换MPI_Recv()参数,您的代码可能会正常工作。