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.
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;}sequential: 140sparallel: 45sspeedup: 0.32sequential: 140sparallel: 80sspeedup: 1.75THREE 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.howMany and never uses it. What did we call that in Quarter 2?unsplittable represent, and where is it correctly used?unsplittable were 0?processors to 4 and give the new parallel time and speedup, by hand.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.