O'Reilly logo

Learning .NET High-performance Programming by Antonio Esposito

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required