I was wondering if a code like this can cause race conditions or any other error, and in case it can, how should I manage this situation?
int main(int argc, char **argv) {
int rank, num_procs;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Status status;
MPI_Request req;
if (!rank) {
while(condition){
int recv_buffer;
int other_recv;
int value = 1;
MPI_Recv(&recv_buffer, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
MPI_Isend(&value, 1, MPI_INT, recv_buffer, status.MPI_SOURCE, MPI_COMM_WORLD, &req);
MPI_Recv(&other_recv, 1, MPI_INT, status.MPI_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
/* end signal from process 0 to others */
}
else{
while(1){
int buffer = 1;
int other_value = 1;
int recv_buffer;
MPI_Isend(buffer, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &req);
MPI_Isend(&other_value, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &req);
MPI_Recv(&recv_buffer, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
/* if end message reached => break */
}
}
}
I need a communication like this.
Edit:changed some error in code