exam2-s02 - NAME CS4400 Exam 2 April 1 2002 Instructions 1...

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

View Full Document Right Arrow Icon
1 of 15 NAME : CS4400 Exam 2 April 1, 2002 Instructions: 1. Make sure your exam has all of it’s pages. 2. Write your name on the front page and your name or secret integer on EVERY subsequent page. 3. The exam has a maximum score of 61 points. Approximately 1.25 points per minute is the pace you should work at. PLAN your time. 4. Problems vary in dif f culty, the point value of each problem is indicated, the last problem is the thought problem which you should save for last but save some time to attempt. 5. Write your answers in the space provided - use the backs of the pages for temporary calcula- tions and scratch paper. Write clearly and clearly indicate your f nal answer. If we can’t f nd your answer OR can’t read your writing then you will lose points which will not be given back by argument. 6. The exam is open book and notes. You may use a calculator but NO laptops or other wireless devices. GOOD LUCK!! Problem Grader Points Your Score 1 Bin 5 2 Bin 8 3 Zhen 14 4 Zhen 12 5 Bin 12 6 Al 10 TOTAL 61
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 of 15 NAME : Problem 1: (5 points) Consider the following C program: Assume - no processes getting cancelled by signals. Recall the following: Function fork returns 0 to the child process and the child’s process Id to the parent. Function wait returns -1 when there is an error, e.g., when the executing process has no child. Macro WEXITSTATUS extracts the exit status of the terminating process. What are all valid outputs of this program? Hint: there are several. #include <stdio.h> #include <sys/wait.h> #include <unistd.h> main() { int status; printf(“%s\n”, “Hello”); printf(“%d\n”, !fork()); if(wait(&status) != -1) printf(“%d\n”, WEXITSTATUS(status)); printf(“%s\n”, “Bye”); exit(2); }
Background image of page 2
3 of 15 NAME : Problem 2: (8 points): This problem concerns optimizing a procedure for maximum performance on an Intel Pentium III. Recall the following performance characteristics of the functional units on this machine: You’ve just joined a programming team that is trying to develop the world’s fastest factorial rou- tine. Starting with recursive factorial, they’ve converted the code to use iteration as follows: By doing so, they have reduced the number of cycles per element (CPE) for the function from around 63 to around 4 (really!!). Still they would like to do better. Operation Latency Issue Interval Integer Add 1 1 Integer Multiply 4 1 Integer Divide 36 36 Floating Point Add 3 1 Floating Point Multiply 5 2 Floating Point Divide 38 38 Load or Store (Cache Hit) 1 1 int fact(int n) { int i; result = 1; for (i = n; i > 0; i--) result = result * i; return result; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 of 15 NAME : One of the programmers heard about loop unrolling and generated the following code: Unfortunately the team has discovered that this code returns 0 for some values of n.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/28/2008 for the course CSCI 2400 taught by Professor Grundwald during the Spring '08 term at Colorado.

Page1 / 15

exam2-s02 - NAME CS4400 Exam 2 April 1 2002 Instructions 1...

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