Last week got you back into programming again, with some reviews about basic thread execution. It’s now time for you to design and implement your first Parallel Program to solve the traditional Matrix Multiplication operation.
During the lecture we touched on matrix multiplication as a common example problem for parallel programming. If you need to refresh your brains on how to perform matrix multiplication there are plenty of YouTube video’s out there, but I suggest this one from Khan Academy.
Make sure you are clear on how to perform matrix multiplication before continuing.
Since this is not a course on matrix multiplication, I have provided you with a starting point that performs matrix multiplication using sequential programming. Download the A1_StartingPoint.cpp file from eConestoga and import it into a Visual Studio solution space.
The program has no errors and should compile and execute.
HINT
As you are performing your development, shrink the
size of the arrays down to 10×10 and use the
DisplayArray function to help with debugging.
The first thing you need to think about is your data. As you start designing parallel software you need to evaluate how many threads you will be using, what are the critical sections of the code and are the threads sharing data? Answer the following questions in the provided text boxes:
In order to design a parallel version of this algorithm you will need to design and implement two new functions as follows:
FUNCTION #1: parallel_matrix_multiply()
This function will be called by the main and perform all the logic to break the data into “chunks” for parallel processing.
FUNCTION #2: parallel_helper()
This function will contain the source code each thread is responsible for executing. When designing this code, think about the questions you answered above.
Once you have implemented your parallel code update the main to execute the parallel processing after the sequential processing, timing how long it takes (just like the sequential code). Add the results of the parallel processing to the Final Results and calculate the efficiency of your new code.
HINT: Efficiency = (Sequential_Time / Parallel_Time) / Number of Threads
What was were your results? What was your efficiency? Cut and Paste the FINAL RESULTS from your program into the text box below. This cut & paste should include the sequential and parallel processing times and the efficiency calculation.
How many cores does your laptop/PC have? Open up the Task Manager and take a look, like we did in the lecture. How many threads did you create? Play around with executing your program using:
How does it affect the efficiency of the program? In the text box below, using your own words, explain why you see a difference.
You should now have a parallel solution that compiles and runs properly. Next I want you to evaluate the cost of these controls. For this part, you will modify your code to introduce specific controls into the design and answer questions.
Place a std::mutex around your results matrix. Anytime you read/write to the results matrix your program must acquire the mutex, perform the operation and release the mutex for other threads to use. Make sure your matrix size is at least 1000×1000 and run your program 10 times. Each time you run your program, log the Efficiency and Execution Time in the text boxes below, then calculate the average Efficiency and Execution Time.
Efficiency/Execution Time Output for each of the 10 runs
Average Efficiency: Average Execution Time:
Change the std::mutex around your results matrix with a std::shared_mutex and updated your codes logic accordingly. Make sure your matrix size is at least 1000×1000 and run your program 10 times. Each time you run your program, log the Efficiency and Execution Time in the text boxes below, then calculate the average Efficiency and Execution Time.
Efficiency/Execution Time Output for each of the 10 runs
Average Efficiency: Average Execution Time:
You have now seen the impact of a std::mutex vs. a std::shared_mutex. Can you modify your design to create a faster and/or more efficient solution? Try. Once you have succeeded mark your test data below and explain what you did and why you think it worked. Efficiency/Execution Time Output for each of the 10 runs
Rubric
See eConestoga for details.
Once you have completed your assignment upload the following files INDIVIDUALLY to eConestoga using the assignment submission link:
Please make sure you delete all .vs (Hidden), release and debug directories before you compress and upload your solution.

![[SOLVED] Cscn73000 assignment 1– matrix multiplication 2025](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[SOLVED] Implementing Hashtable-based Symbol Tables](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.