When To Use Parallel.ForEach and When to Use PLINQ

When To Use Parallel.ForEach and When to Use PLINQ

Rate This
  • Comments 5

If you've played around with PLINQ and Parallel.ForEach loops in .NET 4, you may have noticed that many PLINQ queries can be rewritten as parallel loops, and also many parallel loops can be rewritten as PLINQ queries. However, both parallel loops and PLINQ have distinct advantages in different situations. When writing parallel code, it helps to understand these differences to appropriately decide between the two models.

Pamela Vagata wrote an interesting comparison of parallel loops and PLINQ: When Should I Use Parallel.ForEach? When Should I Use PLINQ?

Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post
  • IMHO last sample FindLowestIndex<T,T> is wrong. There is no synchronization so it can happen that matchedindex will not be lowest. It is needed rewrite it to use ParallelLoopState.LowestBreakIteration.

  • Great catch! The lack of synchronization on matchedIndex can result in a race condition such that the returned value isn't the lowest index. Thanks for pointing this error out, we're looking into fixing this in the paper :)

  • The like "When Should I Use Parallel.ForEach? When Should I Use PLINQ?" is broken

  • The link "When Should I Use Parallel.ForEach? When Should I Use PLINQ?" is broken

  • @PepLamb: Thanks.  Fixed.

Page 1 of 1 (5 items)