/* 01_hello.c - the smallest useful MPI program: who am I, how many are we, where do I run?
 * Build: mpicc -O2 -o 01_hello 01_hello.c
 * Run:   mpirun -np 4 ./01_hello
 */
#include <stdio.h>
#include <mpi.h>

int main(int argc, char **argv)
{
    int rank, size, len;
    char host[MPI_MAX_PROCESSOR_NAME];

    MPI_Init(&argc, &argv);                    /* must come before any other MPI call */
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);      /* my id: 0 .. size-1 */
    MPI_Comm_size(MPI_COMM_WORLD, &size);      /* number of processes in the job */
    MPI_Get_processor_name(host, &len);        /* the node this process runs on */

    printf("Hello from rank %d of %d on %s\n", rank, size, host);

    MPI_Finalize();                            /* no MPI calls after this */
    return 0;
}
