Is there any way to add a barrier in MPI code.
By barrier I mean, I want all the different processors to first finish till a point and then carry on from there. That is a processor must wait for the other processors to finish the code till that region and then only proceed to the remaining part of the code.
For Example,
int main()
{
.
.
.
//I want all my processors to do till this and
wait for other processers to complete till this point,
and then resume the remaining part
.
.
.
}
Is there any way to do this in MPIch?
That is a processor must wait for the other processors to finish the code till that region and then only proceed to the remaining part of the code.
Yes, what you are looking for is the routine MPI_Barrier:
Blocks until all processes in the communicator have reached this routine.
Notes
Blocks the caller until all processes in the communicator have called it; that is, the call returns at any process only after all members of the communicator have entered the call.
To learn more about when to use a MPI_Barrier you can read When do I need to use MPI_Barrier()?