Question: A 2 2 - WAP to multiply two matrices using multiple threads in c language Pre - requisites: Knowledge about multi - thread process, How
A WAP to multiply two matrices using multiple threads in c language
Prerequisites:
Knowledge about multithread process, How to read and understand man pages
Good knowledge about pthread library functions.
Multiplication of two matrices.
Dynamic allocation for D array.
Objective:
To understand working and flow of multithread programs.
Requirements:
Create three local matrices, M MxN M NxP and Result MxP M columns M rows where M N & P values are provided by user.
In case M columns M rows print error message to user.
Create all matrices using dynamic allocation.
Use structure to pass arguments to threads sample structure.
typedef struct threaddata
short mrow;
short mcol;
short mcol;
int matrix;
int matrix;
int result;
short currow;
Threaddatat;
Each thread will calculate and store single row in result. So number of threads equals number of rows in M
Eg: M M
Thread : M row x M col col col
xxxxxxxxx
Thread : M row x M col col col
xxxxxxxxx
Thread : M row x M col col col
xxxxxxxxx
Dont create any global variables.
Create generic function for matrix dynamic allocation and deallocating.
Sample execution:
matrixmul
Enter M rows and columns
Enter M rows and columns
Enter M values
Enter M values
Result is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
