# Tag Info

2

I have experienced serious memory leaks with NDSolve, NIntegrate, and FindRoot in every version of Mathematica I have owned (still on V9), perhaps over 20 years. They typically show up for me when the routine is called at a deep level in a complex program. The only cure in many cases is to remove the offending routine and write your own. For NIntegrate, ...

1

After reading this and this answer, I noticed that the debugger is also useful for identifying the error source in this case. You just need to: Go to Evaluation and check on Debugger. Check on Break at Messages and click the Show Stack button (alternatively you can click the button after running the erroneous code) in the newly opened panel. Run the ...

3

http://mathematica.stackexchange.com/a/118739/6804 discusses compiling a library link dll and attaching a debugger. With say Visual Studio, you can just attach to process -> WolframKernel.exe after the dll has been loaded (via LibraryFunctionLoad).

7

In your example, a message is issued at the problem. You want to find out where the message comes from. The debugger is pretty good at this. Just enable the debugger, then enable Break at Messages, then evaluate your code. You get a nice display of the stack, which in itself allows you to localize the problem. Since this was an interactive ...

1

My code is executed in two distinct environments: inside WorkBench where I test it, and automatically by kernel. Inside WorkBench $Linked is True, so I set the following: If[$Linked, dbPrint = Print; ]; Then, when I need a debug print out, I used dbPrint which only has a value when being run inside of WorkBench, and does not effect production code. ...

3

Actually form C.E.'s comment. Make a custom function for this SetAttributes[AddPrint, HoldFirst] AddPrint[loopBody_] := Module[{st = ToString[Unevaluated[loopBody], InputForm], i = 0}, StringReplace[st, RegularExpression["^|(?<=;)"] :> TemplateApply["Print[];", ++i]]] It can help you add Print into your loopBody automatically loopBody = ...

2

I often use the form Block[{Print=Identity}, expr] to suppress Print statements that I have added for debug purposes.

3

Perhaps you need to define MTensor for variable left and right. The modified code is: #include "WolframLibrary.h" DLLEXPORT int NonzeroBasis(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) { /*define the argument-varible*/ mreal saved; mint i, p; mreal u; MTensor tensor_U; mreal *U; /*-------------...

3

Yes, this is possible. In Mathematica print out \$ProcessID then in GDB you can use attach to attach to that process id and you should be able to debug.

16

Update: The very likely reason for the garbled error messages is that you have a Chinese version of Visual Studio printing errors in Chinese, and there is a mismatch in the character encoding of these messages and how Mathematica tried to interpret them. CreateLibrary has two very useful options: "ShellCommandFunction" and "ShellOutputFunction". Set ...

8

For me (Windows 10) I get a readable error message like So I add mint saved;. Compiling again I get which leads me to change your MArgument_setReal(Res,tensor_N); to MArgument_setMTensor(Res,tensor_N); and then things work. BTW: I use Needs["CCompilerDriver`"]; srccode=" #include \"WolframLibrary.h\" DLLEXPORT int NonzeroBasis(WolframLibraryData ...

Top 50 recent answers are included