title: segmentation fault during push_back
body: <p>I'm getting a very weird segmentation fault on the following loop.
  The goal is to have each processor do some checks of x/y points which are stored on the following vectors</p>
  
  <p>Just to clarify: This is a multi-processor code not multi thread. This is how I'm getting the rank:</p>
  
  <pre><code> int my_rank = Utilities::MPI::this_mpi_process(mpi_communicator); 
  
   std::vector&lt;std::vector&lt;double&gt; &gt; Xcoord(n_proc);
   std::vector&lt;std::vector&lt;double&gt; &gt; Ycoord(n_proc);
  </code></pre>
  
  <p>The Xcoord[i] is a vector of x coordinates that come from the i processor and the current processor will do some checks on them, which I'm not including them below:</p>
  
  <p>The code loops through the n processors, first check if it has any information about the paarticular point, and if yes, saves the id of the point and the id of the processor.  </p>
  
  <pre><code>std::vector&lt;std::vector&lt;int&gt; &gt; which_point(n_proc);
  std::vector&lt;std::vector&lt;int&gt; &gt; which_proc(n_proc);
  for (int i = 0; i &lt; n_proc; ++i){
       if (i == my_rank) continue;
       for (unsigned int j = 0; j &lt; Xcoord[i].size(); ++j){
           bool yit = getYiterator(yxmap, Ycoord[i][j], itY);
           if (yit){
                bool xit = getXiterator(itY-&gt;second, Xcoord[i][j], itX);
                if (xit){
                      itZ = itX-&gt;second.zmap.begin();
                      for (; itZ != itX-&gt;second.zmap.end(); ++itZ){
                          which_point[my_rank].push_back(j);
                          which_proc[my_rank].push_back(i);
                      }
                }
           }
      } 
  }
  </code></pre>
  
  <p>(In the innermost loop the itX->second.zmap.size() is 3)</p>
  
  <p>When I run the code in one processor everything works fine.</p>
  
  <p>When I do so with 4 processors I'm getting segmentation faults.</p>
  
  <p>If I remove one of the two lines  </p>
  
  <pre><code>which_proc[my_rank].push_back(i); or 
  which_point[my_rank].push_back(j); 
  </code></pre>
  
  <p>the code works even with 4 processors. </p>
  
  <p>I've also noticed that the segmentation fault is always associated with rank 2. So if I set the condition if (my_rank != 2) in front of one of the two above lines the code works in 4 processors.</p>
  
  <p>I've seen few posts on this issue but in most cases the errors occurred from empty pointers passing to push_back().</p>
  
  <p>Here I'm pushing back just an integer number, which to me obviously exists when it's pushed to a vector.</p>
  
  <p>Any idea how I could catch this error??</p>
  
  <p>Thank you</p>