This is a simple MPI code sample to send, receive and print the procids of all non-root processes. Running the following code with the number of process > 3 results in Segfault with Exit Code 11.
int main(int argc, char *argv[])
{
int ierr, procid, numprocs;
int root = 0;
ierr = MPI_Init(&argc, &argv);
ierr = MPI_Comm_rank(MPI_COMM_WORLD, &procid);
ierr = MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
int i;
if (procid == root) {
int num;
for (i=1; i<numprocs; i++) {
printf("Waiting for response from %d\n", i);
MPI_Recv(&num, 1, MPI_INT, i, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Received: %d\n", num);
}
}
else {
printf("I am proc %d of %d\n", procid, numprocs);
MPI_Send(&procid, 1, MPI_INT, root, 0, MPI_COMM_WORLD);
}
ierr = MPI_Finalize();
}