Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #define TILE _ SIZE 1 6 #define UNROLL _ FACTOR 8 void matrix _ multiplication ( int * A , int * B
#include #include #define TILESIZE #define UNROLLFACTOR void matrixmultiplicationint A int B int C int N Initialize result matrix C to for int i ; i N N; i Ci; Iterate over the tiles for int i ; i N; i TILESIZE for int j ; j N; j TILESIZE for int k ; k N; k TILESIZE Compute the block submatrix for int ii i; ii i TILESIZE && ii N; ii for int jj j; jj j TILESIZE && jj N; jj int sum ; int kk; for kk k; kk k TILESIZE && kk UNROLLFACTOR N; kk UNROLLFACTOR Prefetching next elements builtinprefetch&Aii N kk UNROLLFACTOR; builtinprefetch&Bkk UNROLLFACTOR N jj; Loop unrolling sum Aii N kk Bkk N jj; sum Aii N kk Bkk N jj; sum Aii N kk Bkk N jj; sum Aii N kk Bkk N jj; sum Aii N kk Bkk N jj; sum Aii N kk Bkk N jj; sum Aii N kk Bkk N jj; sum Aii N kk Bkk N jj; Handle the remaining elements for ; kk k TILESIZE && kk N; kk sum Aii N kk Bkk N jj; Cii N jj sum; can sopmebody modify this withoput changing its functionality
#include
#include
#define TILESIZE
#define UNROLLFACTOR
void matrixmultiplicationint A int B int C int N
Initialize result matrix C to
for int i ; i N N; i
Ci;
Iterate over the tiles
for int i ; i N; i TILESIZE
for int j ; j N; j TILESIZE
for int k ; k N; k TILESIZE
Compute the block submatrix
for int ii i; ii i TILESIZE && ii N; ii
for int jj j; jj j TILESIZE && jj N; jj
int sum ;
int kk;
for kk k; kk k TILESIZE && kk UNROLLFACTOR N; kk UNROLLFACTOR
Prefetching next elements
builtinprefetch&Aii N kk UNROLLFACTOR;
builtinprefetch&Bkk UNROLLFACTOR N jj;
Loop unrolling
sum Aii N kk Bkk N jj;
sum Aii N kk Bkk N jj;
sum Aii N kk Bkk N jj;
sum Aii N kk Bkk N jj;
sum Aii N kk Bkk N jj;
sum Aii N kk Bkk N jj;
sum Aii N kk Bkk N jj;
sum Aii N kk Bkk N jj;
Handle the remaining elements
for ; kk k TILESIZE && kk N; kk
sum Aii N kk Bkk N jj;
Cii N jj sum;
can sopmebody modify this withoput changing its functionality
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started