fork download
  1. #include <mpi.h>
  2. #include <stdio.h>
  3.  
  4. int main(int argc, char** argv) {
  5. int rank;
  6. int buf;
  7. const int root=0;
  8.  
  9. MPI_Init(&argc, &argv);
  10. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  11.  
  12. if(rank == root) {
  13. buf = 777;
  14. }
  15.  
  16. printf("[%d]: Before Bcast, buf is %d\n", rank, buf);
  17.  
  18. /* everyone calls bcast, data is taken from root and ends up in everyone's buf */
  19. MPI_Bcast(&buf, 1, MPI_INT, root, MPI_COMM_WORLD);
  20.  
  21. printf("[%d]: After Bcast, buf is %d\n", rank, buf);
  22.  
  23. MPI_Finalize();
  24. return 0;
  25. }
Success #stdin #stdout #stderr 0.27s 37920KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted