Given two numerical matrices (which is row-column arrangements of numbers) A and B, where matrix A contains m rows and n columns and matrix B contains k rows and n columns, the row-major dot product of A and B is defined as a matrix P, where P contains m rows and k columns. Entries in matrix P for row i and column j (the cell (i, j)) is the dot product of ith row vector from A and jth row vector from B. For example,
Multi-threaded implementation of the above problem: In this problem, you are required to write a multi-threaded program to find the row-major dot product of two matrices. The following provides a design guideline:
1. Calculate each cell of the product matrix P in a separate worker thread. This will involve determining the dimension of the product matrix. The number of worker threads is same as number of cells in the product matrix.
2. The main (or, parent) thread will initialize the matrices A and B and allocate space to hold the matrix P. Ideally, these matrices should be declared as global data so that each worker thread has access to these matrices.
3. The parent thread will create required number of worker threads. Each worker thread is responsible for calculating one cell value of the product matrix. For example, a worker thread responsible for cell (i, j) of the product matrix is passed the row i from first matrix and row j from the second matrix to calculate the dot product.
4. Once all worker threads have completed, the main thread will output the product matrix P. This requires
the main thread to wait for all worker threads to finish before it can output the value of the matrix
product. [Hint: you may check use of join() or yield() to make the main thread waiting.]
Get Free Quote!
373 Experts Online