Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is c++ program of multiplying matrix .. also i computed each number in the output matrix with a separate thread . cab you correct

This is c++ program of multiplying matrix .. also i computed each number in the output matrix with a separate thread .

cab you correct this program without deleting the lines of thread functions.

#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

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

Step: 3

blur-text-image

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

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions