/* A simple example of MPI broadcast. */ #include #include #include #include int main (int argc, char *argv[]) { int rank, size, aNumber, i, maxIter; const int root=0; char hostname[256]; MPI_Init (&argc, &argv); /* starts MPI */ MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */ MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */ gethostname(hostname, 255); /* get host name */ maxIter = 6; if(rank == 0) { aNumber = 17; } else { aNumber = -1; } printf("[Rank %d on host %s]: Before Bcast, aNumber is %d\n", rank, hostname, aNumber); for (i=0; i