title: Optimising and why openmp is much slower than sequential way?
body: <p>I am a newbie in programming with OpenMp. I wrote a simple c program to multiply matrix with a vector. Unfortunately, by comparing executing time I found that the OpenMP is much slower than the Sequential way.</p>
  
  <p>Here is my code (Here the matrix is N*N int, vector is N int, result is N long long):</p>
  
  <pre><code>#pragma omp parallel for private(i,j) shared(matrix,vector,result,m_size)
  for(i=0;i&lt;m_size;i++)
  {  
    for(j=0;j&lt;m_size;j++)
    {  
      result[i]+=matrix[i][j]*vector[j];
    }
  }
  </code></pre>
  
  <p>And this is the code for sequential way:</p>
  
  <pre><code>for (i=0;i&lt;m_size;i++)
          for(j=0;j&lt;m_size;j++)
              result[i] += matrix[i][j] * vector[j];
  </code></pre>
  
  <p>When I tried these two implementations with a 999x999 matrix and a 999 vector, the execution time is:</p>
  
  <p>Sequential: 5439 ms
  Parallel:   11120 ms</p>
  
  <p>I really cannot understand why OpenMP is much slower than sequential algo (over 2 times slower!) Anyone who can solve my problem?</p>