0

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

cdiggins
  • 15,532
  • 6
  • 92
  • 95
  • 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
  • 1
    In general, the answer is probably .AsParallel().Where(... or some other LINQ ex method. – SimpleVar Apr 04 '12 at 00:23

2 Answers2

5
myCollection.AsParallel().Where(...);

Source: http://msdn.microsoft.com/en-us/library/dd460714.aspx

cdiggins
  • 15,532
  • 6
  • 92
  • 95
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
  • 1
    Well, 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);

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.

Community
  • 1
  • 1
Tim Schmelter
  • 411,418
  • 61
  • 614
  • 859