#include #include int main(int argc, char** argv) { int rank, size; /* initialize MPI */ MPI_Init(&argc, &argv); /* get the rank (process id) and size (number of processes) */ MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); /* the data our program operatres on */ char string[100]; /* have process 0 read in a string */ if (rank == 0) { printf("Enter a string: "); fflush(stdout); scanf("%s", string); } /* now broadcast this out to all processes */ MPI_Bcast(string, 100, MPI_CHAR, 0, MPI_COMM_WORLD); /* print the string */ printf("Process %d has %s!\n", rank, string); /* quit MPI */ MPI_Finalize(); return 0; }