Question: This is a C++ program of calculating matrix i computed each number in the output matrix with a separate thread . correct this program without

This is a C++ program of calculating matrix

i computed each number in the output matrix with a separate thread .

correct this program without deleting the thread lines and compute the program and be sure that the program works correctly .

#include #include #include #define Nthreads 10 void* func(void* ) { // detach the current thread // from the calling thread pthread_detach(pthread_self()); pthread_t thread1,thread2; char *message1 = "thread 1"; char *message2 = "thread 2"; int iret1, iret2; printf("Inside the thread "); // exit the current thread pthread_exit(NULL); } void fun() { pthread_t ptid; pthread_create(&ptid, NULL, &func, NULL); // replace print_message_function with the name of the function you want to call iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread1, NULL, print_message_function, (void*) message2); pthread_join( thread1, NULL); pthread_join( thread2, NULL); pthread_t thread_id[Nthreads]; int i, j; for (i=0; i < Nthreads; i++) { pthread_create( &thread_id[i], NULL, thread_function, NULL ); } for (j=0; j < Nthreads; j++) pthread_join ( thread_id[j], NULL); printf("final counter value: %d ", counter); printf("thread 1 returns: %d " ,iret1); printf("thread 2 returns: %d ", iret2); exit(0); } // Declare variables int c, d, p, q, m, n, k, tot = 0; int fst[10][10], sec[10][10], mul[10][10], transpose[10][10]; int main() { fun()

printf(" Please insert the number of rows and columns for first matrix "); scanf("%d%d", &m, &n); // Read in the elements of the first matrix printf(" Insert your matrix elements : "); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &fst[c][d]); // Read in the number of rows and columns for the second matrix printf(" Please insert the number of rows and columns for second matrix "); scanf(" %d %d", &p, &q); // Check if the matrices can be multiplied if (n != p) printf(" Your given matrices cannot be multiplied with each other. "); else { // Read in the elements of the second matrix printf(" Insert your elements for second matrix "); for (c = 0; c < p; c++) for (d = 0; d < q;

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!