Crash of Matlab running chili() function

A place to report and discuss potential bugs
Post Reply
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Crash of Matlab running chili() function

Post by katarkon »

Running example scripts from slowmotion folder (like nitroxide_basic.m) Matlab R2012b closes sometimes withowt any error messages. The error is irreproducible and may occurs at second of fird start of the script.

Running the same script on Matlab R2007b returns the follow messages:

Code: Select all

------------------------------------------------------------------------
       Segmentation violation detected at Mon Sep 11 09:12:27 2017
------------------------------------------------------------------------

Configuration:
  MATLAB Version:   7.5.0.342 (R2007b)
  MATLAB License:   161052
  Operating System: Microsoft Windows XP
  Window System:    Version 5.1 (Build 2600: Service Pack 3)
  Processor ID:     x86 Family 6 Model 7 Stepping 6, GenuineIntel
  Virtual Machine:  Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
  Default Charset:  windows-1251

Register State:
  EAX = 00000004  EBX = 12357870
  ECX = 14476a04  EDX = 00ced244
  ESI = 00ced2a4  EDI = 14470000
  EBP = 00cecbfc  ESP = 00cecb98
  EIP = 14476a60  FLG = 00210246

Stack Trace:
  [0] chili_lm.mexw32:0x14476a60(4, 0x00ced244, 4, 0x00ced2a4)
  [1] libmex.dll:_mexRunMexFile(4, 0x00ced244, 4, 0x00ced2a4) + 139 bytes
  [2] libmex.dll:private: void __thiscall Mfh_mex::runMexFileWithSignalProtection(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(4, 0x00ced244, 4, 0x00ced2a4) + 86 bytes
  [3] libmex.dll:public: virtual void __thiscall Mfh_mex::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(4, 0x00ced244, 4, 0x00ced2a4) + 261 bytes
  [4] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(4, 0x00ced244, 4, 0x00ced2a4) + 203 bytes
  [5] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(735, 0x13fd6734 "chili_lm", 4, 4) + 744 bytes
  [6] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x13fd6734 "chili_lm", 735, 4, 0xfffffffc) + 156 bytes
  [7] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 18040, 885, 0) + 2614 bytes
  [8] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 18040, 60, 0) + 87 bytes
  [9] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 18040, 60, 0) + 274 bytes
  [10] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x14017720, 0x12a7d600, 0x85113f33, 0xffffffff) + 916 bytes
  [11] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(2, 0x00ced884, 3, 0x00ced8e4) + 673 bytes
  [12] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 2, 0x00ced884, 3) + 29 bytes
  [13] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00ced884, 3, 0x00ced8e4) + 28 bytes
  [14] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00ced884, 3, 0x00ced8e4) + 203 bytes
  [15] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(698, 0x13fd66bc "chili", 2, 3) + 744 bytes
  [16] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x13fd66bc "chili", 698, 2, 3) + 156 bytes
  [17] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 18040, 122, 0) + 2614 bytes
  [18] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 18040, 60, 0) + 87 bytes
  [19] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 18040, 60, 0) + 274 bytes
  [20] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x14017720, 0x12a7d600, 0x851136f3, 0xffffffff) + 916 bytes
  [21] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(0, 0x00cedec4, 2, 0x00cedf24) + 673 bytes
  [22] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0, 0x00cedec4, 2) + 29 bytes
  [23] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cedec4, 2, 0x00cedf24) + 28 bytes
  [24] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cedec4, 2, 0x00cedf24) + 203 bytes
  [25] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(698, 0x0155bdd3 "chili", 0, 2) + 744 bytes
  [26] m_interpreter.dll:_inCallFcnFromReference(0x8511081f, 0xffffffff, 0x0150283c, 0) + 166 bytes
  [27] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 0, 22, 0) + 4760 bytes
  [28] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 0, 3, 0) + 87 bytes
  [29] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 0, 3, 0) + 274 bytes
  [30] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x12a4bee0, 0x129f6301, 0x85110cf3, 0xffffffff) + 916 bytes
  [31] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(0, 0x00cee4c4, 0, 0x00cee524) + 673 bytes
  [32] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0, 0x00cee4c4, 0) + 29 bytes
  [33] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cee4c4, 0, 0x00cee524) + 28 bytes
  [34] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cee4c4, 0, 0x00cee524) + 203 bytes
  [35] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(680, 0x015d7804 "nitroxide_basic", 0, 0) + 744 bytes
  [36] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x015d7804 "nitroxide_basic", 680, 0, 0) + 156 bytes
  [37] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(2, 0, 0, 0) + 2739 bytes
  [38] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 87 bytes
  [39] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 274 bytes
  [40] m_interpreter.dll:_inInterPcode(2, 0x8511000b, 0, 0x015edd20 "nitroxide_basic\n") + 162 bytes
  [41] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_function(int *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck,bool)(0x00cef2bc, 0x00cef32c, 0x00cef358, 2) + 152 bytes
  [42] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalStringWithIsVarFcn(struct _memory_context *,char const *,enum EvalType,int,struct mxArray_tag * * const,enum inDebugCheck,struct _pcodeheader *,int *,bool (__cdecl*)(void *,char const *),void *,bool)(0x7ac2177c, 0x015edd20 "nitroxide_basic\n", 0, 0) + 2454 bytes
  [43] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalReturnandtype(char const *,int *,enum inDebugCheck,bool)(0x015edd20 "nitroxide_basic\n", 0, 2, 0) + 107 bytes
  [44] m_interpreter.dll:_inEvalCmdNoEnd(0x015edd20 "nitroxide_basic\n", 0, 0x7d177eec, 0x7ab9e7f0) + 20 bytes
  [45] bridge.dll:enum inExecutionStatus __cdecl ThrowSignal(char const *)(0x015edd20 "nitroxide_basic\n", 0x7d1779a0, 0x014d4398, 0x014d4338) + 77 bytes
  [46] bridge.dll:__catch$_mnParser$0(0x2bd8eb15, 0x014d4338, 0x014d4338, 0) + 292 bytes
  [47] mcr.dll:public: void __thiscall mcrInstance::mnParser(void)(0x35c86445, 0x004043f0, 336710, 0) + 62 bytes
  [48] MATLAB.exe:0x00401414(4194304, 0, 336710, 10)
  [49] MATLAB.exe:0x00401733(0, 0, 0x7ffdb000, 0x8054b6ed)
  [50] kernel32.dll:0x7c817077(0x00401910, 0, 0x78746341, 32)

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.
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Crash of Matlab running chili() function

