Aggregation is another common design pattern that's used in parallel applications. In parallel programs, the data is divided into units so that it can be processed across cores by a number of threads. At some point, there is a need to combine data from all the relevant sources before it can be presented to the user. This is where aggregation comes into the picture.
Now, let's explore the need for aggregation and what is provided by PLINQ.
A common use case of aggregation is as follows. Here, we are trying to iterate a set of values, perform some operations, and return the result to the caller:
var output = new List<int>();
var input = Enumerable.Range(1, 50);
Func<int,int> action = (i) => i * i;
foreach (var item in input)
{
var result = action(item);
output.Add(result);
}
The problem with the preceding code is that the output isn't...