Definition
MPI_Comm_rank gets the rank of the calling MPI process in the communicator given.
int MPI_Comm_rank(MPI_Comm communicator,
int* rank);
Topology
C | Fortran-2008 | Fortran-90
MPI_Comm_rank gets the rank of the calling MPI process in the communicator given.
int MPI_Comm_rank(MPI_Comm communicator,
int* rank);
The MPI communicator to explore.
A pointer on the variable in which write the rank of the calling MPI process in the MPI communicator given.
The error code returned from the communicator rank retrieval.
MPI_SUCCESS
The routine successfully completed.
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
/**
* @brief For each process in the default communicator MPI_COMM_WORLD, show their rank.
**/
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
int my_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
printf("I am MPI process %d.\n", my_rank);
MPI_Finalize();
return EXIT_SUCCESS;
}