Question

I would like to extract following code into a new method:

...
Parallel.For(0, Environment.ProcessorCount, i => 
       { handTypeSum[i] = new PSTLooper(intHands).EvalEnumeration(i); });
...

PSTLooper is of type IEvaluator and I have several other IEvaluators I would like to test with that method. The Method should be executed as fast as possible, for now I'm quite happy with the performance of Parallel.For (I would love to learn about faster/better methods).

I need to generate a new object for each Thread and the current # of Thread for my EvalEnumeration(int instance) method. Several attempts have failed because of these constraints.

Some of my tries:


StartNewTest(new PSTLooper(intHands));

public void StartNewTest(IEvaluator)
{
     Parallel.For(0, Environment.ProcessorCount, i => 
          { handTypeSum[i] = e.EvalEnumeration(i); });
}

that approach compiles, but only uses the IEvaluator and does not create a new one.


StartNewTest(new PSTLooper(intHands).EvalEnumeration());

public void StartNewTest(Func<long[]> func)
{
     Parallel.For(0, Environment.ProcessorCount, i => 
          { handTypeSum[i] = func.Invoke(); });
}

that does not compile, as I need the # of Instance.


I'm quite sure that my approach is not the best, but for now I don't know any better and thus need to ask this question here.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top