I am trying to let one process handle all the printtf operations so the printing happens in the order i want. I am trying to store the data that process 1 generate and let process 0 print the data that both process 0 and process 1 generate but i only get what process 0 is generating.
Here is the relevant part of the code
char str3[33]; char str4[66]; MPI_Barrier(MPI_COMM_WORLD); while (count<5){ MPI_Recv(&count,1,MPI_INT,(my_rank+1)%2,tag,MPI_COMM_WORLD,&status); char str[30]; if(my_rank==0) sprintf(str,"Process %d received the count\n",my_rank); if(my_rank==1) sprintf(str3,"Process %d received the count\n",my_rank); count++; char str2[66]; if (my_rank==0) sprintf(str2,"Process %d incremented the count(%d) and sent it back to process %d\n",my_rank,count,(my_rank+1)%2); if (my_rank==1) sprintf(str4,"Process %d incremented the count(%d) and sent it back to process %d\n",my_rank,count,(my_rank+1)%2); if(my_rank==0){ printf(str3); printf (str4); printf(str); printf(str2); memset(str3,'\0',sizeof(str3)); memset(str4,'\0',sizeof(str4)); memset(str,'\0',sizeof(str)); memset(str2,'\0',sizeof(str2)); } MPI_Send(&count,1,MPI_INT,(my_rank+1)%2,tag,MPI_COMM_WORLD); }
MPI_Recv()operation before theMPI_Send()? Does your program terminate properly ? Because i would expect a deadlock sinceMPI_Recv()is blocking until it receives a message that will never be sent...