I want to resolve stack smashing error in the code
I have tried running the code with mpicc and mpiexec
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
int rank,size,x,status;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if(rank==0)
{
scanf("%d",&x);
MPI_Send(&x,1,MPI_INT,1,1,MPI_COMM_WORLD);
printf("I have send %d from process 0\n",x);
//fflush(stdout);
}
else
{
MPI_Recv(&x,1,MPI_INT,0,1,MPI_COMM_WORLD,&status);
printf("I have received %d in process 1\n",x);
//fflush(stdout);
}
MPI_Finalize();
return 0;
}
I expected the code to print the receiving and sending statements but the actual output prints the receiving and sending statements and gives
* stack smashing error *
I can't understand why does it happen?
status
should be of typeMPI_Status
. Might be the cause of your error, might not. - john