To get the size of a communicator (e.g. MPI_COMM_WORLD
) and the local process' rank inside it:
int rank, size;
int res;
MPI_Comm communicator = MPI_COMM_WORLD;
res = MPI_Comm_rank (communicator, &rank);
if (res != MPI_SUCCESS)
{
fprintf (stderr, "MPI_Comm_rank failed\n");
exit (0);
}
res = MPI_Comm_size (communicator, &size);
if (res != MPI_SUCCESS)
{
fprintf (stderr, "MPI_Comm_size failed\n");
exit (0);
}