Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Study the code: Cache Performanc /* COPYING: * Dave Patterson at UCB modified this code from a program by Andrea * Dusseau of U.C. Berkeley,which

Study the code: Cache Performanc

/* COPYING: * Dave Patterson at UCB modified this code from a program by Andrea * Dusseau of U.C. Berkeley,which was based on a description in * Saavedra-Barrera [1992]: * Saavedra-Barrera, R. H. [1992]. CPU Performance Evaluation and * Execution Time Prediction Using Narrow Spectrum Benchmarking, * Ph.D. Dissertation, University of Calif., Berkeley (May). * Patterson has given permission to use and modify this code as long * as these people and the U. of Cal., Berkeley get proper credit. */

#include #include #include #include #define CACHE_MIN (1024) /* smallest cache */ #define CACHE_MAX (16*1024*1024) /* largest cache */ #define SAMPLE 10 /* to get a larger time sample */ #ifndef CLK_TCK #define CLK_TCK 60 /* number clock ticks per second */ #endif int x[CACHE_MAX]; /* array going to stride through */ double get_seconds() { /* routine to read time */ struct tms rusage; times(&rusage); /* UNIX utility: time in clock ticks */ return (double) (rusage.tms_utime)/CLK_TCK; }

int main() { int register i, index, stride, limit; int temp; int steps, tsteps, csize; double sec0, sec; /* timing variables */ for (csize=CACHE_MIN; csize <= CACHE_MAX; csize=csize*2) for (stride=1; stride <= 128; stride=stride*2) { sec = 0; /* initialize timer */ limit = csize-stride+1; /* cache size this loop */ steps = 0; do { /* repeat until collect 1 second */ sec0 = get_seconds(); /* start timer */ for (i=SAMPLE*stride;i!=0;i=i-1) /* larger sample */ for (index=0; index < limit; index=index+stride) x[index] = x[index] + 1; /* cache access */ steps = steps + 1; /* count while loop iterations */ sec = sec + (get_seconds() - sec0);/* end timer */

} while (sec < 1.0); /* until collect 1 second */ /* Repeat empty loop to loop subtract overhead */ tsteps = 0; /* used to match no. while iterations */ do { /* repeat until same no. iterations as above */ sec0 = get_seconds(); /* start timer */ for (i=SAMPLE*stride;i!=0;i=i-1) /* larger sample */ for (index=0; index < limit; index=index+stride) temp = temp + index; /* dummy code */ tsteps = tsteps + 1; /* count while iterations */ sec = sec - (get_seconds() - sec0);/* - overhead */ } while (tsteps

__________________________ TASKS:

1. What does it do? 2. What does it print?

Compile and run the code by going to the directory where you downloaded the c file and type: gcc -O0 filename.c. /a.out 3. Why do you see the numbers you see? Relate the numbers to the memory system. Use the output to figure out the memory system of the HPC machine. For example, how many and how large caches does the machine have and how did you arrive at that?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Under what conditions is the MantelHaenszel test appropriate?

Answered: 1 week ago

Question

What is electric dipole explain with example

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago