/* bcast.c check broadcast */ #include "mpi.h" #include int main(int argc, char *argv[]) { int proc, myid, numprocs; int count = 1; int master = 0; double esec = 0.0; int bufout[1000]; /* initialized by master, received by all */ MPI_Status status; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); if(myid == 0) { printf("bcast.c numprocs=%d \n", numprocs); printf("Bcast is blocking and must be executed by all.\n"); printf("there is no guarantee of order from printf.\n"); bufout[0] = 100; } /* all */ MPI_Bcast(bufout, count, MPI_INT, master, MPI_COMM_WORLD); esec = MPI_Wtime(); printf("recvd bcast %d for proc=%d at %g sec\n", bufout[0], myid, esec); MPI_Finalize(); return 0; }