// passOne.c // Run this with 2 processes (0 and 1). This program passes the value of PI from processor 1 to // processor 0. // Note that MPI_Send and MPI_Recv use the address (&) of the variable sent or passed. // MPI_Recv uses the address of the status variable as its last argument. #include #include #include "mpi.h" int main(int argc, char **argv) { int rank, size; double pi; int i, count; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); count = 1; if (rank == 0) { MPI_Recv(&pi, 1, MPI_DOUBLE, 1, 10, MPI_COMM_WORLD, &status); printf("Data received from process 1:\n"); printf("%.20f\n", pi); } else { if (rank == 1) { pi = M_PI; MPI_Send(&pi, count, MPI_DOUBLE, 0, 10, MPI_COMM_WORLD); } } MPI_Finalize(); return 0; } /* CRAY SV1: cc passOneMPI.c mpirun -np 2 a.out Data received from process 1: 3.14159265358979000000 */