#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; } /* MPICH version on the workstations: mpicc.mpich arrayMPI.c mpirun.mpich -np 2 -all-local a.out (Enter password once) Data received from process 1: 383.0 886.0 777.0 915.0 793.0 335.0 386.0 492.0 649.0 421.0 362.0 27.0 690.0 59.0 763.0 926.0 540.0 426.0 172.0 736.0 211.0 368.0 567.0 429.0 782.0 530.0 862.0 123.0 67.0 135.0 929.0 802.0 22.0 58.0 69.0 167.0 393.0 456.0 11.0 42.0 229.0 373.0 421.0 919.0 784.0 537.0 198.0 324.0 315.0 370.0 413.0 526.0 91.0 980.0 956.0 873.0 862.0 170.0 996.0 281.0 305.0 925.0 84.0 327.0 336.0 505.0 846.0 729.0 313.0 857.0 124.0 895.0 582.0 545.0 814.0 367.0 434.0 364.0 43.0 750.0 87.0 808.0 276.0 178.0 788.0 584.0 403.0 651.0 754.0 399.0 932.0 60.0 676.0 368.0 739.0 12.0 226.0 586.0 94.0 539.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 */