c++ - Block Matrix Multiplication -


i want perform block matrix multiplication(divide matirix multiple sxs matrices , multiply corresponding blocks). have written code following sample code of architecture book of hennesy:

for(int jj=0;jj<=(n/s);jj += s){             for(int kk=1;kk<=(n/s);kk += s){                     for(int i=1;i<=(n/s);i++){                             for(int j = jj; j<=((jj+s-1)>(n/s)?(n/s):(jj+s-1)); j++){                                     temp = 0;                                     for(int k = kk; k<=((kk+s-1)>(n/s)?(n/s):(kk+s-1)); k++){                                             temp += b[i][k]*a[k][j];                                     }                                     c[j][i] += temp;                             }                     }             }     }   

here, nxn size of original matrix. a, b matrices of same size. dividing a,b matrices blocks of size sxs. in program, have given block size 4. put elements of a, b 5, constant , n = 1000. however, getting wrong values in result. doing wrong here? stuck on past 2 hours. can guys please if possible. reference code in book this:

for (jj = 0; jj <= size; jj += n) {     (kk = 1; kk <= size; kk += n) {         (i = 1; <= size; i++) {             (j = jj; j <= findmin(jj+n-1, size); j++) {                 temp = 0;                 (k = kk; k <= findmin(kk+n-1, size); k++) {                     temp += b[i][k] * a[j][k];                 }                 c[j][i] += temp;             }         }      } }   

here, s=n , size = n/s

for(int jj=0;jj<n;jj+= s){         for(int kk=0;kk<n;kk+= s){                 for(int i=0;i<n;i++){                         for(int j = jj; j<((jj+s)>n?n:(jj+s)); j++){                                 temp = 0;                                 for(int k = kk; k<((kk+s)>n?n:(kk+s)); k++){                                         temp += a[i][k]*b[k][j];                                 }                                 c[i][j] += temp;                         }                 }         } } 

axb size n


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -