Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are talking about use of Caches then you might want to do something called loop tiling. You break the loop into tiles such that inner part of the loop gets stored inside cache (which is quite large these days). So your loop will turn into something like (if you are passing the matrices into a function using pointers ) </p> <pre><code>for(j=0;j&lt;size;j+=t) for(k=0;k&lt;size;k+=t) for(i=0;i&lt;size;i+=t) for(ii=i;ii&lt;MIN(i+t,size);ii++) for(jj=j;jj&lt;MIN(j+t,size);jj++) { var=*(c+ii * size+jj); //Var is a scalar variable for(kk=k;kk&lt;MIN(k+t,size);kk++) { var = var + *(a+ii *size +kk) * *(bt +jj * size+ kk); } *(c+ii *size +jj) = var; } </code></pre> <p>The value of t varies depending on the speedup that you get. It can t = 64,128,256 and so on. There are many other techniques that you can use here. Loop tiling is just once technique to utilize the cache efficiently.Further, you can transpose the B matrix before you send to the multiplication function. That way you will get a linear access of elements of matrix B. To explain you more Consider </p> <pre><code> A -------- and B | | | | -------- | | | | -------- | | | | -------- | | | | </code></pre> <p>Here, you will always consider, to multiply the first row of A with first column of B.And since you are using <code>C</code> I believe, CPU requires extra efforts to read in the all the columns of matrix B one by one inside the memory. To ease up these efforts, you can transpose the matrix and get the rows of matrix <code>B'</code> (which are nothing but columns of <code>B</code> essentially) and use loop tiling to cache the maximum amount of elements for multiplication.Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload