#include #include const int MAXITEMS = 10; int main(int argc, char **argv) { int size; int rank; int value=34567; int root=0; int array[MAXITEMS]; int i; int anytag =0; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) { srand(time(0)); for (i=0; i < MAXITEMS; i++) { array[i] = rand() % 100; } printf("Here's the entire array from process %d: (starts on address %u)\n", rank, array); for (i=0; i < MAXITEMS; i++) { printf("%d ", array[i]); } printf("\n"); //Send the array to each process other then process 0 (root process) for (i=1; i < size; i++) { MPI_Send(array, MAXITEMS, MPI_INT, i, anytag, MPI_COMM_WORLD); } } else { MPI_Recv(array, MAXITEMS, MPI_INT, 0, anytag, MPI_COMM_WORLD, &status); printf("Hello from process %d out of %d, Received: ", rank, size); printf("(starts on address %u)\n", array); for (i=0; i < MAXITEMS; i++) { printf("%d ", array[i]); } printf("\n"); } MPI_Finalize(); return 0; } /* mpirun N sendArray1 Here's the entire array from process 0: (starts on address 3221223504) 8 20 31 59 48 30 13 39 86 25 Hello from process 2 out of 6, Received: (starts on address 3221223760) 8 20 31 59 48 30 13 39 86 25 Hello from process 1 out of 6, Received: (starts on address 3221223760) 8 20 31 59 48 30 13 39 86 25 Hello from process 5 out of 6, Received: (starts on address 3221223760) 8 20 31 59 48 30 13 39 86 25 Hello from process 3 out of 6, Received: (starts on address 3221223760) 8 20 31 59 48 30 13 39 86 25 Hello from process 4 out of 6, Received: (starts on address 3221223760) 8 20 31 59 48 30 13 39 86 25 */