Write a program, using your favorite computer (under some operating system, supp
ID: 3531404 • Letter: W
Question
Write a program, using your favorite computer (under some operating system, supporting Virtual Memory Management) and your favorite programming language, which demonstrates that the timings of matrix addition differ substantially for large enough matrices, depending on whether one uses Version 1 or Version 2: Version 1: for i:= 1 to n do for j := 1 to n do C[i, j] := A[i,j] + B[i, j] Version 2: for j := 1 to n do for i:= 1 to n do C[i, j] := A[i,j] + B[i, j] Specifically, use this sequence of value for n, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, and study the timings of both versions. Keep in mind that if everything was done in main memory, the timings for the two versions would be the same and doubling n would quadruple the time required. Note that you must initialize your matrices A and B but the time required for this should not be part of your measurements.Explanation / Answer
Hey, please rate with 5 stars :)
I want to give you the main logic behin this problem, since you can easily find such codes on the internet :)
You must be knowing that arrays are stored in row major form on the hard disk. Therefore, the order in which we access them depends on the timing it will take. That is, if we access the elements in row major form, it will take less time since the values will be found on the cache itself. The whole question of yours revolves around this concept.
You can easily find a code for matrix addition over the intenet. I leave it up to you.
Cheers!
Please rate :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.