// arrayMPI.c // Run this with 2 processors. Processor 1 creates an array of 'count' random // numbers. In this example 'count' is 100. Processor 0 (the root process) // receives this array from processor 1. // Make sure you are understanding what each parameter in the MPI calls represe\ nt. #include #include "mpi.h" int main(int argc, char **argv) { int rank, size; MPI_Status status; double data[100]; int i, count; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); count = 100; if (rank == 0) { MPI_Recv(data, 100, MPI_DOUBLE, 1, 10, MPI_COMM_WORLD, &status); printf("Data received from process 1:\n"); for (i = 0; i < count; i++) { printf("%7.1f", data[i]); if (i % 10 == 9) printf("\n"); } printf("\n"); } else { if (rank == 1) { for (i = 0; i < count; i++) data[i] = rand() % 1000; MPI_Send(data, count, MPI_DOUBLE, 0, 10, MPI_COMM_WORLD); } } MPI_Finalize(); return 0; } /* CRAY SV1: cc arrayMPI.c mpirun -np 2 a.out Data received from process 1: 838.0 758.0 113.0 515.0 51.0 627.0 10.0 419.0 212.0 86.0 749.0 767.0 84.0 60.0 225.0 543.0 89.0 183.0 137.0 566.0 966.0 978.0 495.0 311.0 367.0 54.0 31.0 145.0 882.0 736.0 524.0 505.0 394.0 102.0 851.0 67.0 754.0 653.0 561.0 96.0 628.0 188.0 85.0 143.0 967.0 406.0 165.0 403.0 562.0 834.0 353.0 920.0 444.0 803.0 962.0 318.0 422.0 327.0 457.0 945.0 479.0 983.0 751.0 894.0 670.0 259.0 248.0 757.0 629.0 306.0 606.0 990.0 738.0 516.0 414.0 262.0 116.0 825.0 181.0 134.0 343.0 22.0 233.0 536.0 760.0 979.0 71.0 201.0 336.0 61.0 160.0 5.0 729.0 644.0 475.0 693.0 514.0 139.0 88.0 521.0 */