#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) MPI_Bcast(array, MAXITEMS, MPI_INT, 0, MPI_COMM_WORLD); 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 sendArray1Bcast Here's the entire array from process 0: (starts on address 3221223488) 4 47 85 45 72 39 34 69 88 90 Hello from process 0 out of 6, Received: (starts on address 3221223488) 4 47 85 45 72 39 34 69 88 90 Hello from process 3 out of 6, Received: (starts on address 3221223744) 4 47 85 45 72 39 34 69 88 90 Hello from process 1 out of 6, Received: (starts on address 3221223744) 4 47 85 45 72 39 34 69 88 90 Hello from process 2 out of 6, Received: (starts on address 3221223744) 4 47 85 45 72 39 34 69 88 90 Hello from process 5 out of 6, Received: (starts on address 3221223744) 4 47 85 45 72 39 34 69 88 90 Hello from process 4 out of 6, Received: (starts on address 3221223744) 4 47 85 45 72 39 34 69 88 90 */