/* file: bcast.c compile: cc -64 bcast.c -lmpi run: mpirun -np 4 ./a.out */ #include #include #define N 5 main(int argc, char *argv[]) { int num_procs; int my_proc; int a[N]; int i, j; int root=0; /* rank=0 */ /* initialize an array 'a' with -11 in all processes */ for(i = 0; i < N; i++) a[i] = -11; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &num_procs); MPI_Comm_rank(MPI_COMM_WORLD, &my_proc); /* update the array 'a' with -20 in the root process */ if (my_proc == root) { for(i=0;i