I need to check if a MPI communicator is MPI_COMM_WORLD comm. This means that all processors are within this communicator.
I tried this
int isCommWolrd(MPI_Comm comm) {
    int size_comm = 0;
    int size_comm_world = 0;
    MPI_Comm_size(comm, &size_comm);
    MPI_Comm_size(MPI_COMM_WORLD, &size_comm_world);
    return (size_comm == size_comm_world);
}
Is it sufficient to check only the sizes of the communicator. Can there be a false positive of negative?
                        
Use
MPI_Comm_compare()and check the result isMPI_IDENTYour method can lead so false positive. For example, if you
MPI_Comm_dup(MPI_COMM_WORLD, &comm), then the resultingcommhas the same size thanMPI_COMM_WORLD, but it a different communicator.