- Work out multiplication compatibility, (m x n) can multiply (n x o) matrices which will yield a (m x o) matrix. That is not really needed here since we are only looking at square matrices which are n x n and thus have the correct dimensions for multiplication.
- Choose block size: b
- Create a new matrix with the dimensions (m x o).
- Traversing the new matrix in a row by row (or column by column) fashion create tuples in batches size b.
Example with b = 2 and m = n = o = 3 and array indices based on one:
1. (1,1) (1,2)
2. (1,3) (2,1)
3. (2,2) (2,3)
4. (3,1) (3,2)
5. (3,3)
- Start a thread for each of the batches. Using
Thread.Start
you will pass the list of tuples to the thread as well as a reference to the the newly created m x o matrix as well as both original matrices in the order left hand side, right hand side. - In the threads work method you'll do the multiplication of row x by column y for each tuple (x, y) of the list you passed to the thread. The resulting scalar is placed into the new matrix at position (x,y).
- In your main program wait for all threads to finish (
Join
). The multiplication result is now in the newly created matrix from step 3.
That is all there is to it really. The multiplication of a row by a column or
matrix multiplication[
^] is straight forward enough so I won't go into that.
Regards,
Manfred