Question
Expert I need complete working code Output By eliminating the errors. This Below Code written in c language has Some errors. The Expert should eliminate
Expert I need complete working code Output By eliminating the errors. This Below Code written in c language has Some errors.
The Expert should eliminate all these errors and provide me the working code but without any errors .
I need To run this on gcc compiler.
#include
// Multiplication of a Matrix void* multiplication(void* arg) { int i, j ,sum ,k; int core = (int)arg; // Each thread computes 1/3th of matrix addition for (i = core * MAX / 3; i < (core + 1) * MAX / 3; i++) { for (j = 0; j < MAX; j++) { sum=0; for (k=0 ; k< MAX; k++ ) sum=sum + mat_A[i][k] * mat_B[k][j]; mult[i][j] = sum; } } }
// Driver Code int main() { int i, j, step = 0; // Generating random values in mat_A and mat_B for (i = 0; i < MAX; i++) { for (j = 0; j < MAX; j++) { mat_A[i][j] = rand() % 10; mat_B[i][j] = rand() % 10; } } // Displaying mat_A printf(" Matrix A: "); for (i = 0; i < MAX; i++) { for (j = 0; j < MAX; j++) { printf("%d ", mat_A[i][j]); } printf(" "); } // Displaying mat_B printf(" Matrix B: "); for (i = 0; i < MAX; i++) { for (j = 0; j < MAX; j++) { printf("%d ", mat_B[i][j]); } printf(" "); } // Creating threads equal // to core size and compute matrix row for (i = 0; i < CORE; i++) { pthread_create(&thread[i], NULL, &addition, (void*)step); pthread_create(&thread[i + CORE], NULL, &subtraction, (void*)step); pthread_create(&thread[i], NULL, &multiplication, (void*)step); step++; } // Waiting for join threads after compute for (i = 0; i < CORE * 2; i++) { pthread_join(thread[i], NULL); } // Display Addition of mat_A and mat_B printf(" Sum of Matrix A and B: "); for (i = 0; i < MAX; i++) { for (j = 0; j < MAX; j++) { printf("%d ", sum[i][j]); } printf(" "); } // Display Subtraction of mat_A and mat_B printf(" Subtraction of Matrix A and B: "); for (i = 0; i < MAX; i++) { for (j = 0; j < MAX; j++) { printf("%d ", sub[i][j]); } printf(" "); } // Display Multiplication of mat_A and mat_B printf(" Multiplication of Matrix A and B: "); for (i = 0; i < MAX; i++) { for (j = 0; j < MAX; j++) { printf("%d ", mult[i][j]); } printf(" "); } return 0; }
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