THINK FIRST·CODE LATER

← All labs

Amdahl's law: is renting more servers worth it?

Problem

A faculty member asks how many cloud servers to rent for a simulation. Help them with Amdahl's law.

Input: first line P minEfficiency — the parallel fraction (0 ≤ P ≤ 1) and the minimum acceptable efficiency in percent. Then one or more server counts N, until the end of input.

For each N print N=… speedup=… efficiency=…% with speedup 1 / ((1 − P) + P / N) (three decimals) and efficiency speedup / N × 100 (one decimal), followed by OK if the efficiency is at least the minimum, otherwise WASTEFUL.

At the end print Max speedup: … (three decimals, 1 / (1 − P), or unlimited if P = 1) and Largest efficient N: … — the largest of the given N that is OK, or none.

Input:

0.9 50
2 4 8 16

Output:

N=2 speedup=1.818 efficiency=90.9% OK
N=4 speedup=3.077 efficiency=76.9% OK
N=8 speedup=4.706 efficiency=58.8% OK
N=16 speedup=6.400 efficiency=40.0% WASTEFUL
Max speedup: 10.000
Largest efficient N: 8

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os1-2-data-1.txt

0.9 50
2 4 8 16
What your program must print for os1-2-data-1.txt
N=2 speedup=1.818 efficiency=90.9% OK
N=4 speedup=3.077 efficiency=76.9% OK
N=8 speedup=4.706 efficiency=58.8% OK
N=16 speedup=6.400 efficiency=40.0% WASTEFUL
Max speedup: 10.000
Largest efficient N: 8

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os1-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os1-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.