Data parallelism with TPL

As already said, data parallelism with TPL happens only when we deal with a dataset (not the DataSet class). Within .NET, the easy way of doing this is with the Parallel.For and Parallel.ForEach methods from the Parallel module. The following example shows the basic usage of the Parallel module:

for (int i = 0; i < 10; i++)
{
    //do something
}

Parallel.For(0, 10, i =>
{
    //do something
});

The first thing that catches our eye is the singularity of logic. While in task parallelism we deal with multiple instances of logic; here, there is always only one type of logic. We simply execute it on multiple CPUs.

This example is obviously incompatible with the Set Theory previously exposed, because there is neither a simple collection ...

Get Learning .NET High-performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.