title: Inconsistent data received with respect to MPI_Isend
body: <p>I am passing arrays of objects between master and workers using the MPI library. As there are numerous objects, I am using <code>MPI_Isend</code> and then <code>MPI_Recv</code> in for loops. Everything works well except for the last <code>MPI_Recv</code> in which <code>MPI_Recv</code> receives only the last sent element of <code>MPI_Isent</code>, additionally the code terminates without any error.</p>
  <p>The sent input is:</p>
  <pre><code>1 2 3 0.4 0 4 5 1 
  2 4 7 0.678 0 8 1
  ....
  5 8 7 0.56 0 6 1
  </code></pre>
  <p>and the received input is:</p>
  <pre><code>5 8 7 0.56 0 6 1
  5 8 7 0.56 0 6 1
  5 8 7 0.56 0 6 1
  .... (always the same) 
  </code></pre>
  <p>My question is simply: Why ? I have the feeling something is getting overwritten in the MPI transmission, but I can't figure out where, and why. The first part of my code seems ok, my problem is at the very last part.</p>
  <h2>Edit</h2>
  <p>According to the comments, the problem is that there is no <code>MPI_Waitall()</code> verifying for completion. I must admit having trouble understanding where to insert any <code>MPI_Wait</code>or <code>MPI_Waitall</code>.</p>
  <p><strong>main.cpp</strong></p>
  <pre><code>MPI_Datatype mpi_gene = MPI_Send_Genes();
  MPI_Request reqs_6[size_req], reqs_7[size_req]; 
  MPI_Status status_7[size_req];
  
  if(rank==0){
  
      for(int r=1; r &lt; com; r++){
        
        MPI_Isend(&amp;num_orgs, 1, MPI_INT, r, 0, parallel_0, &amp;reqs_0[r]);
  
        for(int org = 0; org &lt; NEAT::pop_size; org++){
  
          //send some genome information
          genome_info g_info;
          g_info.generation = pop-&gt;organisms[org]-&gt;generation;
          MPI_Isend(&amp;g_info, 1, mpi_genome_info, r, org, parallel_1, &amp;reqs_1[org]);
  
          //define the genome
          NEAT::Genome* sent_genome = pop-&gt;organisms[org]-&gt;gnome;
  
          //third the genes
          std::vector&lt;NEAT::Gene*&gt; gen_genes = sent_genome-&gt;genes;
          int num_genes = gen_genes.size();
          struct genes sent_genes[num_genes];
  
          for(int id = 0; id &lt; num_genes; id++){
            if(gen_genes[id]-&gt;lnk-&gt;linktrait==0){
              sent_genes[id].trait_id = 0;
            }else{
              sent_genes[id].trait_id = gen_genes[id]-&gt;lnk-&gt;linktrait-&gt;trait_id;
            }
            sent_genes[id].in_node_id = gen_genes[id]-&gt;lnk-&gt;in_node-&gt;node_id;
            sent_genes[id].out_node_id = gen_genes[id]-&gt;lnk-&gt;out_node-&gt;node_id;
            sent_genes[id].weight = gen_genes[id]-&gt;lnk-&gt;weight;
            sent_genes[id].recurrent = gen_genes[id]-&gt;lnk-&gt;is_recurrent;
            sent_genes[id].innovation_num = gen_genes[id]-&gt;innovation_num;
            sent_genes[id].mutation_num = gen_genes[id]-&gt;mutation_num;
            sent_genes[id].enable = gen_genes[id]-&gt;enable;
  
            if(id==3){
              std::cout &lt;&lt; 
            sent_genes[id].in_node_id &lt;&lt; &quot; &quot; &lt;&lt;
            sent_genes[id].out_node_id &lt;&lt;&quot; &quot; &lt;&lt;
            sent_genes[id].weight &lt;&lt;&quot; &quot; &lt;&lt;
            sent_genes[id].recurrent &lt;&lt;&quot; &quot; &lt;&lt;
            sent_genes[id].innovation_num &lt;&lt;&quot; &quot; &lt;&lt;
            sent_genes[id].mutation_num &lt;&lt;&quot; &quot; &lt;&lt;
            sent_genes[id].enable &lt;&lt;&quot; &quot; &lt;&lt;
            std::endl; 
            }
          }
  
          MPI_Isend(&amp;num_genes, 1, MPI_INT, r, org, parallel_6, &amp;reqs_6[org]);
          MPI_Isend(&amp;sent_genes, num_genes, mpi_gene, r, org, parallel_7, &amp;reqs_7[org]); 
        }
      }
    }
    
    std::cout &lt;&lt; &quot;--------------&quot; &lt;&lt; std::endl; 
  
      if(rank!=0){
  
        std::vector&lt;NEAT::Organism*&gt; local_pop;
        int generation;
        MPI_Recv(&amp;num_orgs, 1, MPI_INT, 0, 0, parallel_0, &amp;status);
        
        for(int org = 0; org &lt; num_orgs ; org++){
  
          //receive genome information
          genome_info rcvd_genome_info;
          MPI_Recv(&amp;rcvd_genome_info, 1, mpi_genome_info, 0, org, parallel_1, &amp;status);
          generation = rcvd_genome_info.generation; 
  
          //receive genes 
          int num_rcvd_genes;
          MPI_Recv(&amp;num_rcvd_genes, 1, MPI_INT, 0, org, parallel_6, &amp;status);
          genes rcvd_genes[num_rcvd_genes];
          MPI_Recv(&amp;rcvd_genes, num_rcvd_genes, mpi_gene, 0, org, parallel_7, &amp;status);
          MPI_Waitall(size_req, &amp;reqs_7[size_req], MPI_STATUSES_IGNORE);
          std::cout &lt;&lt; num_rcvd_genes &lt;&lt; std::endl; //this is ok
          std::vector&lt;NEAT::Gene*&gt; gen_genes;
          for(int id = 0; id &lt; num_rcvd_genes; id++){
            genes p_gene = rcvd_genes[id];
  
            if(id==3){//PROBLEM HERE
              std::cout &lt;&lt; id &lt;&lt; &quot; &lt;- &quot;&lt;&lt;
              p_gene.in_node_id &lt;&lt; &quot; &quot; &lt;&lt;
              p_gene.out_node_id &lt;&lt;&quot; &quot; &lt;&lt;
              p_gene.weight &lt;&lt;&quot; &quot; &lt;&lt;
              p_gene.recurrent &lt;&lt;&quot; &quot; &lt;&lt;
              p_gene.innovation_num &lt;&lt;&quot; &quot; &lt;&lt;
              p_gene.mutation_num &lt;&lt;&quot; &quot; &lt;&lt;
              p_gene.enable &lt;&lt;&quot; &quot; &lt;&lt;
              std::endl; 
            }
          }
        }
        MPI_Waitall(size_req, &amp;reqs_7[size_req], MPI_STATUSES_IGNORE);
      }
  </code></pre>
  <p><strong>send_genes.cpp</strong></p>
  <pre><code>MPI_Datatype MPI_Send_Genes(){
  
    int nitems = 8;
    int gene_blocklengths[nitems] = {1,1,1,1,1,1,1,1};
    MPI_Datatype gene_types[nitems] = {MPI_INT, MPI_INT, MPI_INT, MPI_DOUBLE, MPI_C_BOOL, MPI_DOUBLE, MPI_DOUBLE, MPI_C_BOOL};
    MPI_Datatype mpi_gene;
    MPI_Aint gene_offsets[nitems];
  
    gene_offsets[0] = offsetof(genes, trait_id);
    gene_offsets[1] = offsetof(genes, in_node_id);
    gene_offsets[2] = offsetof(genes, out_node_id);
    gene_offsets[3] = offsetof(genes, weight);
    gene_offsets[4] = offsetof(genes, recurrent);
    gene_offsets[5] = offsetof(genes, innovation_num);
    gene_offsets[6] = offsetof(genes, mutation_num);
    gene_offsets[7] = offsetof(genes, enable);
  
    MPI_Type_create_struct(nitems, gene_blocklengths, gene_offsets, gene_types, &amp;mpi_gene);
    MPI_Type_commit(&amp;mpi_gene);
  
    return mpi_gene;   
  }
  </code></pre>
  <p><strong>send_genes.h</strong></p>
  <pre><code>struct genes{
    int trait_id;
    int in_node_id;
    int out_node_id;
    double weight;
    bool recurrent;
    double innovation_num;
    double mutation_num;
    bool enable;
  };
  </code></pre>