【问题标题】:Encog DotNet 3.3 Multithread ErrorEncog DotNet 3.3 多线程错误
【发布时间】:2016-01-14 02:07:14
【问题描述】:

我收到了似乎是 Encog (3.x) 线程/工作负载错误...

在两台服务器上使用带有 VS.NET 2015 的 Encog CS 3.1、3.2 和 3.3,每台服务器都配备双 X5400 系列 4 核/4 线程 Xeon(总共 8 核/8 线程系统),没有问题。一个有 32Gb RAM,另一个有 64Gb(虽然我实际上只看到 1 个繁忙的线程,但那是另一回事了......)。

我最近尝试了完全相同的代码,在双 X7500 系列 8 核/16 线程 Xeon 服务器(总共 16 核/32 线程 64Gb 系统)上的 VS IDE 上编译 (exe) 和我收到此错误(使用Encog CS 预编译 DLL 直接来自 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 

这里的问题是代码完全相同,具有完全相同的数据集等。尝试了在前两个 X5400 服务器上运行良好的不同代码(尽管似乎是单线程)并且仍然相同问题(在 X7500 服务器上)。所有运行 W2K8R2 且带有最新补丁等的机器。

代码是用 VB 完成的,但如前所述,除了在这个更高线程数的服务器上之外,它工作得很好。

什么给了?

【问题讨论】:

  • 我刚刚通过 BIOS 禁用了一半的内核和超线程,有效地渲染了一个 8 核 / 8 线程系统,你瞧,Encog 出现了,这清楚而直接地使这成为了一个 Encog 多线程问题。 ..
  • 我对自己的ENCOG很感兴趣,我还需要花一些时间来尝试一下。根据我的经验,为多核开发的软件的问题经常出现在不可见或不显示自身的竞态条件下,这要归功于内核较少且缓存较小的处理器上的时序或慢速缓存,但随着内核数量的增长,比赛条件暴露的机会更高。
  • 听起来很合理,尽管原始问题中提到的最慢的机器是双 3GHz x 4 核(总共 8 个物理核)@每个 12Mb L2 高速缓存,1333 Mhz FSB 和 Encog 运行良好。所有机器实际上大部分时间都处于空闲状态。然而,最大的机器只有一半的内核被禁用,还有 HT,Encog 运行良好......
  • 我要调试一下,看看到底发生了什么……会发回来的。
  • Ok... 结果 Process.GetCurrentProcess().ProcessorAffinity 给了我 {4294967295} ,正如我通过查看代码所想的那样,它旨在返回线程数,根本不是正确实现(var num = (int) (Math.Log(((int) Process.GetCurrentProcess().ProcessorAffinity + 1), 2));)。我将编辑代码以获取实际的线程数,然后我将返回结果。

标签: c# vb.net multithreading encog


【解决方案1】:

建议使用:

var num = (int)Environment.ProcessorCount;

代替:

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

获取处理器(线程)计数:

Encog.Util.Concurrency.DetermineWorkload > publicDetermineWorkload(int threads, int workflowSize)

as var num = (int) (Math.Log(((int) Process.GetCurrentProcess().ProcessorAffinity + 1), 2));对于双 CPU、32 线程系统,返回 4294967295,而 Environment.ProcessorCount 正确返回 32。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 2020-08-08
    • 1970-01-01
    相关资源
    最近更新 更多