Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q1 (12,5 points). We want you to write a multithreaded program in C to do some simple matrix arithmetic. The requirement is very simple; your
Q1 (12,5 points). We want you to write a multithreaded program in C to do some simple matrix arithmetic. The requirement is very simple; your program should read a square matrix of some integers from a text file (an example file given below), populate it into a proper data structure, and calculate the sum of all the numbers present in the matrix. But the calculation process should be carried out by 4 different worker threads in parallel. You can think of your matrix equally divided into 4 sections (northwest, northeast, southwest, southeast). You can also assume that the number of rows, hence the number of columns since it is a square matrix, is an integral power of 2. The results of the worker threads should be assembled, i.e. added up, to get the overall result of the program. In the meantime, the main thread should also calculate the same summation, and compare its own results with the assembled results of the worker threads. Finally, it should produce a simple output indicating whether the resulting cooperative calculation by the worker threads is correct, or not. You should take care of any synchronization requirements of the threads, and implement the proper synchronization solution whenever needed. On the other hand, you should not overly constrain the running of your threads by some unnecessary synchronizations. Possible parallelism in the hardware you will use to run your program should be exploited as much as possible. What type of parallelism you employed in your program to get the result? And at which points do you need to synchronize your threads, including the main thread? An example input file for a 4x4 matrix: 23 21 43 126 56 4 1 22 67 876 0 9 99 100 999 86
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