Question
1-We want you to write a multi-theard program in C language to do a simple matrix operation. The requirement is very simple; your program should
1-We want you to write a multi-theard program in C language to do a simple matrix operation. The requirement is very simple; your program should read a square matrix of integers from a text file (here is an example file), place it in an appropriate data structure, and calculate the sum of all the numbers contained in the matrix. However, the calculation must be done in parallel by 4 different worker threads. You can think of your matrix as evenly divided into 4 parts. You can also assume that the number of rows and, since it's a square matrix, the number of columns is an integer power of 2. In order to get the final result in your program, the results of each of the worker threads must be combined , ie aggregated. Meanwhile, the main thread should calculate the same sum and compare its own result with the total result from the threads. Finally, it should produce a simple output that indicates whether the result is correct. You should implement an appropriate synchronization mechanism where necessary. On the other hand, you should not unnecessarily restrict the running of your threads with unnecessary synchronizations. The possible parallelism in the hardware you will use to run your program should be utilized as much as possible. What kind of parallelism did you use in your program to achieve the result? And at what points did you need to synchronize your threads, including the main thread?
Example of input file for a 4x4 matrix: 23 56 67 99 21 4 876 100 43 1 0 999 126 22 9 86
2-Let's say that the slightly changed version of the program given in the 1st question above is very important for a company and is run continuously. The only difference is that the main thread is not expected to check the sum, it just prints the sum resulting from the running of the worker threads. Due to some legal requirements that are beyond your scope and you cannot change, you only have to run one instance of this program at a time. Another run of the app can only be started after the previous run has finished its job. That is, your application is not allowed to run parallel on two or more separate terminals. You can always assume there is some matrix data to process, no shortage of matrix. There are enough matrices to keep your program busy all the time and are waiting on disk. The firm only wants to purchase a dedicated physical (or virtual) server to run this program. You are requested to make a suggestion on the number of cores required in the server to be purchased and the user to kernel thread mapping strategy from the user to be used in the operating system that will run on it. They want the solution to be optimized as much as possible, all purchased CPU cores should be kept as busy as possible. If they are convinced that each CPU will be busy doing useful work throughout the day, they are willing to increase the number of CPU cores. The stage of reading the matrices from the disk will not take much time compared to the calculation phase, as they already have an SSD-type ultra-high-speed disk that they will connect to the server and use. The matrices are huge and doing the calculations will take much more time than reading them from the SSD unit. (You might think that the calculation for this question is a much more comprehensive statistical operation, not simple addition).
a.How many core CPUs would you recommend on a server that will be used to run this application? Why? b.What type of user-to-core thread mapping strategy would you recommend within the operating system to be installed on this server? Why?
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