title: Why parallel For loop in C# takes more time than simple For loop?
body: <p>I have a CFD (Computational fluid dynamics ) in c# which takes too much time to calculate results. For improving my code, I started to learn TPL and using parallel codes. For the loops that order is not important I can use TPL and for the loops with order the PLINQ is the only way.
  Am I correct?</p>
  
  <p>As the first step, I changed For loops to Parallel.For and interestingly found out that run time increased !</p>
  
  <p>Sample of my code:</p>
  
  <pre><code>for (int i = 0; i &lt; nx; i++)
  {
      for (int j = 0; j &lt; ny; j++)
      {
          if (!Cells[i, j, 0].IsVirtual)
          {
              // calculate x velocity
              // calculate y velocity
  
          }
       }
   }
  </code></pre>
  
  <p>With parallel tasks:</p>
  
  <pre><code>Parallel.for (0,nx, i =&gt;
  {
      for (int j = 0; j &lt; ny; j++)
      {
          if (!Cells[i, j, 0].IsVirtual)
          {
              // calculate x velocity
              // calculate y velocity
          }
      }
  });
  </code></pre>
  
  <p><strong><em>How can I speed up my code?</em></strong> 
  Each my outputs takes 10 min which is very long time and I ned at least 5000 outputs.</p>