jeffheaton / encog-dotnet-core

http://www.heatonresearch.com/encog
Other
430 stars 150 forks source link

Encog DotNet 3.3 Multithread Error #89

Open XeonMan opened 8 years ago

XeonMan commented 8 years ago

I am getting what seems to be an Encog (3.x) threading / workload error...

Been using Encog CS 3.1, 3.2 and 3.3 with VS.NET 2015 on two servers, each with dual X5400 series 4 core / 4 thread Xeons (8 core / 8 thread system total) without a problem. One has 32Gb RAM and the other 64Gb (though I am only actually seeing 1 busy thread, but that's another story...).

I recently tried the exact same code, compiled (exe) and on the VS IDE on a dual X7500 series 8 core / 16 thread Xeon server (16 core / 32 thread 64Gb system total) and I get this error (with the Encog CS pre-compiled DLL straight from GitHub):

System.OverflowException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Arithmetic operation resulted in an overflow. at Encog.Util.Concurrency.DetermineWorkload..ctor(Int32 threads, Int32 workloadSize) at Encog.Neural.Networks.Training.Propagation.Propagation.Init() at Encog.Neural.Networks.Training.Propagation.Propagation.CalculateGradients() at Encog.Neural.Networks.Training.Propagation.Propagation.ProcessPureBatch() at Encog.Neural.Networks.Training.Propagation.Propagation.Iteration() at EncogConsole.modEncog.ElmanTypeA(Boolean boolErrorVerbose, Boolean boolTestOutput) in C:\Users\Administrator\Documents\Visual Studio 2015\Projects\NormalizedConsole_v4B\EncogConsole\modEncog.vb:line 126 at EncogConsole.modEncog.Main() in C:\Users\Administrator\Documents\Visual Studio 2015\Projects\NormalizedConsole_v4B\EncogConsole\modEncog.vb:line 35 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()System.OverflowException: Arithmetic operation resulted in an overflow. at Encog.Util.Concurrency.DetermineWorkload..ctor(Int32 threads, Int32 workloadSize) at Encog.Neural.Networks.Training.Propagation.Propagation.Init() at Encog.Neural.Networks.Training.Propagation.Propagation.CalculateGradients() at Encog.Neural.Networks.Training.Propagation.Propagation.ProcessPureBatch() at Encog.Neural.Networks.Training.Propagation.Propagation.Iteration() at EncogConsole.modEncog.ElmanTypeA(Boolean boolErrorVerbose, Boolean boolTestOutput) in C:\Users\Administrator\Documents\Visual Studio 2015\Projects\NormalizedConsole_v4B\EncogConsole\modEncog.vb:line 126 at EncogConsole.modEncog.Main() in C:\Users\Administrator\Documents\Visual Studio 2015\Projects\NormalizedConsole_v4B\EncogConsole\modEncog.vb:line 35 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() 0.31s The thing here is that the code is the exact same, with the exact same datasets, etc. Tried different code that's running fine on the first two X5400 servers (albeit on what seems to be a single thread) and still the same problem (on the X7500 server). All machines running W2K8R2 with latest patches, etc. Code is done with VB, but as said before, works just fine, except on this higher thread count server. What gives?
XeonMan commented 8 years ago

Suggest using:

var num = (int) Environment.ProcessorCount;

instead of:

var num = (int) (Math.Log(((int) Process.GetCurrentProcess().ProcessorAffinity + 1), 2));

to get the processor (thread) count in:

Encog.Util.Concurrency.DetermineWorkload > public DetermineWorkload(int threads, int workloadSize)

as var num = (int) (Math.Log(((int) Process.GetCurrentProcess().ProcessorAffinity + 1), 2)); returns 4294967295 for a dual cpu, 32 thread system whereas Environment.ProcessorCount correctly returns 32.