#include #include #include "mpi.h" int main(int argc, char **argv) { int rank, size; MPI_Status status; double pi; int i, count, source; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); count = 1; source = 0; if (rank == source) { pi = M_PI; printf("Rank %d is broadcasting %.10f\n", rank, pi); } MPI_Bcast(&pi, 1, MPI_DOUBLE, source, MPI_COMM_WORLD); if (rank != source) { printf("Rank %d receives %.10f from process %d\n", rank, pi, source); } MPI_Finalize(); return 0; } /* MPICH version on the workstations: mpicc.mpich bcast.c mpirun.mpich -np 4 -all-local a.out (Enter password 3 times) Rank 0 is broadcasting 3.1415926536 Rank 2 receives 3.1415926536 from process 0 Rank 1 receives 3.1415926536 from process 0 Rank 3 receives 3.1415926536 from process 0 CRAY SV1: cc bcast.c mpirun -np 8 a.out Rank 0 is broadcasting 3.1415926536 Rank 1 receives 3.1415926536 from process 0 Rank 2 receives 3.1415926536 from process 0 Rank 3 receives 3.1415926536 from process 0 Rank 4 receives 3.1415926536 from process 0 Rank 5 receives 3.1415926536 from process 0 Rank 6 receives 3.1415926536 from process 0 Rank 7 receives 3.1415926536 from process 0 mpirun -np 4 a.out Rank 0 is broadcasting 3.1415926536 Rank 2 receives 3.1415926536 from process 0 Rank 3 receives 3.1415926536 from process 0 Rank 1 receives 3.1415926536 from process 0 */