c - MPI - Segmentation fault EXIT CODE: 139 -
i have simple mpi code runs before terminating shows following error.
=== = bad termination of 1 of application processes = exit code: 139 = cleaning remaining processes = can ignore below cleanup messages =================================================================================== application terminated exit string: segmentation fault (signal 11) typically refers problem application.
below source code.
/* 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 value %d\n", rank, ball_value); if (ball_value == 1000) break; if (abs(ball_value) > 100) { int send_1000 = 1000; int i; (i = 0; < size; i++) if (i != rank) mpi_send(&send_1000, 30, mpi_int, i, 10, mpi_comm_world); //broadcast others break; } ball_value += delta; int next_to_send = rand() % size; if (next_to_send != rank) { printf("sending ball %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; }
i'm not sure rest of code (seems ok didn't closely), sure you've got mpi_recv()
/ mpi_send()
pairs wrong. problem send , receive arrays of 30 integers, while allocated memory 1 of each. try replacing 30
parameter 1
in 3 mpi_send()
or mpi_recv()
calls, , code might work.
Comments
Post a Comment