/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public MultithreadedScalingTestDemo(DemosGame game)
: base(game)
{
simulationBuilders = new Func<Space, int>[]
{
BuildPileSimulation,
BuildWallSimulation,
BuildPlanetSimulation
};
#if WINDOWS
int coreCountMax = Environment.ProcessorCount;
testResults = new double[coreCountMax, simulationBuilders.Length];
int reruns = 1;
for (int i = 0; i < reruns; i++)
{
GC.Collect();
var threadManager = new SpecializedThreadManager();
//Try different thread counts.
for (int j = 0; j < coreCountMax; j++)
{
threadManager.AddThread();
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[j, k] = RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
}
}
#else
testResults = new double[4, simulationBuilders.Length];
int reruns = 10;
for (int i = 0; i < reruns; i++)
{
GC.Collect();
var threadManager = new SpecializedThreadManager();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 1 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[0, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 3 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[1, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 5 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[2, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
threadManager.AddThread(delegate { Thread.CurrentThread.SetProcessorAffinity(new[] { 4 }); }, null);
for (int k = 0; k < simulationBuilders.Length; k++)
testResults[3, k] += RunTest(threadManager, simulationBuilders[k]);
GC.Collect();
}
#endif
}