views:

548

answers:

3

Hi,

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.

+1  A: 

More threads may not result in higher throughput once you exceed the number of available processors. Once you've done that, all that happens is context switching and time slicing between threads.

Have a look at ThreadPool.

duffymo
Yes... and no. If your thread is asleep (I/O bound threads are included here), you're basically wasting a CPU core.
Blindy
+3  A: 

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

Eric Dahlvang
I guess this is for PLINQ but I get the idea.. thanks.
Gilad
+1  A: 

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.

cdiggins