title: How to write fast code for matrix multiplication in C++?
body: <p>I wrote some C++ code for matrix multiplication. I used <code>vector&lt;double&gt;</code> to save the matrix entries, and I used a series of 3 nested <code>for</code> loops to calculate the multiplication entry-by-entry. It turns out that this is super slow (for a 900*500 and 500*500 matrix multiplication, it takes about 10 seconds on my macbook air). What is the reason? Did I use a bad representation of matrix or there are big flaws in the code?</p>
  
  <pre><code>    for (int c_b=0;c_b&lt;B.n_c;c_b++)
      {
          vector&lt;double&gt; vtmp(A.n_r);
          for (int r_a=0;r_a&lt;A.n_r;r_a++)
          {
              sum=0;
              for (int i=0;i &lt; A.n_c;i++)
              {
                  sum=sum+A.mat[r_a+i*A.n_r]*B.mat[i+c_b*B.n_r];
              }
              vtmp[r_a]=sum;
          }
          Cvv[c_b]=vtmp;
      }
  </code></pre>
  
  <p>UPDATE: This issue has been resolved by using subroutines in Lapack.</p>