From d7698982e02a87cfac33f79a295dd2aa5d7277f8 Mon Sep 17 00:00:00 2001 From: vsalomaki Date: Thu, 21 Jan 2016 20:08:35 +0200 Subject: [PATCH 1/2] Arithmetic overflow when running 32 CPUs -> Fix for it When running the code on a system with 32 (virtual) CPUs, the Process.GetCurrentProcess().ProcessorAffinity overflows 32-bit integer. Example of such system is c4.8xlarge at Amazon, --- encog-core-cs/Util/Concurrency/DetermineWorkload.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encog-core-cs/Util/Concurrency/DetermineWorkload.cs b/encog-core-cs/Util/Concurrency/DetermineWorkload.cs index c2e65841..43c1425b 100644 --- a/encog-core-cs/Util/Concurrency/DetermineWorkload.cs +++ b/encog-core-cs/Util/Concurrency/DetermineWorkload.cs @@ -66,7 +66,7 @@ public DetermineWorkload(int threads, int workloadSize) _workloadSize = workloadSize; if (threads == 0) { - var num = (int) (Math.Log(((int) Process.GetCurrentProcess().ProcessorAffinity + 1), 2)); + var num = (int) (Math.Log(((long) Process.GetCurrentProcess().ProcessorAffinity.ToInt64() + 1), 2)); // if there is more than one processor, use processor count +1 if (num != 1) From 336f721adeffa2790249ef9eaec0dc9725c5f069 Mon Sep 17 00:00:00 2001 From: vsalomaki Date: Thu, 21 Jan 2016 20:36:56 +0200 Subject: [PATCH 2/2] Better solution for the 36 CPU overflow.. --- encog-core-cs/Util/Concurrency/DetermineWorkload.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/encog-core-cs/Util/Concurrency/DetermineWorkload.cs b/encog-core-cs/Util/Concurrency/DetermineWorkload.cs index 43c1425b..557f735e 100644 --- a/encog-core-cs/Util/Concurrency/DetermineWorkload.cs +++ b/encog-core-cs/Util/Concurrency/DetermineWorkload.cs @@ -66,7 +66,7 @@ public DetermineWorkload(int threads, int workloadSize) _workloadSize = workloadSize; if (threads == 0) { - var num = (int) (Math.Log(((long) Process.GetCurrentProcess().ProcessorAffinity.ToInt64() + 1), 2)); + var num = Environment.ProcessorCount; // if there is more than one processor, use processor count +1 if (num != 1)