Question: Question: We want you to write a multi-thread program in C to perform a simple matrix operation. The requirement is very simple; your program should

Question: We want you to write a multi-thread program in C to perform 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 sections (northwest, northeast, southwest, southeast). 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. To get the final result in your program, each of the worker threads results should be combined (added together). 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:

Question: We want you to write a multi-thread program in C to

56 99 23 21 43 126 841 67 876 0 9 100 999 86 22

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!