title: MPI directive for serial run
body: <p>I added a piece of code to an open source software. My code reads data from a file, copies the data to an std::vector (using push_back) and later uses that vector for some applications. The code works when I run it in serial, however, in parallel I get the following error:</p>
  
  <p>mpirun noticed that process rank 0 with PID 27564 on node alpha exited on signal 11 (Segmentation fault)</p>
  
  <p>How can I make MPI to only run the part of the code I added in serial and the rest in parallel? I tried the following but I get the same error.</p>
  
  <p>Update: I used <code>std::cout</code> to find out where exactly the code breaks. It turned out when I use the updated value of "normalValue" I get the error.</p>
  
  <pre><code>#ifdef HAVE_MPI
  
  MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank)
  
  #else
  
  rank = MASTER_NODE;
  
  #endif
  
  if ( rank == MASTER_NODE){
  double temp_x=0;
  double temp_y=0;
  double temp_z=0;
  double temp_v=0;
  
  std::ifstream file;
  //x,y,z,v are the data members of the class declared in the header file
  //...
  
     for (i = 0; i &lt; n; i++){
      normalValue+=Dir[i]*Dir[i];
      }
  
      for (i = 0; i &lt; n; i++){
      Dir[i]/=normalValue;// **This is where the I get the error. The problem is related to "normalValue". I get the same error even if I try to use std::cout&lt;&lt;normalValue&lt;&lt;std::endl**
      }
  
  
  while (file.good())
  {
  
      file &gt;&gt; temp_x &gt;&gt; temp_y &gt;&gt; temp_z&gt;&gt; temp_v;
      x.push_back(temp_x);
      y.push_back(temp_y)
      z.push_back(temp_z);
      v.push_back(temp_v);
  }
  </code></pre>
  
  <p>Thanks.</p>