title: openMP - parallelization with for loop and private
body: <p>I wrote a function to evaluate a given function at points in a set (set_). Code with no parallelization is like that: </p>
  
  <pre><code>void Method::evaluateSet(double* funcEvals_, double** set_)
  {
      for(int j= 0;j&lt;m_npts;j++)
      {
          if(!(isInsideConstraints(set_[j])) || qIsNaN(funcEvals_[j]) || !qIsFinite(funcEvals_[j])) 
          {
              funcEvals_[j] = DBL_MAX;                     
          }
          else
          {
              solverInput input_(m_input);
              input_.setFunParameters(simplex_[j]);
              funcEvals_[j]=input_.apply(simplex_[j]);
          }
      }           
  }
  </code></pre>
  
  <p>and this is working properly. </p>
  
  <p>I then parallelize using openMP, with a parallel construct, and a private copy of the variable set_ for each thread. Loop is </p>
  
  <pre><code>#pragma omp parallel for  private (set_)
  for(int j= 0;j&lt;m_npts;j++)
  {
      if(!(isInsideConstraints(set_[j])) || qIsNaN(funcEvals_[j]) || !qIsFinite(funcEvals_[j])) 
      {
          funcEvals_[j] = DBL_MAX;
      }
      else
      {
          solverInput input_(m_input);
          input_.setFunParameters(set_[j]);
          funcEvals_[j]=input_.apply(set_[j]);
      }
  }
  #pragma omp barrier
  </code></pre>
  
  <p>It crashes, and error occurs at if evaluation, with <code>set_ is being used without been initialized</code>. I don't understand. Since I set the <code>set_</code> variable private, shouldn't there be a copy of original <code>set_</code> in each thread?</p>
  
  <p>What is wrong with the code and how to improve?</p>
  
  <p>Thanks and regards.</p>