Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PLINQ to spawn more concurrent threads in .NET 4.0 beta 2?

In former versions of Parallel Extensions you could set the number of threads:

enumerable.AsParallel(numberOfThreads)

But now that overload is not available anymore. How to do it now?

like image 485
Jader Dias Avatar asked Dec 14 '22 01:12

Jader Dias


2 Answers

In the new version you can specify it with the extension method ".WithDegreeOfParallelism(int degreeOfParallelism)".

IE:

enumerable.AsParallel().WithDegreeOfParallelism(numberOfThreads)
like image 188
Maghis Avatar answered Dec 16 '22 17:12

Maghis


I really have no idea why it changed, so I can't answer the question, but it seems like if the developer specifies the number of threads, then the parallel runtime won't be able to perform the operation in the most optimal way based on the currently available hardware threads.

I don't want to specify number of threads. The beauty of PLINQ is that it just goes parallel without me having to figure out any threading logic.

like image 28
CoderDennis Avatar answered Dec 16 '22 17:12

CoderDennis