Question: ( 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 C++ code using pthread library functions for thread management and mutual exclusion for the application in vector-vector (i.e.,1D-1D array) multiplication
(dot product) and matrix-matrix multiplication. The sizes of matrices and vectors (1D arrays) considere will of the order of at least 100.
We need to write two C++ programs for the inter-related problems.
The first program should first initialize two 1D arrays x and y, each of size 100, with some random integers (using expressions like rand()%10). The program then computes the dot product (or inner
product) of x and y(each of size N elements) using the following formula:
Sum =i=0i=N-1x[i]**y[i]
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 2; 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 0 to (N/2)-1, and the second thread should do the summation of the
product for indices (N/2) to N-1. Same idea should be extendable to more than 2 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 B, each of size NxN. We need to compute
matrix C, such that C=A.B, where the element of C at row i and column j is given by
C[i][j]=k=0k=N-1A[i][k]**B[k][j]
for 0iN-1, and 0jN-1.
One possibility is to use one thread for the computation of only one element in C; however, you need to explore other possibilities.
General:
Your programs should work for any number of user-defined threads (using #define directive).
The size of the 1D arrays and matrices should also be user-defined (using #define directive).
Make use of an array of threads, and use pthread_create() 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.
 (Operating systems - linux) The purpose of this mini project to

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!