/* "hello world" program */ #include #include #include /* MPI header file */ int main(int argc, char *argv[]) { int nprocs; int myid; /* initialize for MPI (should come before any other calls to MPI routines) */ if (MPI_Init(&argc, &argv) != MPI_SUCCESS) { fprintf(stderr, "MPI initialization error\n"); exit(EXIT_FAILURE); } /* get number of processes (function returns success/error, but we ignore it) */ MPI_Comm_size(MPI_COMM_WORLD, &nprocs); /* get this process's number (ranges from 0 to nprocs - 1) (function returns success/error, but we ignore it) */ MPI_Comm_rank(MPI_COMM_WORLD, &myid); /* print a greeting */ printf("hello from process %d of %d\n", myid, nprocs); /* clean up for MPI (should come after all other calls to MPI routines) (function returns success/error, but we ignore it) */ MPI_Finalize(); return EXIT_SUCCESS; }