Reputation: 35
i'm building a custom plugin for Unity GameEngine which supports .NET 3.5 And to be able to use TPL i installed the Reactive Extensions v1.0.2856.0 (i think is the last that includes TPL). So, in a script i have a loop with about 65000 interations. I have no problem using the Parallel.Foreach loop for example, but the problem is that with the default partitioner the work is not distributed equally because of the small count of iterations and actually the loop gets a bit slower.
So my questions is: Is there a way to create a partitioner which gives to my 2 CPU cores about half of the iterations to work with.
Upvotes: 1
Views: 246
Reputation: 2686
Use ParallelOptions.MaxDegreeOfParallelism:
var options = new ParallelOptions {MaxDegreeOfParallelism = 2};
Parallel.ForEach(list, options,
item =>
{
// work})
});
Upvotes: 0