Write a multi-thread program to handle two matrices, A and B. Randomly generate the content of matrix A and B withi spec

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a multi-thread program to handle two matrices, A and B. Randomly generate the content of matrix A and B withi spec

Post by answerhappygod »

Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 1
Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 1 (53.38 KiB) Viewed 41 times
Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 2
Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 2 (43.22 KiB) Viewed 41 times
Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 3
Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 3 (25.33 KiB) Viewed 41 times
Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 4
Write A Multi Thread Program To Handle Two Matrices A And B Randomly Generate The Content Of Matrix A And B Withi Spec 4 (39.22 KiB) Viewed 41 times
Write a multi-thread program to handle two matrices, A and B. Randomly generate the content of matrix A and B withi specified dimension provided as two command arguments. Dimension of A and B must be the same. Then create three threads: a. one thread will transpose the A and B b. one thread will calculate addition of two matrices as C= A + B c. one thread will calculate subtraction of two matrices as C-A-B Also print out the results for each thread. Remember to allocate space for C and the transposed A and B. The following image shows a transposed matrix. A = e #include #include 2x3 #include #include Sample Array Statistics Solution that we discussed in class: //From OS concepts of John Wiley & Sons //please run this program as ./main 3567246 // It is up to you as what integer array to supply as the arguments. /* the list of integers */ int "list; int maximum; int minimum; AT= b /* the threads will set these values */ double average: a d void *calculate_average(void *param); void "calculate maximum(void *param); 3x2
void *calculate_average(void *param); void *calculate maximum(void *param); void *calculate_minimum(void *param); int main(int argc, char "argv[]) { int i; int num_of_args = argc-1; pthread_t tid_1; pthread_t tid_2; pthread_t tid_3; /* allocate memory to hold array of integers */ list = malloc(sizeof(int) num_of_args); for (i = 0; i < num_of_args; i++) list = atoi(argv[i+1]); /* create the threads "/ pthread_create(&tid_1, pthread_create(&tid_2, 0, calculate_average, &num_of_args); 0, calculate_maximum, &num_of_args); pthread_create(&tid_3, 0, calculate_minimum, &num_of_args); /* wait for the threads to exit */ pthread_join(tid_1, NULL); pthread_join(tid_2, NULL); pthread_join(tid_3, NULL); printf("The average is %f\n", average); printf("The maximum is %d\n", maximum); printf("The minimum is %d\n", minimum); return 0; } void *calculate_average(void *param) { int count = "(int *)param;
S int count= "(int *)param; int i, total = 0; printf("count=%d\n",count); for (i = 0; i < count; i++) printf("%d\n",list); for (i = 0; i < count; i++) total += list: average = total / count; pthread_exit(0); } void 'calculate maximum(void *param) { int count = "(int *)param; int i; maximum list[0]; for (i = 1; i < count; i++) if (list> maximum) maximum = list; pthread_exit(0); E } void "calculate_minimum(void "param) { int count(int *)param; int i; minimum list[0]; for (i=1;i< count; i++) if (list< minimum) minimum = list; = Ma
pthread_exit(0); } void *calculate_maximum(void *param) int count = "(int *)param; int i; maximum = list[0]; for (i = 1; i < count; i++) if (list> maximum) maximum = list; pthread_exit(0); } void *calculate_minimum(void *param) { int count = *(int *)param; int i; minimum list[0]; for (i = 1; i < count; i++) if (list < minimum) minimum = list[i]; pthread_exit(0); = } Also available here: https://replit.com/@zhumi/Multithread-Statistics#main.c
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply