// mpicc notes.c -o n ; mpirun -n 4 ./n

#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv[]) {
    int nprocs, myrank;

    /* Initialize the MPI environment. 
       Unlike Fortran, C passes the command line arguments. */
    MPI_Init(&argc, &argv);
    
    /* Obtain the total number of processes. 
       Note the '&' to pass nprocs by reference. */
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
    
    /* Obtain the rank of the calling process. */
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

    /* All processes synchronize here: */
    MPI_Barrier(MPI_COMM_WORLD);

    /* Print the formatted output */
    printf("I am process: %d of %d\n", myrank, nprocs);

    /* Terminate the MPI environment */
    MPI_Finalize();

    return 0;
}
