#include #include const int MAXROWS = 5; const int MAXCOLS = 5; int main(int argc, char **argv) { int size; int rank; int value=34567; int root=0; int matrix[MAXROWS][MAXCOLS]; int i, j; int anytag =0; int sum, totalsum; 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 < MAXROWS; i++) { for (j = 0; j < MAXCOLS; j++) { matrix[i][j] = rand() % 100; } } printf("Here's the entire array from process %d: (starts on address %u)\n", rank, matrix); for (i=0; i < MAXROWS; i++) { for (j = 0; j < MAXCOLS; j++) { printf("%5d ", matrix[i][j]); } printf("\n"); } printf("\n"); //Send the array to each process other then process 0 (root process) for (i=1; i < size; i++) { MPI_Send(matrix, MAXROWS*MAXCOLS, MPI_INT, i, anytag, MPI_COMM_WORLD); } } else { MPI_Recv(matrix, MAXROWS*MAXCOLS, MPI_INT, 0, anytag, MPI_COMM_WORLD, &status); printf("Hello from process %d out of %d Received:\n", rank, size); printf("(starts on address %u)\n", matrix); printf("Here's the entire array from process %d: (starts on address %u)\n", rank, matrix); for (i=0; i < MAXROWS; i++) { for (j = 0; j < MAXCOLS; j++) { printf("%5d ", matrix[i][j]); } printf("\n"); } printf("\n"); } MPI_Finalize(); return 0; } /* mpirun N sendMatrix1 Here's the entire array from process 0: (starts on address 3221223392) 20 65 85 52 72 66 76 52 81 10 18 32 12 22 30 87 46 90 82 52 63 68 99 74 96 Hello from process 2 out of 6 Received: (starts on address 3221223664) Here's the entire array from process 2: (starts on address 3221223664) 20 65 85 52 72 66 76 52 81 10 18 32 12 22 30 87 46 90 82 52 63 68 99 74 96 Hello from process 1 out of 6 Received: (starts on address 3221223664) Here's the entire array from process 1: (starts on address 3221223664) 20 65 85 52 72 66 76 52 81 10 18 32 12 22 30 87 46 90 82 52 63 68 99 74 96 Hello from process 4 out of 6 Received: (starts on address 3221223664) Here's the entire array from process 4: (starts on address 3221223664) 20 65 85 52 72 66 76 52 81 10 18 32 12 22 30 87 46 90 82 52 63 68 99 74 96 Hello from process 5 out of 6 Received: (starts on address 3221223664) Here's the entire array from process 5: (starts on address 3221223664) 20 65 85 52 72 66 76 52 81 10 18 32 12 22 30 87 46 90 82 52 63 68 99 74 96 Hello from process 3 out of 6 Received: (starts on address 3221223664) Here's the entire array from process 3: (starts on address 3221223664) 20 65 85 52 72 66 76 52 81 10 18 32 12 22 30 87 46 90 82 52 63 68 99 74 96 */