Plinq Vs Linq Parallel Programming in .Net Framework 4.0

No.of Views1139
Bookmarked0 times
Downloads 
Votes0
By  usamawahabkhan   On  25 May 2010 08:05:12
Tag : LINQ , General
PLINQ automatically parallelizes local LINQ queries. PLINQ has the advantage ofbeing easy to use in that it offloads the burden of both work partitioning and resultcollation to the Framework.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

PLINQ automatically parallelizes local LINQ queries. PLINQ has the advantage ofbeing easy to use in that it offloads the burden of both work partitioning and resultcollation to the Framework.
 

Image Loading

How to partitioning working

Image Loading

Wihtout PLIINQ

Image Loading

With PLINQ

Image Loading
public static void callPlinQ()
        {

            DateTime daa = new DateTime();
            daa = DateTime.Now;

            IEnumerable<int> numbersx = Enumerable.Range(3, 1000000 - 3);

            var parallelQueryx = from n in numbersx.AsParallel()
                                 where Enumerable.Range(2, (int)Math.Sqrt(n)).All(i => n % i > 0)
                                 select n;int[] primesx = parallelQueryx.ToArray();

            DateTime exx = new DateTime();
            exx = DateTime.Now;

            Console.WriteLine(" in PLINQ "+(exx - daa).ToString());
        }

With LINQ

Image Loading
public static void callLinQ()
        {

            DateTime da = new DateTime();
            da = DateTime.Now;

            IEnumerable<int> numbers = Enumerable.Range(3, 1000000 - 3);

            var parallelQuery = from n in numbers
                                where Enumerable.Range(2, (int)Math.Sqrt(n)).All(i => n % i > 0)
                                select n;int[] primes = parallelQuery.ToArray();

            DateTime ex = new DateTime();
            ex = DateTime.Now;

            Console.WriteLine("LINQ "+(ex - da).ToString());
        }

Enjoy the PLINQ.

Sample Project Source

Download source files -23 kb

 
Sign Up to vote for this article
 
About Author
 
usamawahabkhan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Pakistan
Joined date-06 May 2010
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
    In this article we will focus LINQ Remote and Local exaction such as This query executes on the server, Remote execution of query is default in LINQ, In Remote execution advantage of Databases index can be taken, Remote execution allows us to take the advantage of Database server engine, Remote execution allows us to only select particular rows from the table. This is very useful when we do have large amount of data in the server.
    Published Date : 07/Jan/2011
    In this article, we will see how to work with LINQ against IIS.
    Published Date : 10/Aug/2010
    how to create a XML tree using Functional Construction method of LINQ to XML.
    Published Date : 13/Apr/2010
    This article demonstrates how to use LINQ on DataTable, XML Data using LINQ to XML and SQL server data base using LINQ to SQL Classes.
    Published Date : 28/Jun/2010
    In this article we will focus, how to read CSV file using LINQ to CSVProvider.I hope we know read CSV file using StreamReader or any other readers in C#. But when we are use the LINQ to CSVProvider, and then we could get additional features to query data in LINQ as like Sql Query.
    Published Date : 01/Jan/2011
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top