void iso_diffusion_denoising(image *u, image *u_bar, float kappa, int iters) {
int my_rank,num_procs;
float *temp;
int i,j,k=0;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
int m=u->m;
int n=u->n;
//temp= malloc(n*sizeof(float));//1*n array ?
float *ptr;
for(k=0;k<iters;k++) {
for(i=1; i<m-1; i++) {
for(j=1; j<n-1; j++) {
/* temp[m-1]=u->image_data[m-1][0];
temp[m-1]=u->image_data[m-1][n-1];
temp[i]=u->image_data[m-1][j];*/
u_bar->image_data[i][j]= u->image_data[i][j] + kappa*(u->image_data[i-1][j] + u->image_data[i][j-1] - 4*u->image_data[i][j] + u->image_data[i][j+1] + u->image_data[i+1][j]);
u->image_data[i][j]=u_bar->image_data[i][j];
}
}
//temp[m-1][n-1]
if(my_rank==0) {
ptr = u->image_data[m-1];
MPI_Send(&ptr[0],n,MPI_FLOAT,1,1,MPI_COMM_WORLD);
MPI_Recv(&temp,n,MPI_FLOAT,1,2,MPI_COMM_WORLD,&status);
printf("my rank is : %d ", my_rank);
fflush(stdout);
} else if(my_rank==1) { //if(my_rank!=num_procs) {
ptr = u->image_data[0];
MPI_Send(&ptr[0],n,MPI_FLOAT,0,2,MPI_COMM_WORLD);
MPI_Recv(&temp,n,MPI_FLOAT,1,1,MPI_COMM_WORLD,&status);
printf("my rank is : %d ", my_rank);
fflush(stdout);
}
}
}
mpirun -np 2 Oblig 0.1 20 noisy denoised
my rank is : 1114636288 [safir:22140] *** Process received signal ***
--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 22140 on node safir.ifi.uio.no exited on signal 11 (Segmentation fault).
why is my_rank printed out with a very large value? Also I get a segmentation fault.
The problem appears to be with your first argument to MPI_Recv. Here you are sending a pointer to
tempwhich is itself a pointer. MPI_Recv is trying to copynfloats starting at the memory location reserved for thetemppointer. You need to allocate memory fortemp(uncomment the call to malloc) and change the MPI_Recv calls to:This is most likely where
my_rankis getting it’s garbage value. MPI_Recv is trying to writen * sizeof(float)bytes of data wheretempis stored and is overwriting into memory reserved for other variables, i.e.my_rank.And don’t forget to free up any memory you allocate for
tempwhen you are done with it!A couple other things, I’ve done very little MPI programming but I think your MPI_Recv call in the
my_rank == 1block should have a source of 0. I also thought MPI_Send and MPI_Recv were blocking calls – in other words they don’t return until the transfer either completes or fails. Since both of your ranks are calling MPI_Send first I would expect them to both block and deadlock your program. Maybe they are failing – you should check the return value of MPI_Send for success.