# Getting a Stack Trace on parallel execution

I find debugging very difficult in Mathematica, perhaps because I am unfamiliar with the appropriate tools. Ideally, I would like a "break on error" like Matlab with step control, however for the meantime let me be more specific.

When an error occurs, I can click the little red box with three dots and obtain a stack trace which is helpful in identifying in which function/location the error occurred. In parallel execution this little box doesn't appear, I only get the error message and the kernel id. How can I print out the function stack trace in parallel execution to provide a similar granularity of detail as to where the error occurred?

• This is how I use the debugger. Hope it helps. As for parallel stuff: I would not try to debug it this way. It would be a mess. I would debug the code in a serial environment first. – Szabolcs Sep 4 '18 at 13:41
• @Szabolcs, thanks. The problem is that the code base is very large, with many things composed of many others - lots of interdependency and many calls to different modules. Moreover, the computation happens over a day or two and across more than 50 CPU cores, and yet the error occurs after a long period of time. It is simply not feasible to run it in a serial environment to wait days or weeks for the error to occur each time.. – bjorne Sep 4 '18 at 13:45
• Well, it probably won't be easy then. Here's a way to trigger an error on any message: mathematica.stackexchange.com/a/1545/12 Look up Stack[] and use it in the message handler to collect information about the kernel state at the time of the message. You'd need to do this on the subkernels, as their state is separate from that of the main kernel. – Szabolcs Sep 4 '18 at 14:15
• Download the troubleshooting notebook linked at the very end of this blog post: szhorvat.net/pelican/latex-typesetting-in-mathematica.html It has a section where I attempt to collect stack traces on the machine of the user experiencing the problem. It may be helpful, but it's neither a pretty nor a complete solution. – Szabolcs Sep 4 '18 at 14:17
• @Szabolcs, thanks! – bjorne Sep 4 '18 at 14:37