title: Send dynamic array with dynamic size using MPI_Bcast
body: <p>OpenMPI: I want to read a file on the root node and send the contents of that file to all other nodes.
  I have found that MPI_Bcast does that :</p>
  
  <pre><code>int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype,
      int root, MPI_Comm comm)
  </code></pre>
  
  <p>All the examples that I have found have the <code>count</code> value already known, but in my case, the count value is primarily known on the root.  Other <a href="https://stackoverflow.com/questions/7864075/using-mpi-bcast-for-mpi-communication">examples</a> say the same call of MPI_Bcast retrieves data on the other nodes.</p>
  
  <p>I've added this:</p>
  
  <pre><code>typedef short Descriptor[128];
  MPI_Datatype descriptorType;
  MPI_Type_contiguous(sizeof(Descriptor), MPI_SHORT, &amp;descriptorType);
  MPI_Type_commit(&amp;descriptorType);
  
  
  
   if(world_rank == 0)   {
    struct stat finfo;
  
    if(stat(argv[1], &amp;finfo) == 0) {
          querySize = finfo.st_size/sizeof(Descriptor);
    }
  
   {
    //read binary query
    queryDescriptors = new Descriptor[querySize];
    fstream qFile(argv[1], ios::in | ios::binary);
    qFile.read((char*)queryDescriptors, querySize*sizeof(Descriptor));
    qFile.close();
  
    }
  }
  
    MPI_Bcast((void*)&amp;querySize, 1, MPI_INT, 0, MPI_COMM_WORLD);
    if (world_rank != 0)
    {
          queryDescriptors = new Descriptor[querySize];
    }
    MPI_Bcast((void*)queryDescriptors, querySize, descriptorType, 0, MPI_COMM_WORLD);
  </code></pre>
  
  <p>When I call it like this :  <code>mpirun -np 2 ./mpi_hello_world</code> it works ok, but when I call it with more than <strong>2</strong>, I get this:</p>
  
  <pre><code>mpi_hello_world: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &amp;((av)-&gt;bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) &amp;&amp; old_size == 0) || ((unsigned long) (old_size) &gt;= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) &amp; ~((2 * (sizeof(size_t))) - 1))) &amp;&amp; ((old_top)-&gt;size &amp; 0x1) &amp;&amp; ((unsigned long)old_end &amp; pagemask) == 0)' failed.
  mpi_hello_world: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &amp;((av)-&gt;bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) &amp;&amp; old_size == 0) || ((unsigned long) (old_size) &gt;= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) &amp; ~((2 * (sizeof(size_t))) - 1))) &amp;&amp; ((old_top)-&gt;size &amp; 0x1) &amp;&amp; ((unsigned long)old_end &amp; pagemask) == 0)' failed.
  </code></pre>