title: MPI-Ibcast usage
body: <p>I try to understand how MPI_Ibcast works. 
  I came up with one test that illustrates what I need.
  It may not be correct, as I may not understand the right usage of Ibcast:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;mpi.h&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  
  using namespace std;
  
  class A {
  public:
          int a[3];
          MPI_Request request;
          int tag;
          A() {}
          int foo() {
                  int rank;
                  MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
                  cout&lt;&lt;rank&lt;&lt;endl;
                  if (rank == 0)
                          tag = 5;
                  MPI_Ibcast(&amp;tag, 1, MPI_INT, 0, MPI_COMM_WORLD, &amp;request);
          }
  };
  
  int main(int argc, char* argv[]) {
          MPI_Init(&amp;argc, &amp;argv);
          int rank;
          MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
          MPI_Status* status = new MPI_Status[2];
          MPI_Request* request = new MPI_Request[2];
          A* a = new A[2];
          for (int i = 0; i &lt; 2; i++) {
                  a[i].request = request[i];
          }
  
          for (int i = 0; i &lt; 2; i++) {
                  if (i == 0 &amp;&amp; rank == 0) {
                          a[0].foo();
                  }else if ( i == 1 &amp;&amp; rank == 1) {
                          a[1].foo();
                  }
                  int a;
                  for (int i = 0; i &lt; 1000; i++)
                          a+=i;
          }
          MPI_Waitall(2, request, status);
          cout &lt;&lt;a[1].tag&lt;&lt;" "&lt;&lt;a[1].tag&lt;&lt;" "&lt;&lt;a[1].tag&lt;&lt;endl;
          MPI_Finalize();
  }
  </code></pre>
  
  <p>I want to see, if MPI_Ibcast can be called in a function in the first iteration, then this function returns and in another iteration another process will also call MPI_Ibcast and then it all finishes ( tag will be broadcasted and set to 5 in all two processes). The reason why I use classes here is that I have them inside original program and here I try to model a small problem.</p>
  
  <p>So the task is: in separate cycles separate instances on separate processes call a function. Some of them are organized in groups, inside this group Ibcast broadcasts the tag. Here I have one group with two classes. Maybe I should somehow correct this example ?</p>