Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.
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;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

Students also viewed these Databases questions

Question

What do you see as your biggest strength/weakness?

Answered: 1 week ago

Question

In what ways are you similar to your closest friends?

Answered: 1 week ago