MatLab Mex 文件每三分之一崩溃一次 运行

MatLab Mex File Crashing Every Third Run

我目前正在尝试 运行 来自 glmnet 包 (http://web.stanford.edu/~hastie/glmnet_matlab/index.html) 的代码。 它在此过程中调用 mex 文件。当我前两次 运行 包中的函数时,它工作正常。每三次我尝试,MatLab 都会给出一个 "catastrophic" 错误并要求我关闭它。 它可能与 mex 文件的内存分配有关吗?我想知道这是否是 mex 文件用户的常见问题。 谢谢

编辑:这是 "catastrophic" 错误:

------------------------------------------------------------------------
          Access violation detected at Mon Jul 13 13:20:32 2015
------------------------------------------------------------------------

Configuration:
  Crash Decoding      : Disabled
  Crash Mode          : continue (default)
  Current Graphics Driver: Unknown hardware 
  Default Encoding    : windows-1252
  Graphics card 1     : NVIDIA ( 0x10de ) NVIDIA GeForce GT 740M Version 9.18.13.4752
  Graphics card 2     : Intel Corporation ( 0x8086 ) Intel(R) HD Graphics 4000 Version 10.18.10.3308
  Host Name           : Marcelo
  MATLAB Architecture : win64
  MATLAB Root         : C:\Program Files\MATLAB\MATLAB Production Server\R2015a
  MATLAB Version      : 8.5.0.197613 (R2015a)
  OpenGL              : hardware
  Operating System    : Microsoft Windows 8.1 Single Language
  Processor ID        : x86 Family 6 Model 58 Stepping 9, GenuineIntel
  Virtual Machine     : Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  Window System       : Version 6.3 (Build 9600)

Fault Count: 1


Abnormal termination:
Access violation

Register State (from fault):
  RAX = 00006e6f69746365  RBX = 0000000000000000
  RCX = 0000000004032bf0  RDX = 0000000000000000
  RSP = 0000000004031108  RBP = 0000000004032ce0
  RSI = 00000000f69ef970  RDI = 0000000004032be0

   R8 = 000000007fc60fc0   R9 = 0000000000000006
  R10 = 000000007fefd750  R11 = 000000007fefd750
  R12 = 0000000000000001  R13 = 0000000000000000
  R14 = 0000000004032ce0  R15 = 0000000004032be0

  RIP = 00000000fe16e073  EFL = 00010206

   CS = 0033   FS = 0053   GS = 002b

Stack Trace (from fault):
[  0] 0x00000000fe16e073 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmx.dll+00450675 MXGETPR+00000003
[  1] 0x00007ff87cdc1a95 C:\Users\Marcelo\Desktop\Marcelo\PUC\Mestrado\Diss\InstrumentSelection\glmnet_matlab\glmnetMex.mexw64+00006805 MEXFUNCTION+00002709
[  2] 0x00000000fc5f3740 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmex.dll+00079680 mexRunMexFile+00000112
[  3] 0x00000000fc5f2a72 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmex.dll+00076402 inSwapMexfileReader+00000594
[  4] 0x00000000fc5f25c8 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmex.dll+00075208 mexUnlock+00002840
[  5] 0x0000000004f22694 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00075412 Mfh_file::dispatch_fh+00000548
[  6] 0x0000000004f22a7e C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00076414 Mfunction_handle::dispatch+00000766
[  7] 0x0000000005059597 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00103831 in_is_matlab_function+00048455
[  8] 0x000000000505a1ab C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00106923 in_is_matlab_function+00051547
[  9] 0x000000000512684f C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944207 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000991
[ 10] 0x00000000051267b1 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944049 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000833
[ 11] 0x000000000509da75 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00383605 inGetCurrentWS+00155269
[ 12] 0x000000000509ce8c C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00380556 inGetCurrentWS+00152220
[ 13] 0x000000000509b6e9 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00374505 inGetCurrentWS+00146169
[ 14] 0x0000000004f22694 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00075412 Mfh_file::dispatch_fh+00000548
[ 15] 0x0000000004f22a7e C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00076414 Mfunction_handle::dispatch+00000766
[ 16] 0x0000000005059597 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00103831 in_is_matlab_function+00048455
[ 17] 0x000000000505a1ab C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00106923 in_is_matlab_function+00051547
[ 18] 0x000000000512684f C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944207 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000991
[ 19] 0x00000000051267b1 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944049 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000833
[ 20] 0x000000000509da75 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00383605 inGetCurrentWS+00155269
[ 21] 0x000000000509ce8c C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00380556 inGetCurrentWS+00152220
[ 22] 0x000000000509b6e9 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00374505 inGetCurrentWS+00146169
[ 23] 0x0000000004f22694 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00075412 Mfh_file::dispatch_fh+00000548
[ 24] 0x0000000004f22a7e C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00076414 Mfunction_handle::dispatch+00000766
[ 25] 0x0000000005059597 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00103831 in_is_matlab_function+00048455
[ 26] 0x00000000051731a7 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+01257895 inIsKeyword+00027799
[ 27] 0x000000000505b69a C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00112282 in_is_matlab_function+00056906
[ 28] 0x000000000512684f C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944207 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000991
[ 29] 0x00000000051267b1 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944049 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000833
[ 30] 0x000000000509da75 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00383605 inGetCurrentWS+00155269
[ 31] 0x000000000509ce8c C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00380556 inGetCurrentWS+00152220
[ 32] 0x000000000509b6e9 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00374505 inGetCurrentWS+00146169
[ 33] 0x0000000004f22757 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00075607 Mfh_file::dispatch_fh+00000743
[ 34] 0x0000000004f22a7e C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00076414 Mfunction_handle::dispatch+00000766
[ 35] 0x0000000005059597 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00103831 in_is_matlab_function+00048455
[ 36] 0x00000000051731a7 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+01257895 inIsKeyword+00027799
[ 37] 0x000000000505b69a C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00112282 in_is_matlab_function+00056906
[ 38] 0x000000000512684f C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944207 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000991
[ 39] 0x00000000051267b1 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00944049 MathWorks::MException::MExceptionEnvelope::MCOSClassID+00000833
[ 40] 0x000000000509da75 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00383605 inGetCurrentWS+00155269
[ 41] 0x000000000509ce8c C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00380556 inGetCurrentWS+00152220
[ 42] 0x000000000509b6e9 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00374505 inGetCurrentWS+00146169
[ 43] 0x0000000004f22757 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00075607 Mfh_file::dispatch_fh+00000743
[ 44] 0x0000000004f22a7e C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_dispatcher.dll+00076414 Mfunction_handle::dispatch+00000766
[ 45] 0x000000000512b268 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00963176 inAnonymousFunction+00000360
[ 46] 0x000000000512b864 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00964708 inAnonymousFunction+00001892
[ 47] 0x000000000512ba25 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00965157 inAnonymousFunction+00002341
[ 48] 0x000000000512b9f2 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00965106 inAnonymousFunction+00002290
[ 49] 0x000000000512b9a7 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00965031 inAnonymousFunction+00002215
[ 50] 0x00000000050df6bd C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00652989 inGetCallersWorkSpace+00001805
[ 51] 0x00000000050d854d C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00623949 inEvalCmdWithLocalReturn+00000285
[ 52] 0x00000000050d8471 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\m_interpreter.dll+00623729 inEvalCmdWithLocalReturn+00000065
[ 53] 0x00000000fb5fe82d C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmwbridge.dll+00059437 mnGetPrompt+00002717
[ 54] 0x00000000fb5ff2a9 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmwbridge.dll+00062121 mnParser+00000745
[ 55] 0x00000000fd0e13d4 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00398292 mcrInstance::mnParser_on_interpreter_thread+00000036
[ 56] 0x00000000fd0a9757 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00169815 mcr::runtime::setInterpreterThreadToCurrent+00019751
[ 57] 0x00000000fd0a9793 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00169875 mcr::runtime::setInterpreterThreadToCurrent+00019811
[ 58] 0x00000000fd0a9f91 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00171921 mcr::runtime::setInterpreterThreadToCurrent+00021857
[ 59] 0x00000000fab5d216 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\uiw.dll+00512534 UIW_AttachThreadInput+00001270
[ 60] 0x00000000fab5caa5 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\uiw.dll+00510629 wsd_to_MSW+00004373
[ 61] 0x00000000fab5cb29 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\uiw.dll+00510761 wsd_to_MSW+00004505
[ 62] 0x00007ff8ad1708ca                     C:\WINDOWS\system32\USER32.dll+00592074 BroadcastSystemMessageExA+00000586
[ 63] 0x00007ff8ad0e2e1f                     C:\WINDOWS\system32\USER32.dll+00011807 IsWindow+00000367
[ 64] 0x00007ff8ad0e2e96                     C:\WINDOWS\system32\USER32.dll+00011926 IsWindow+00000486
[ 65] 0x00007ff8af413034                      C:\WINDOWS\SYSTEM32\ntdll.dll+00602164 KiUserCallbackDispatcher+00000036
[ 66] 0x00007ff8ad0e2a8a                     C:\WINDOWS\system32\USER32.dll+00010890 PeekMessageW+00000250
[ 67] 0x00007ff8ad0e6283                     C:\WINDOWS\system32\USER32.dll+00025219 GetMessageA+00000243
[ 68] 0x00007ff8ad0e622f                     C:\WINDOWS\system32\USER32.dll+00025135 GetMessageA+00000159
[ 69] 0x00000000fab09bdb C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\uiw.dll+00170971 UIW_ShowMenuItem+00005179
[ 70] 0x00000000fab5db52 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\uiw.dll+00514898 UIW_SuspendAttachThreadInput+00000466
[ 71] 0x0000000100122c83 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmwservices.dll+01256579 services::system_events::PpeDispatchHook::dispatchOne+00032291
[ 72] 0x000000010012e6f5 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmwservices.dll+01304309 sysq::addProcessPendingEventsUnitTestHook+00005813
[ 73] 0x000000010012e7a0 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmwservices.dll+01304480 sysq::addProcessPendingEventsUnitTestHook+00005984
[ 74] 0x0000000100130595 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmwservices.dll+01312149 sysq::getCondition+00004629
[ 75] 0x0000000100131f52 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\libmwservices.dll+01318738 svWS_ProcessPendingEvents+00000162
[ 76] 0x00000000fd0aa6ad C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00173741 mcr::runtime::setInterpreterThreadToCurrent+00023677
[ 77] 0x00000000fd0ab31a C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00176922 mcr::runtime::setInterpreterThreadToCurrent+00026858
[ 78] 0x00000000fd0a2f75 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00143221 mcr_process_events+00007557
[ 79] 0x00000000fd0a4882 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mcr.dll+00149634 mcr_process_events+00013970
[ 80] 0x00000000084ab49d C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\MVMLocal.dll+00177309 mvm_server::inproc::LocalFactory::terminate+00048141
[ 81] 0x00000000fa8fa27a C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mvm.dll+00828026 mvm::detail::initLocalMvmHack+00000490
[ 82] 0x00000000fa8fa838 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mvm.dll+00829496 mvm::detail::SessionImpl::privateSession+00000376
[ 83] 0x00000000fa8faa88 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\mvm.dll+00830088 mvm::detail::SessionImpl::privateSession+00000968
[ 84] 0x000000014000630d C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\MATLAB.exe+00025357
[ 85] 0x0000000140007dd0 C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64\MATLAB.exe+00032208
[ 86] 0x00007ff8acea13d2                   C:\WINDOWS\system32\KERNEL32.DLL+00005074 BaseThreadInitThunk+00000034
[ 87] 0x00007ff8af395444                      C:\WINDOWS\SYSTEM32\ntdll.dll+00087108 RtlUserThreadStart+00000052


This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.

If this problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/contact_us/

A technical support engineer might contact you with further information.

Thank you for your help.

总结我们上面的评论,首先使用调试器完成 MEX 函数。查看此 post,了解如何根据您使用的操作系统使用 IDE 进行设置:Preventing a MEX file from crashing in MATLAB... 所以在第三次尝试时,找出它是哪一行崩溃于.

现在您已经确定了它崩溃的地方,您将遇到未解决的 Link 错误。未解决的链接错误来自尝试使用没有可用代码定义的代码/函数。当您 运行 代码时,似乎有预编译的 MEX 文件导致了问题。尝试重新编译代码,使其与您的系统最兼容。

64 位 Windows 的说明在这里:http://web.stanford.edu/~hastie/glmnet_matlab/win64compile.html. Similarly, the 32-bit instructions are here: http://web.stanford.edu/~hastie/glmnet_matlab/win32compile.html。您可以跳过说明中的第二步,因为我相信这一步是由较新版本的 MATLAB 处理的。


希望这会让事情变得更加稳定!