Matrix Multiplication using Tiling Method

Execution Time for Matrix multiplication can be improved by using a tile method which is based on dividing the matrix/2D array into smaller sub matrices/Tiles and then multiplying each of the tile in manner as shown below:
The 2D arrays must be Square Matrices of same size in order of power of 2.



Implementation in C++:

for(int i_=0;i_<N;i_+=tile) {
for(int j_=0;j_<N;j_+=tile) {
for(int k_=0;k_<N;k_+=tile) {
    for(i=i_; i<i_+tile; ++i){
               for(j=j_; j<j_+tile; ++j){
                          for(k=k_; k<k_+tile; ++k){
                      P[j][i] += A[j][k]*B[k][i];
                  }
              }
      }
      }
      }
}

tile: Tile size could be 2, 4, 8, 16...

Comments

Popular posts from this blog

How to install GEM5 Simulator in ubuntu

Shell Scripting is Fun