Post by Stefan Stoll »

Thanks for reporting. It looks like you have 32-bit machine. Unfortunately, we don't have any and therefore cannot test this. Can you try this on a 64-bit machine?
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Crash of Matlab running chili() function

Post by katarkon »

I can try to reproduce the problem on 64-bit platform but not right now.
I found that the bug is reproduced independently from the number of nuclei in spin system (0,1,2).
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Crash of Matlab running chili() function

Post by Stefan Stoll »

Try the following things to further localize the bug. See if you can find conditions under which there is no crash.
  1. Reduce numbers in Opt.LLKM.
  2. Reduce the undocumented Opt.AllocationBlockSize from its default value of 1e6 to 1e5, 1e4, 1e3.
Run everything with Opt.Verbosity = 2 and observe the basis size and the number of non-zero elements reported.
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Crash of Matlab running chili() function

Post by katarkon »

I found that the code nNuclei = (int)mxGetScalar(mxGetField(prhs[idxS],0,"nNuclei")); in chili_lm.c cause the crash.

UPD:
The bug was found.
The variable idxS is used before initilization. The line idxS = 0; should be placed before nNuclei = (int)mxGetScalar(mxGetField(prhs[idxS],0,"nNuclei"));. It fix the bug (recompilation of mex files is required).
PS. The compiler should issue a warning in such case but really not.
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Crash of Matlab running chili() function

Post by Stefan Stoll »

Great - thanks for locating the bug! We will fix it and post a bug-fix release.
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Crash of Matlab running chili() function

Post by Stefan Stoll »

Fixed in 5.2.2
Post Reply