Hi,
I am trying the following parallel code,but during the execution there creates a deadlock right after when MASTER node that is rank-0 recieved the string "RESULT" from the slave rank.
Can anybody help me in removing this deadlock,I have already spent two days on this code but invain.
Code is given below
/*******************************************************************************/
#include "mpi.h"
int master(void);
int slave(void);
#define WORKTAG 1
#define Result_TAG 2
static char RESULT[15] = "RESULT";
int main(int argc,char *argv[])
{
int my_rank, size;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
if(my_rank == 0)
{
master();
}
else
{
slave();
}
MPI_Finalize();
return (0);
}
/////////////////////////
// MASTER //
/////////////////////////
int
master(void)
{
int my_rank,rank,ntasks,done=0,source;
int work=555, R_work;
char buff[15];
MPI_Status status;
MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
MPI_Comm_size(MPI_COMM_WORLD,&ntasks);
//MASTER DOING WORK
//MASTER sending instructions to start doing work
for(rank = 1; rank < ntasks; ++rank){
MPI_Send(&work, 1, MPI_INT, rank, WORKTAG, MPI_COMM_WORLD);
printf("I am %d sending %d towards %d WITH tag %d\n", my_rank, work, rank,WORKTAG);
}
//MASTER sending RESULTS after doing some processing to rank-0
MPI_Send(RESULT, 15, MPI_CHAR, 0, Result_TAG, MPI_COMM_WORLD);
printf("I am rank %d sending %s towards rank-0 WITH tag %d\n", my_rank, RESULT,Result_TAG);
//MASTER recieving Results from all nodes including master
while(done <= (ntasks)) {
MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
source = status.MPI_SOURCE;
MPI_Recv(buff,15,MPI_CHAR,source,Result_TAG,MPI_COMM_WORLD,&status);
done++;
printf("Master recieved + %s +from rank %d \n",buff,source,ntasks);
}
return(0);
}
/////////////////////////
// SLAVE FUNCTION //
/////////////////////////
int slave(void)
{
int my_rank,rank,ntasks;
int R_work;
MPI_Status status;
char buff[15];
MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);
MPI_Comm_size(MPI_COMM_WORLD,&ntasks);
//SLAVE recieving instructions to start doing work
MPI_Recv(&R_work, 1, MPI_INT, 0, WORKTAG, MPI_COMM_WORLD, &status);
printf("===I am rank %d and recieved %d from rank %d with tag %d\n", my_rank, R_work, status.MPI_SOURCE,status.MPI_TAG);
//SLAVE sending RESULT after doing processing to rank-0
MPI_Send(RESULT, 15, MPI_CHAR, 0, Result_TAG, MPI_COMM_WORLD);
printf("I am rank %d sending %s towards rank%d WITH tag %d\n", my_rank, RESULT, rank,Result_TAG);
return (0);
}
Ahmed irshad
---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
|