Question
Matrix multiplication theory : Given two matrices, A and B, where matrix A contains m rows and k columns and matrix B contains k rows
Matrix multiplication theory: Given two matrices, A and B, where matrix A contains m rows and k columns and matrix B contains k rows and n columns, the matrix product of A and B is matrix P, where P contains m rows and n columns. Entries in matrix P for row i and column j is the sum of the products of the elements for i throw in matrix A and jth column in matrix B.
Multi-threaded matrix multiplication:
In this problem, you are required to write a multi-threaded program for matrix product. Calculate each cell of the product matrix P in a separate worker thread. This will involve creating m n worker threads. 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. The parent thread will create m n worker threads, passing each worker the values of row i and column j that it uses in calculating the matrix product. Once all worker threads have completed, the main thread will output the product contained in 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. Programming instruction:
your program should read the data from a file. The file name is provided as command-line argument at execution time. The data file format is as follows: first line has 4 integer numbers, separated by single spaces, specifying dimension of two matrices. For example, 3 2 2 3 means matrix A has dimension 3 2 and matrix B has dimension 2 3. Your program should check, at the beginning, whether two matrices are eligible for multiplication (that is, the middle two numbers are equal or not) and indicate it with appropriate message. The program then reads the matrices (see the sample data file MatrixData.txt), completes calculation as specified above, and produces the output on console in a matrix format (standard row-column format). You can assume that the data file will have integer value matrices only. However, the given data file is just a sample. Instructor may test your program using another, but similar, data file where the matrices have larger dimensions.
Important requirement: For each worker thread, display the begin of the thread as Thread i starts calculating.. and then display the value it produces before the thread ends with Thread i returns value
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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