Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase concurrent parallel tasks with System.Threading.Parallel (.Net 4.0)

I'm experimenting with the new System.Threading.Parallel methods like parallel for and foreach.

They seem to work nicely but I need a way to increase the number of concurrent threads that are executed which are 8 (I have a Quad core).

I know there is a way I just can find the place thy hidden the damn property.

Gilad.

like image 269
Gilad Avatar asked Sep 11 '26 04:09

Gilad


2 Answers

quote:

var query = from item in source.AsParallel().WithDegreeOfParallelism(10)
        where Compute(item) > 42
        select item;

In cases where a query is performing a significant amount of non-compute-bound work such as File I/O, it might be beneficial to specify a degree of parallelism greater than the number of cores on the machine.

from: MSDN

like image 146
Eric Dahlvang Avatar answered Sep 12 '26 17:09

Eric Dahlvang


IF you are using Parallel.For or Parallel.ForEach you can specify a ParallelOptions object which has a property MaxDegreesOfParallelism. Unfortunately this is just a maximum limit as the name suggests, and does not provide a lower bound guarantee. For the relationsship to WithDegreeOfParallelism see this blog post.

like image 26
cdiggins Avatar answered Sep 12 '26 17:09

cdiggins