#include #include int main(int argc, char **argv) { int rank, size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if ( rank == 0 ) { /* Rank 0 sends an integer to each of the other process ranks */ int i; int value = 0; for (i = 1; i < size; i++) { value = value + i; MPI_Send(&value, 1, MPI_INT, i, 0, MPI_COMM_WORLD); } } else { /* All other process ranks receive one number from Rank 0 */ int value; MPI_Status status; MPI_Recv(&value, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status); printf("Rank %d received value %d\n", rank, value); } MPI_Finalize(); return 0; }