title: mpi_gather for struct with dynamic array
body: <p>I have a struct: </p>
  
  <pre><code>typedef struct 
  { 
  double distance;
  int* path;
  } tour;
  </code></pre>
  
  <p>Then I trying to gather results from all processes:</p>
  
  <pre><code>   MPI_Gather(&amp;best, sizeof(tour), MPI_BEST, all_best, sizeof(tour)*proc_count, MPI_BEST, 0, MPI_COMM_WORLD);
  </code></pre>
  
  <p>After gather my root see that all_best containts only 1 normal element and trash in others.
  Type of  all_best is tour*.</p>
  
  <p>Initialisation of MPI_BEST:</p>
  
  <pre><code> void ACO_Build_best(tour *tour,int city_count, MPI_Datatype *mpi_type /*out*/)
   {
  int block_lengths[2];
  MPI_Aint displacements[2];
  MPI_Datatype typelist[2];
  MPI_Aint start_address;
  MPI_Aint address;
  
  block_lengths[0] = 1;
  block_lengths[1] = city_count;
  
  typelist[0] = MPI_DOUBLE;
  typelist[1] = MPI_INT;
  
  MPI_Address(&amp;(tour-&gt;distance), &amp;displacements[0]);
  MPI_Address(&amp;(tour-&gt;path), &amp;displacements[1]);
  
  displacements[1] = displacements[1] - displacements[0];
  displacements[0] = 0;
  
  MPI_Type_struct(2, block_lengths, displacements, typelist, mpi_type);
  MPI_Type_commit(mpi_type);
  }
  </code></pre>
  
  <p>Any ideas are welcome.</p>