I have a list of objects and I have to do some elaboration for each one of them, all of this in the least amount of time possible.
Since those elaborations are indipendent from each others, we've decided to do them in parallel with Parallel.ForEach
.
Parallel.ForEach(hugeObjectList,
new ParallelOptions { MaxDegreeOfParallelism = 50 },
obj => DoSomeWork(obj)
);
Since it seems unreasonable to me setting a huge number on ParallelOptions.MaxDegreeOfParallelism
(e.g. 50 or 100), how can we find the optimal number of parallel task to crunch this list?
Does Parallel.Foreach
start a DoSomeWork
on a different core? (so, since we have 4 cores, the correct degree of parallelism would be 4?)
I think this says it all
By default, For and ForEach will utilize however many threads the underlying scheduler provides, so changing MaxDegreeOfParallelism from the default only limits how many concurrent tasks will be used.