Assignment PDF
Assignment PDF
Given
MatrixA of size N * M
MatrixB of size M * L
The result of multiplying them is a matrix of size N *L
Rule of Multiplication:
Example:
A
1
2
3
1
2
3
B
1
2
3
1
2
3
3X4
5
5
5
5
Result
1
1
1
1
4X2
20 4
40 8
60 12
3X2
Parallelization
There are several ways to implement matrix multiplication as parallel program. One way is:
Divide rows of result matrix on the other processes.
o Number of rows to be calculated by each process = N/ (P-1).
For simplicity, if N%(p-1)>0 then the last process will take remaining rows in addition to
its part of rows.
o
To calculate rows i to j in matrixResult, a slave process will need i to j rows of matrixA and all
columns of matrix (i.e. all matrixB).
Steps:
-
Note: if dimensions were variable (user input) and used dynamic allocation then the matrices will be
sent/received row by row as the memory wont be contiguous. So it is better in lab to apply static
allocation and who finishes early starts in make code dynamic.
Page 2 of 2