Using PCP – Parallel.For() Overloads for Common Task Scheduling Scenarios

A common pattern in parallel computing scenarios is the task scheduling/execution scenario of initialization(1) –> parallel-work-execution(N) –> finalization(1).    The initialization phase runs once (as a single task) followed by the parallel-work-execution phase (as 1-N concurrent tasks) followed by the finalization phase (as a single collation task).

Implementation of this pattern is greatly simplified using an overload of the Parallel.For() .NET library function.   The pattern is also available with other API variations including Parallel.ForEach().   Note the following commented code snippet illustrating the use of this pattern:

image