Parallel Filter Algorithm in C#

Go To


I am looking for an implementation of a parallel filter algorithm in C#.

2012-04-04 00:21
by cdiggins
Add more information of your problem. Give an example of what you are trying to accomplish. Add in some code that does the procedure in a non parallel manner to help us understand the actual need - SimpleVar 2012-04-04 00:22
In general, the answer is probably .AsParallel().Where(... or some other LINQ ex method - SimpleVar 2012-04-04 00:23




2012-04-04 00:26
by Kendall Frey
Thats the answer @YoryeNathan put as a comment 4 minutes before you - Jeremy Thompson 2012-04-04 00:35
Well, it is the answer, and since Yorye didn't post it as an answer I did - Kendall Frey 2012-04-04 00:39
IMHO its better SO etiquette to tell someone their comment is answer: We can disagree on this but @YoryeNathan does contribute to the site... 0/80 QA rate. ps its not the answer until it has a green tick under it; - Jeremy Thompson 2012-04-04 00:44
Removed "TIP: Google is your friend". That didn't add anything to your answer - cdiggins 2012-04-04 11:47


You're probably looking for ParallelEnumerable.AsParallel Method:

var data = Enumerable.Range(1, 100000000).Select(i => i);
var even = data.AsParallel().Where(i => i % 2 == 0);

Edit: The above example is not a good candidate for PLINQ since the mudulo operation is not enough work and the overhead of parallelization will offset most or all of the speedup.

I've copied the links from my own question on the same subject, they are all worth reading.

2012-04-04 00:29
by Rango