title: Why OpenMP version is slower?
body: <p>I am experimenting with OpenMP. I wrote some code to check its performance. On a 4-core single Intel CPU with Kubuntu 11.04, the following program compiled with OpenMP is around 20 times slower than the program compiled without OpenMP. Why?</p>
  
  <p>I compiled it by g++ -g -O2 -funroll-loops -fomit-frame-pointer -march=native -fopenmp</p>
  
  <pre><code>#include &lt;math.h&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main ()
  {
    long double i=0;
    long double k=0.7;
  
    #pragma omp parallel for reduction(+:i)
    for(int t=1; t&lt;300000000; t++){       
      for(int n=1; n&lt;16; n++){
        i=i+pow(k,n);
      }
    }
  
    cout &lt;&lt; i&lt;&lt;"\t";
    return 0;
  }
  </code></pre>