title: Using MPI_Bcast for MPI communication
body: <p>I'm trying to broadcast a message from the root node to all other nodes using MPI_Bcast. However, whenever I run this program it always hangs at the beginning. Does anybody know what's wrong with it?</p>
  
  <pre><code>#include &lt;mpi.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(int argc, char** argv) {
          int rank;
          int buf;
          MPI_Status status;
          MPI_Init(&amp;argc, &amp;argv);
          MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
  
          if(rank == 0) {
                  buf = 777;
                  MPI_Bcast(&amp;buf, 1, MPI_INT, 0, MPI_COMM_WORLD);
          }
          else {
                  MPI_Recv(&amp;buf, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &amp;status);
                  printf("rank %d receiving received %d\n", rank, buf);
          }
  
          MPI_Finalize();
          return 0;
  }
  </code></pre>