title: C# Optimization of nested For loops
body: <p>I am trying to improve my code's execution speed. Through the C#.NET Diagnostic tools I found that the below piece of code is slowing down my program significantly as I loop through it 10,000 times. I would like input on optimization for this part of code.</p>
  
  <pre><code>long length = Random_Vector_Size;
  
  Parallel.ForEach(Partitioner.Create(0, length), (range) =&gt;
  {
        for (q = 1; q &lt;= Random_Vector_Size; q++)
        {
            U[q - 1] = MathNet.Numerics.Distributions.Normal.InvCDF(0.00, 1.00, instance.genrand_real3());
        }
  });
  
  
  for (p = 1; p &lt;= Random_Vector_Size; p++)
  {
      C[p - 1] = 0;
      Parallel.ForEach(Partitioner.Create(0, length), (range) =&gt;
      {
          for (q = 1; q &lt;= Random_Vector_Size; q++)
          {
              C[p - 1] += M[p - 1][q - 1] * U[q - 1];
          }
      });
  }
  </code></pre>