Question: A 2 2 - WAP to multiply two matrices using multiple threads in c language Pre - requisites: Knowledge about multi - thread process, How

A22- WAP to multiply two matrices using multiple threads in c language
Pre-requisites:
Knowledge about multi-thread process, How to read and understand man pages.
Good knowledge about pthread library functions.
Multiplication of two matrices.
Dynamic allocation for 2D array.
Objective:
To understand working and flow of multithread programs.
Requirements:
1. Create three local matrices, M1 MxN M2 NxP and Result MxP (M1 columns = M2 rows) where M, N & P values are provided by user.
2. In case M1 columns != M2 rows print error message to user.
3. Create all matrices using dynamic allocation.
4. Use structure to pass arguments to threads sample structure.
typedef struct thread_data {
short m1_row;
short m1_col;
short m2_col;
int **matrix1;
int **matrix2;
int **result;
short cur_row;
}Thread_data_t;
5. Each thread will calculate and store single row in result. So number of threads equals number of rows in M1.
Eg: M1=123 M2=111
111222
222333
Thread 1 : M1 row1 x M2 col1, col2, col3
1x1+2x2+3x31x1+2x2+3x31x1+2x2+3x3
141414
Thread 2 : M1 row2 x M2 col1, col2, col
1x1+1x2+1x31x1+1x2+1x31x1+1x2+1x3
666
Thread 3 : M1 row3 x M2 col1, col2, col3
2x1+2x2+2x32x1+2x2+2x32x1+2x2+2x3
1212126.
Don't create any global variables.
7. Create generic function for matrix dynamic allocation and deallocating.
Sample execution: -
1../matrix_mul
Enter M1 rows and columns 33
Enter M2 rows and columns 33
Enter M1 values 123111222
Enter M2 values 123123123
Result is
141414
666
121212

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!