title: Receive information in for loop produces strange error
body: <p>I am trying to broadcast parts of an array composed of objects from the master node to the workers using for loops in the <code>MPI</code> library. I am having problems with the <code>Recv</code>steps. Generally speaking, I am open to any recommendation as I think there are simpler ways to address my problem. In my code, compiling each individual <code>MPI_Send</code>/<code>MPI_Recv</code> works perfectly, but not all together at once.</p>
  <pre><code>  if(rank==0){
      for(unsigned int r=1; r &lt; com; r++){ //r is the node identifier
        for(int org = 0; org &lt; NEAT::pop_size; org++){
          ...
          std::vector&lt;NEAT::Trait*&gt; gen_traits = ...; 
          struct traits sent_traits[num_traits];
  
          for(int id = 0; id &lt; num_traits; id++){
            sent_traits[id].trait_id = gen_traits[id]-&gt;trait_id;
            ...and other stuff
          }
  
          MPI_Isend(&amp;num_traits, 1, MPI_INT, r, org, parallel_2, &amp;reqs_2[org]);
          MPI_Isend(&amp;sent_traits, 1, mpi_trait, r, org, parallel_3, &amp;reqs_3[org]);
  </code></pre>
  <p>Compiling up to here with the respective MPI_Recv (see following) works. The strange part comes hereafter: as soon as I include <code>Recv</code> of the vector of nodes the program crashes.</p>
  <pre><code>      struct nodes sent_nodes[num_nodes];
        for(int id = 0; id &lt; num_nodes; id++){
          sent_nodes[id].node_id = gen_nodes[id]-&gt;node_id;
          if(gen_nodes[id]-&gt;nodetrait==0){
            sent_nodes[id].trait_id = 0;
          ...
        }
        
        MPI_Isend(&amp;num_nodes, 1, MPI_INT, r, org+1, parallel_4, &amp;reqs_4[org]); 
        MPI_Isend(&amp;sent_nodes, 1, mpi_node, r, org+1, parallel_5, &amp;reqs_5[org]); 
      }
    }
  }
  
  MPI_Barrier;
  if(rank!=0){
      for(int org = 0; org &lt; num_orgs ; org++){
        /*this first part is ok*/ 
        traits rcvd_traits[num_rcvd_traits];
        MPI_Recv(&amp;num_rcvd_traits, 1, MPI_INT, 0, org, parallel_2, &amp;status);
        MPI_Recv(&amp;rcvd_traits, 1, mpi_trait, 0, org, parallel_3, &amp;status);
  
        std::vector&lt;NEAT::Trait*&gt; gen_traits;
        for(int id = 0; id &lt; num_rcvd_traits; id++){
          traits p_trait = rcvd_traits[id];
          NEAT::Trait* build_trait = new NEAT::Trait(p_trait.trait_id, ....
        }
        /*INCLUDING THIS ADDITIONAL PART LEADS TO A CRASH*/ 
        int num_rcvd_nodes;
        nodes rcvd_nodes[num_rcvd_nodes];
        MPI_Recv(&amp;num_rcvd_nodes, 1, MPI_INT, 0, org, parallel_4, &amp;status);
        MPI_Recv(&amp;rcvd_nodes, 1, mpi_node, 0, org, parallel_5, &amp;status);
  
        std::vector&lt;NEAT::NNode*&gt; gen_nodes;
        for(int id = 0; id &lt; num_rcvd_nodes; id++){
          nodes p_node = rcvd_nodes[id];
          NEAT::NNode* build_node = new NEAT::NNode(p_node.trait_id, p_node.type, p_node.gen_node_label, p_node.ftype, gen_traits);
          gen_nodes.push_back(build_node);
        } 
      }
      std::cout &lt;&lt; &quot;finished &quot; &lt;&lt; std::endl;
  }   
  
  MPI_Finalize();
  </code></pre>
  <p>I get the error:</p>
  <pre><code>===================================================================================
  =   BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
  =   PID 124551 RUNNING AT joachim-X399-AORUS-PRO
  =   EXIT CODE: 139
  =   CLEANING UP REMAINING PROCESSES
  =   YOU CAN IGNORE THE BELOW CLEANUP MESSAGES
  ===================================================================================
  YOUR APPLICATION TERMINATED WITH THE EXIT STRING: Segmentation fault (signal 11)
  This typically refers to a problem with your application.
  </code></pre>
  <p>I am inspiring myself from this toy example:</p>
  <pre><code>int rank, com, num_orgs;
  MPI_Init(NULL, NULL);
  MPI_Status status;
  MPI_Comm parallel_0 = MPI_COMM_WORLD;
  MPI_Comm_rank(parallel_0, &amp;rank);
  MPI_Comm_size(parallel_0, &amp;com);
  MPI_Request reqs[4000];
  
  if(rank==0){
  
    for(int r=1; r &lt; com; r++){
  
      for(int q=0; q &lt; 100; q++){
  
        MPI_Send(&amp;r, 1, MPI_INT, r, q, parallel_0);//, &amp;reqs[r*(q+1)]);
  
      }
    }
  }
  
  if(rank!=0){
    for(int q=0; q &lt; 100; q++){
      int rcvd;
      MPI_Recv(&amp;rcvd, 1, MPI_INT, 0, q, MPI_COMM_WORLD, &amp;status);
    }
  }
  
  MPI_Finalize();
  </code></pre>