#include #include #include #include int main(int argc, char** argv) { int rank, size; /* initialize MPI */ MPI_Init(&argc, &argv); /* get the rank (process rank) and size (number of processes) */ MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); /* we start to work */ printf("Process %d starting!\n", rank); /* simulate the processes taking slightly different amounts of time by sleeping * for our process rank seconds */ sleep(rank); printf("Process %d is done its work!\n", rank); fflush(stdout); /* a barrier */ MPI_Barrier(MPI_COMM_WORLD); printf("Process %d is past the barrier!\n", rank); fflush(stdout); /* quit MPI */ MPI_Finalize(); return 0; }