Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( Operating systems - linux ) The purpose of this mini project to write C + + code using pthread library functions for thread management
Operating systems linux
The purpose of this mini project to write code using pthread library functions for thread management and mutual exclusion for the application in vectorvector ieDD array multiplication
dot product and matrixmatrix multiplication. The sizes of matrices and vectors D arrays considere will of the order of at least
We need to write two programs for the interrelated problems.
The first program should first initialize two D arrays and each of size with some random integers using expressions like rand The program then computes the dot product or inner
product of and each of size elements using the following formula:
Sum
Your program MUST use a multithreaded approach to divide the computational task for Sum. The number of threads used in addition to the main thread should be for example, declared as #define THREADS ; For example, if we use two threads in addition to the main thread then first thread should do the summation of the product for indices to N and the second thread should do the summation of the
product for indices N to Same idea should be extendable to more than threads. The individual partial sums generated by threads should be then added together to compute the final Sum. We also need
to ensure mutual exclusion when using the shared variables.
The second program uses ideas generated from the first program above in order to compute efficientlythe result of the multiplication of two square matrices A and each of size We need to compute
matrix such that where the element of at row i and column is given by
for and
One possibility is to use one thread for the computation of only one element in ; however, you need to explore other possibilities.
General:
Your programs should work for any number of userdefined threads using #define directive
The size of the D arrays and matrices should also be userdefined using #define directive
Make use of an array of threads, and use pthreadcreate in a loop to create multiple threads.
Check the correctness of your program using smaller dimensions for vectors and matrices.
Research about making your program time efficient and implement those ideas in your program.
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