Back

Debug Challenge: Parallel Timing

Three faults · on paper · no computer needed

divider

Objective

This program is supposed to work out how long a job takes. It runs without error and every number it prints is wrong.

There are no syntax errors and nothing crashes. All three faults are logic errors — the kind that produce a confident, plausible, incorrect answer.

Work on paper. You can find all three by reading, and reading is the skill being tested.

divider

The Program

Parallel Timing
int[] tasks = { 15, 25, 35, 45 };
int processors = 2;
int unsplittable = 20; // seconds that cannot be shared out
int seq = SequentialTime();
int par = ParallelTime(processors);
Console.WriteLine($"sequential: {seq}s");
Console.WriteLine($"parallel: {par}s");
Console.WriteLine($"speedup: {Speedup(seq, par):F2}");
int SequentialTime()
{
int total = unsplittable;
for (int i = 0; i < tasks.Length; i++)
{
total = total + tasks[i];
}
return total;
}
int ParallelTime(int howMany)
{
int longest = 0;
for (int i = 0; i < tasks.Length; i++)
{
if (tasks[i] > longest)
{
longest = tasks[i];
}
}
return longest;
}
double Speedup(double sequential, double parallel)
{
return parallel / sequential;
}

What It Prints

Wrong
sequential: 140s
parallel: 45s
speedup: 0.32

What It Should Print

Right
sequential: 140s
parallel: 80s
speedup: 1.75
What You Are Looking For
THREE THINGS ARE WRONG.
One is a formula written backwards.
One is a parameter that is accepted and ignored.
One is a number that was added in one place
and should have been added in two.
The task times are 15, 25, 35, 45.
There are 2 processors.
20 seconds cannot be shared out.
divider

The Questions

Fault 1

  1. Which line is wrong?
  2. What is it computing instead of what it should compute?
  3. Write the corrected line.
  4. How would you have noticed this without being told the right answer?

Fault 2

  1. Which method is wrong, and what is it ignoring?
  2. Work out the correct value by hand. Show the split you chose across the two processors.
  3. Is there more than one split that gives the correct answer?
  4. This method takes a parameter called howMany and never uses it. What did we call that in Quarter 2?

Fault 3

  1. What does unsplittable represent, and where is it correctly used?
  2. Where else does it belong, and why?
  3. What would the program print if unsplittable were 0?

All Three Fixed

  1. Write out the three corrected lines or methods.
  2. Now change processors to 4 and give the new parallel time and speedup, by hand.
  3. Change it to 100. What is the parallel time now, and why does it stop going down?
divider

Submit

All three faults identified with corrected lines, your hand-worked split, and the answers for 4 processors and 100 processors.

It is collected as Homework 7, together with Question Set 21. The drop is worth 5 points for everything in it, graded on completion.

Commence Challenge