Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume that both the arrays (a & b) are stored in a row-major fashion, which means all the element of a row are stored contiguously

Assume that both the arrays (a & b) are stored in a row-major fashion, which means all the element of a row are stored contiguously (a[i][0], a[i][1], a[i][2] etc. are stored in consecutive memory locations). i, j and sum are scalar variables. In the two codes given below identify variables which exhibit temporal locality and variables which exhibit spatial locality. What kind of locality is exhibited by the code itself? Provide adequate justifications by tracing the access pattern for your answer to get full credit.

Code-1: sum = 0.0; for(i=0; i<5000; i++){ for(j=0; j<100; j++){ sum =sum + a[i][j] * b[i][j]; } }

Code-2: sum = 0.0; for(j=0; j<100; j++){ for(i=0; i<5000; i++){ sum =sum + a[i][j] * b[i][j]; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions