Question: this is my phase 1 code : #include #define M 1 _ ROWS 7 #define M 1 _ COLS 7 #define M 2 _ ROWS

this is my phase 1 code :
#include
#define M1_ROWS 7
#define M1_COLS 7
#define M2_ROWS 4
#define M2_COLS 4
// Function to multiply matrices based on the given criteria
void multiplyMatrices(int m1[M1_ROWS][M1_COLS], int m2[M2_ROWS][M2_COLS], int result[M1_ROWS][M1_COLS]){
int i, j, k, l;
for (i =0; i M1_ROWS; ++i){
for (j =0; j M1_COLS; ++j){
result[i][j]=0; // Initializing result matrix element to 0
for (k =0; k M2_ROWS; ++k){
for (l =0; l M2_COLS; ++l){
// Multiplying corresponding elements and summing the result
if (i + k M1_ROWS && j + l M1_COLS){
result[i][j]+= m1[i + k][j + l]* m2[k][l];
}
}
}
}
}
}
// Function to display the matrix
void displayMatrix(int matrix[M1_ROWS][M1_COLS]){
int i, j;
for (i =0; i M1_ROWS; ++i){
for (j =0; j M1_COLS; ++j){
printf("%d\t", matrix[i][j]);
}
printf("
");
}
}
int main(){
int m1[M1_ROWS][M1_COLS]={
{17,11,17,1,14,17,16},
{19,20,3,17,4,14,16},
{3,20,9,19,15,7,4},
{19,4,19,14,1,20,10},
{13,20,16,16,6,1,9},
{2,20,20,15,1,9,13},
{6,10,14,8,2,8,15}
};
int m2[M2_ROWS][M2_COLS]={
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}
};
int result[M1_ROWS][M1_COLS];
multiplyMatrices(m1, m2, result);
// Displaying the result matrix
displayMatrix(result);
return 0;
}
my phase 2 is telling me to :
You will implement a multithreaded version of your work in phase 1 using POSIX Threads.
You will compute each number in the output matrix with a separate thread.
You will display the contents of the output matrix whenever a thread sets a value in the output matrix.
Initially, all the values in the output matrix will be equal to -1.You will implement a multithreaded version of your work in phase 1 using POSIX Threads.
You will compute each number in the output matrix with a separate thread.
You will display the contents of the output matrix whenever a thread sets a value in the
output matrix.
Initially, all the values in the output matrix will be equal to -1.
can you help me with phase 2?
 this is my phase 1 code : #include #define M1_ROWS 7

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 Databases Questions!