Description
Write a program in C to perform Matrix Matrix multiplication. The requirements for the program:
-
You read from a file the values for the input matrix, write also the result of the matrix multiplication to a file.
-
Create your own test matrices with float random values range 0-100
-
Do not assume the size of the matrices are squared, matrix may be of any size and shape (for now is OK to assume they do fit in memory)
-
Matrix multiplication can be done very simple as shown in Fig 1, this algorithm is O(n3), and this algorithm is enough for this lab. NOTE: MAKE SURE YOUR ALGORITHM COMPILES AND RUNS ON THE LAB COMPUTERS.
If you are curious and want 10 extra credit points you can also try to implement Strassen algorithm O(n2.807) , although to really see the speed up using Strassen your matrix must be at least n>100, these algorithm appears in several libraries (BLAS, etc).
Matrix multiplication is still an area of research, most important problems do require multiplication -linear transformations for image/video processing, solving systems of linear equations, rank algorithms,…- of huge matrices (don’t even fit in memory) and getting an algorithm that perform faster is paramount.
for (row=0; row<Hight; row++){ for(col<0; col<Width; col++) {
for(k=0; k<Width; k++){ mm[row*Width+col]+= m1[K*Width+col]*m2[row*Width+k];
}
}
}
Where first matrix is rows1, cols1 columns and second matrix is rows2 rows and cols2 columns
Fig 1. Matrix Multiplication