I am looking for an implementation of a parallel filter algorithm in C#.
Asked
Active
Viewed 1,207 times
0
-
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 Apr 04 '12 at 00:22
-
1In general, the answer is probably .AsParallel().Where(... or some other LINQ ex method. – SimpleVar Apr 04 '12 at 00:23
2 Answers
5
myCollection.AsParallel().Where(...);
Source: http://msdn.microsoft.com/en-us/library/dd460714.aspx
![](../../users/profiles/184528.webp)
cdiggins
- 15,532
- 6
- 92
- 95
![](../../users/profiles/785745.webp)
Kendall Frey
- 39,334
- 18
- 104
- 142
-
Thats the answer @YoryeNathan put as a comment 4 minutes before you? – Jeremy Thompson Apr 04 '12 at 00:35
-
1Well, it *is* the answer, and since Yorye didn't post it as an answer I did. – Kendall Frey Apr 04 '12 at 00:39
-
IMHO its better SO etiquette to tell someone their comment is answer: http://stackoverflow.com/questions/9880994/program-permissions#comment12602770_9880994 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 Apr 04 '12 at 00:44
-
Removed "TIP: Google is your friend". That didn't add anything to your answer. – cdiggins Apr 04 '12 at 11:47
2
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);
- http://msdn.microsoft.com/en-us/magazine/cc163329.aspx (not up-to-date)
- Overview of videos/articles according this topic
- PDF: When To Use ParallelForEach Or PLINQ
- When PLINQ will speedup performance
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.
![](../../users/profiles/-1.webp)
Community
- 1
- 1
![](../../users/profiles/284240.webp)
Tim Schmelter
- 411,418
- 61
- 614
- 859