Cache friendly method to multiply two matrices

前端 未结 2 1595
暗喜
暗喜 2020-12-18 03:15

I intend to multiply 2 matrices using the cache-friendly method ( that would lead to less number of misses)

I found out that this can be done with a cache friendly t

2条回答
  •  心在旅途
    2020-12-18 04:11

    @Cesar's answer is not correct. For example, the inner loop

    for (int k = 0; k < n; k++)
       s += a[i,k] * Bcolj[k];
    

    goes through the i-th column of a.

    The following code should ensure we always visit data row by row.

    void multiply(const double (&a)[I][K], 
                  const double (&b)[K][J], 
                  double (&c)[I][J]) 
    {
        for (int j=0; j

提交回复
热议问题