Following this question and the comments made, together with the information in this question, the following code allows error tracking and debugging very nicely.

SetAttributes[withTaggedMsg, HoldAll];

withTaggedMsg[sym_] := Function[,
    MessagePacket[name__, BoxData[obj_, form_]] /; ! TrueQ[$tagMsg] :=
      Block[{$tagMsg = True},
        Identity@MessagePacket[name, BoxData[RowBox[{
          ToBoxes @ Style[
            Row[{"At iteration", HoldForm[sym], "=", sym, Spacer[5]}, " "],
        obj}], form]]
  ], HoldAll];

f[var : _] :=
    arg = var;

Map[f[#] &, Range[-2, 1, 1]] // withTaggedMsg[arg]

(*At iteration arg=0  Power::infy : Infinity expression 1/0 encountered.
{-(1/2), -1, ComplexInfinity, 1}*)

Now, the big problem is how to use withTaggedMsg together with ParallelMap instead of Map.

ParallelMap[f[#] &, Range[-2, 1, 1]] // withTaggedMsg[arg]

(*At iteration arg=arg Parallel`Protected`PacketHandler::default: Unhandled packet MessagePacket[Power,infy,BoxData[RowBox[{StyleBox[RowBox[{Power,::,infy}],
MessageName],: ,"Infinite expression \!\(1\/0\) encountered."}],StandardForm]] received and discarded from KernelObject[6,local].
{-(1/2), -1, ComplexInfinity, 1}*)

I don't see how I could do it, and would appreciate immensely if I could get some input in this.


  • $\begingroup$ I found this question today while retagging posts. I don't believe I have seen it before. Are you still hoping for an answer? $\endgroup$ – Mr.Wizard Jul 9 '15 at 1:58
  • $\begingroup$ I guess not, no. Sorry if it stayed here for too long. Should I close it? $\endgroup$ – Sos Jul 9 '15 at 10:09
  • $\begingroup$ Surely it is not your fault that nobody answered. Incidentally in 10.1.0 under Windows this appears to work: ParallelMap[withTaggedMsg[arg][f@#] &, Range[-2, 1, 1]]. The inner term can also be written withTaggedMsg[arg]@*f. Do these work for you? $\endgroup$ – Mr.Wizard Jul 9 '15 at 16:10
  • $\begingroup$ Indeed, it works, but it isn't as pretty as the one above (ofc, this isn't a problem): ´ParallelProtectedPacketHandler::default: Unhandled packet MessagePacket[Power,infy,...iteration",TagBox[<<2>>],"=",0,... {GrayLevel[0], RectangleBox[{0, -1}, {2, 1}]}}, AspectRatio->1, Frame->True, FrameStyle->GrayLevel[0.], FrameTicks->None, ImageSize->{Automatic, 10.8}, PlotRangePadding->None]),StripOnInput->False],RowBox[{StyleBox[RowBox[<<1>>],MessageName],: ,"Infinite expression \!(1\/0) encountered."}]}],StandardForm]] received and discarded from KernelObject[2,local].´ $\endgroup$ – Sos Jul 10 '15 at 12:28
  • $\begingroup$ (sorry for the messy comment. but you can see that ´iteration,...=,0´, similarly to the code above.) Maybe you'd like to post this as an answer? $\endgroup$ – Sos Jul 10 '15 at 12:29

Your Answer

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

Browse other questions tagged or ask your own question.