Lect24 - CMSC 216 Introduction to Computer Systems Lecture 24 The Preprocessor Jan Plane& Pete Keleher{jplane [email protected] Storage and

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMSC 216 Introduction to Computer Systems Lecture 24 The Preprocessor Jan Plane & Pete Keleher {jplane, [email protected] Storage and access order matters • The layout of data items in memory means that if we access things in a different order, we can get wildly different execution times • Memory hierarchy: Type of storage Access time (CPU cycles) registers 1 cache (1 st level) ~2-3 memory ~10-100 CMSC 216 - Wood, Sussman, Herman, Plane More detailed memory hierarchy CPU registers hold words retrieved from cache memory. Registers On-chip L1 cache (SRAM) Main memory (DRAM) Local secondary storage (local disks) Larger, slower, and cheaper (per byte) storage devices Remote secondary storage (distributed Fle systems, Web servers) Local disks hold Fles retrieved from disks on remote network servers. Main memory holds disk blocks retrieved from local disks. Off-chip L2 cache (SRAM) L1 cache holds cache lines retrieved from the L2 cache. L2 cache holds cache lines retrieved from memory. L0: L1: L2: L3: L4: L5: Smaller, faster, and costlier (per byte) storage devices CMSC 216 - Wood, Sussman, Herman, Plane Two kinds of locality • Principle of locality: –programs tend to reuse data and instructions near those they have used recently, or that were recently referenced themselves –temporal locality: recently referenced items are likely to be referenced again in the near future –spatial locality: items with nearby addresses tend to be referenced close together in time CMSC 216 - Wood, Sussman, Herman, Plane Locality example • Data – reference array elements in succession (in the same order they're stored in memory) – reference sum each iteration • Instructions – reference instructions in sequence – cycle through loop repeatedly sum = 0; for (i = 0; i < n; i++) sum += a[i]; return sum; CMSC 216 - Wood, Sussman, Herman, Plane Aside: Multidimensional array storage • In C, array elements are stored in row major order in memory, meaning each row's elements are stored in adjacent locations in order by column subscript, and all of the rows are adjacent in memory, stored in order by row subscript. int a[2][3] = {{1, 3, 5}, {2, 4, 6}}; memory layout 6 4 2 5 3 1 1 3 5 2 4 6 conceptually CMSC 216 - Wood, Sussman, Herman, Plane A dramatic locality example #define ROWS 20000 #define COLS 20000 int main() { int arr[ROWS][COLS]; int i, j, sum = 0; struct rusage usage1, usage2; for (i = 0; i < ROWS; i++) for (j = 0; j < COLS; j++) arr[i][j] = rand(); getrusage(RUSAGE_SELF, &usage1); for (i = 0; i < ROWS; i++) for (j = 0; j < COLS; j++) sum += arr[i][j]; getrusage(RUSAGE_SELF, &usage2); printf("sum = %d\n", sum); /* calculate user time, store in usage2 */ printf("User time %d.%06ds\n", (int) usage2.ru_utime.tv_sec, (int) usage2.ru_utime.tv_usec); return 0; } CMSC 216 - Wood, Sussman, Herman, Plane A dramatic locality example #define ROWS 20000 #define COLS 20000 int main() { int arr[ROWS][COLS]; int i, j, sum = 0; struct rusage usage1, usage2; for (i = 0; i < ROWS; i++)...
View Full Document

This note was uploaded on 01/13/2012 for the course CMSC 216 taught by Professor Plane during the Spring '11 term at Maryland.

Page1 / 16

Lect24 - CMSC 216 Introduction to Computer Systems Lecture 24 The Preprocessor Jan Plane& Pete Keleher{jplane [email protected] Storage and

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online