Data parallelism with PLINQ
PLINQ is the framework required to use LINQ within the TPL parallel framework. In .NET, it is straightforward to use parallelism against any LINQ query because we simply need to add the AsParallel
method at the root of the query to switch the execution from the simple LINQ engine to PLINQ with TPL support.
The following example will execute two different where
conditions against an enumerable using PLINQ:
static void Main(string[] args) { //a dataset var items = Enumerable.Range(1, 100); //multi-level in-memory where executed as data parallelism var processedInParallel = items.AsParallel() .Where(x => CheckIfAllowed1(x)) .Where(x => CheckIfAllowed2(x)) .ToArray(); Console.ReadLine(); } private static bool CheckIfAllowed2(int ...
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.