Optimized matrix multiplication in C

后端 未结 13 2391
一整个雨季
一整个雨季 2020-11-30 01:44

I\'m trying to compare different methods for matrix multiplication. The first one is normal method:

do
{
    for (j = 0; j < i; j++)
    {
        for (k          


        
13条回答
  •  -上瘾入骨i
    2020-11-30 02:23

    ATTENTION: You have a BUG in your second implementation

    for (f = 0; f < i; f++) {
        for (co = 0; co < i; co++) {
            MatrixB[f][co] = MatrixB[co][f];
        }
    }
    

    When you do f=0, c=1

            MatrixB[0][1] = MatrixB[1][0];
    

    you overwrite MatrixB[0][1] and lose that value! When the loop gets to f=1, c=0

            MatrixB[1][0] = MatrixB[0][1];
    

    the value copied is the same that was already there.

提交回复
热议问题