Definition
MPI_Barrier blocks all MPI processes in the given communicator until they all call this routine.
int MPI_Barrier(MPI_Comm communicator);
Collectives
Synchronisation
C | Fortran-2008 | Fortran-90
MPI_Barrier blocks all MPI processes in the given communicator until they all call this routine.
int MPI_Barrier(MPI_Comm communicator);
The communicator in which the barrier takes place.
The error code returned from the barrier.
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
/**
* @brief Illustrates how to use an MPI barrier.
**/
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
// Get my rank
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
printf("[MPI process %d] I start waiting on the barrier.\n", my_rank);
MPI_Barrier(MPI_COMM_WORLD);
printf("[MPI process %d] I know all MPI processes have waited on the barrier.\n", my_rank);
MPI_Finalize();
return EXIT_SUCCESS;
}