I am trying to do LU decomposition using MPI.
Below is the snapshot of my code:
if(rank == 0)
{
//Send to each processor the row it owns
for(p=0;p<n;p++)
{
if(map[p]!=0)
{
MPI_Send(&LU[p*n],n,MPI_DOUBLE,map[p],1,MPI_COMM_WORLD);
printf("Sending row %d to %d itr = %d\n",p,map[p],i);
}
}
}
else
{
printf("in else rank = %d\n",rank);
for(l=0;l<n;l++)
{
if(map[l] == rank)
{
printf("in loop itr = %d, rank = %d l = %d n = %d\n",i,rank,l,n);
MPI_Recv(&LU[l*n],n,MPI_DOUBLE,0,1,MPI_COMM_WORLD,&st);
printf("Recv row %d at %d count = %d itr = %d\n",l,rank,count,i);
}
}
}
In this, if rank is zero, I am sending the row to each processor which will be the owner of this row and will perform the computation.
Otherwise, it will receive the rows corresponding to it. The loop is for multiple rows belonging to the same processor. Also map is a array private to each processor and stores the mapping information of each row.
However, after running my program for a 10*10 matrix for 4 instances,
execution gets blocked
It works fine for 1st iteration of i (all the code is inside this loop) but not for successive iterations.
EDIT:
The above code is a part of the code of LU decomposition. We are trying to achieve the following through the snapshot code
Consider 4 processors P0,P1,P2,P3 and a 10*10 matrix .
map will contain 0,1,2,3,0,1,2,3,0,1
which contains which processor is the owner of which row of the matrix . Through the send it is sending each row of the matrix to be worked on by each processor , i.e. P0 would send rows 1,5,9 to P1 , rows 2,6 to P2 and rows 3,7 to P3.
Each processor would in turn will receive the rows meant for it, through receive in the else part.
However my execution is getting blocked if I run this code.