Is it possible to add a stack trace for this parallelized code to see where the problems stem from?

a[x_] := 1/x;
a1 = Parallelize[Map[a, {-1, 0, 1, 2}]];

as you can see in unparallelized version ?

b = Table[1/x, {x, -1, 2}]
  • 1
    $\begingroup$ Good question. I tried a[x_] := TracePrint@Last@{$MachineName, 1/x}; with two remote kernels in different hosts. It does return the TracePrint but strangely it seems to have been evaluate at the local master kernel, not in the remote ones. Therefor I don't think this qualifies as an acceptable answer. $\endgroup$ – rhermans Aug 11 '17 at 14:41
  • $\begingroup$ @rhermans Correct me if i am wrong but the TracePrint will produce everything occurred in the evaluation of a function. Therefor it is not as neat as the embedded stack trace and can produce a lot of unnecessary junk and cause the kernel to explode $\endgroup$ – user49047 Aug 12 '17 at 15:16

You have a 0 in your lists, and 1/0==Infinity

Also, if you remove the ; from the first part, you will see the exact same result.

Additionally, you could use ParallelMap instead of Parallelize[Map[x]]

Anyway, your code basically says "Calculate 1/x for -1, 0, 1, and 2" and it does so correctly for each case. The error you see just comes from the fact that you're calculating a 1/0 case.

If you want to debug, go to Evaluation -> Debugger, and click on "Break at Messages." Then run your code. Once it gets to the error, you can click "Continue" or look for the highlighted (green) line where the error occurred. You can also hit "Show Stack" to see variable values.

| improve this answer | |
  • 1
    $\begingroup$ i am very well aware of why i get the error as i have deliberately made them up so i would get the error. i have already tried what you have suggested in your second part of the answer(debugging mode) and as far as i know it only works for the unparallelized part of the code. $\endgroup$ – user49047 Aug 11 '17 at 14:01
  • 1
    $\begingroup$ You need to include information like this in your question, especially if you deliberately created an error. It's also helpful to people to know what you've already tried, otherwise you're wasting the time of people who might be trying to help you. $\endgroup$ – Matt Stein Aug 11 '17 at 15:08
  • $\begingroup$ @MattStein you make a fair point, in general terms, but I think particularly in this case it's quite evident from the question that the main aim is to find a method for "Debugging parallelized code" and not to find the error on a particularly simple example. $\endgroup$ – rhermans Aug 11 '17 at 15:58
  • $\begingroup$ @MattStein As far as I can tell your answer does not provide a solution for evaluation in a remote kernel called by ParallelMap or Parallelize[Map[x]]. Sorry, the "-1" is mine. Please do correct me if I'm wrong. $\endgroup$ – rhermans Aug 11 '17 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.