Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A processor has a particular speed, clockRate. Although some instructions may re

ID: 3772146 • Letter: A

Question

A processor has a particular speed, clockRate. Although some instructions may require several clock cycles to complete, a modern computer often executes more than one instruction in parallel, so a given program on a given computer has an average instructionsPerCycle that may be either less than or greater than unity. The ideal total execution time is:

statementExecutions x instructionsPerStatement /

(instructionsPerCycle x clockRate ).

To this ideal time, we must add whatever time it takes to fetch information not immediately available. For each successful instruction execution, we must add time to account for the chance of not finding something that’s needed. Not finding something in the first-level cache adds:

(1 - firstCacheHitFraction) x firstCacheSwapTime.

Not finding something in the second-level cache adds:

(1 - firstCacheHitFraction) x (1 - secondCacheHitFraction) x

secondCacheSwapTime.

Not finding something in the main memory adds:

(1 - firstCacheHitFraction) x (1 - secondCacheHitFraction) x

(1 - mainMemoryHitFraction) x

[0.5 / diskSpeed + pageSize/(diskTrackLength x diskSpeed)].

Total incremental time is average incremental time multiplied by: statementExecutions x instructionsPerStatement.

Using initialized values:

Write a Java program that estimates the total time to run a typical computer program. Note the 12 “assumed” numeric values in the sample session below. Use 12 initialization statements to store those values into 12 variables. No user input is necessary. The bottom two lines are calculated results.

Sample session:

Assumed executions of source-code statements: 10000

Assumed average instructions/statement: 20.0

Assumed clock rate in megahertz: 2000.0

Assumed average instructions/cycle: 1.0

Assumed first-level cache hit fraction: 0.99

Assumed first-level cache swap time in microsec: 0.0010

Assumed second-level cache hit fraction: 0.999

Assumed second-level cache swap time in microsec: 0.0050

Assumed main memory hit fraction: 0.9999

Assumed main memory page size in bytes/page: 4096

Assumed disk speed in revolutions/sec: 500.0

Assumed disk track length in bytes/revolution: 400000

Ideal execution time = 1.0E-4 seconds.

Expected execution time = 1.0221409599999999E-4 seconds.

Using inputs:

Modify the program of part A to make it accept inputs that override the initialized values. Make your program so that what appears on your computer screen matches the following sample session. As always, if a sample session contains italicized values, those values indicate user input.

Sample session:

Enter executions of source-code statements: 10000

Enter average instructions/statement: 20

Enter clock rate in megahertz: 2000

Enter average instructions/cycle: 1

Enter first-level cache hit fraction: .99

Enter first-level cache swap time in microsec: .001

Enter second-level cache hit fraction: .999

Enter second-level cache swap time in microsec: .005

Enter main memory hit fraction: .9999

Enter main memory page size in bytes/page: 4096

Enter disk speed in revolutions/sec: 500

Enter disk track length in bytes/revolution: 400000

Ideal execution time = 1.0E-4 seconds.

Expected execution time = 1.0221409599999999E-4 seconds.

Explanation / Answer

Complete Program:

// File: Test.java
import java.util.*;
public class Test
{
public static void main(String[] args)
{
  Scanner input = new Scanner(System.in);
  
  int statementExecutions = 10000;
  double instructionsPerStatement = 20.0;
  double instructionsPerCycle = 1.0;
  double clockRate = 2000.0;
  double firstCacheHitFraction = 0.99;
  double firstCacheSwapTime = 0.0010;
  double secondCacheHitFraction = 0.999;
  double secondCacheSwapTime = 0.0050;
  double mainMemoryHitFraction = 0.9999;
  int pageSize = 4096;
  double diskSpeed = 500.0;
  double diskTrackLength = 400000;
  double idealExecutionTime;
  double expectedExecutionTime;
  
  idealExecutionTime = statementExecutions * instructionsPerStatement / ((instructionsPerCycle * statementExecutions) * (clockRate * 100.0));
  expectedExecutionTime = (1 - firstCacheHitFraction) * (1 - secondCacheHitFraction) * (1 - mainMemoryHitFraction) * (0.5 / diskSpeed + pageSize/(diskTrackLength * diskSpeed));
  
  System.out.println("Ideal execution time = " + idealExecutionTime);
  System.out.println("Expected execution time = " + expectedExecutionTime);
  
  
  System.out.print(" Enter executions of source-code statements: ");
  statementExecutions = input.nextInt();  
  System.out.print("Enter average instructions/statement: ");
  instructionsPerStatement = input.nextDouble();
  System.out.print("Enter clock rate in megahertz: ");
  clockRate = input.nextDouble();
  System.out.print("Enter average instructions/cycle: ");
  instructionsPerCycle = input.nextDouble();
  System.out.print("Enter first-level cache hit fraction: ");
  firstCacheHitFraction = input.nextDouble();
  System.out.print("Enter first-level cache swap time in microsec: ");
  firstCacheSwapTime = input.nextDouble();
  System.out.print("Enter second-level cache hit fraction: ");
  secondCacheHitFraction = input.nextDouble();
  System.out.print("Enter second-level cache swap time in microsec: ");
  secondCacheSwapTime = input.nextDouble();
  System.out.print("Enter main memory hit fraction: ");
  mainMemoryHitFraction = input.nextDouble();
  System.out.print("Enter main memory page size in bytes/page: ");
  pageSize = input.nextInt();  
  System.out.print("Enter disk speed in revolutions/sec: ");
  diskSpeed = input.nextDouble();
  System.out.print("Enter disk track length in bytes/revolution: ");
  diskTrackLength = input.nextDouble();
  
  idealExecutionTime = statementExecutions * instructionsPerStatement / ((instructionsPerCycle * statementExecutions) * (clockRate * 100.0));
  expectedExecutionTime = (1 - firstCacheHitFraction) * (1 - secondCacheHitFraction) * (1 - mainMemoryHitFraction) * (0.5 / diskSpeed + pageSize/(diskTrackLength * diskSpeed));
  
  System.out.println("Ideal execution time = " + idealExecutionTime);
  System.out.println("Expected execution time = " + expectedExecutionTime);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote