Skip to main content

Parallel checkpoint

Challenge on lesson: Checkpoint: parallel

CHALLENGE
Difficulty: advanced+25 XP

Implement static long SumSquaresParallel(int[] data, int threshold) that sums squares of elements โ€” sequentially when data.Length <= threshold, in parallel otherwise, using Parallel.For with a thread-local sum (interlocked-locked final combine). Then implement static int[] SquaresParallel(int[] data) returning squares IN ORIGINAL ORDER via PLINQ (AsOrdered). The test compares both against sequential results and asserts the parallel version of a 10M-element array beats a deliberately slow sequential baseline (a fake per-item cost).

Back to lesson: Checkpoint: parallel