Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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[,
  Internal`InheritedBlock[{MessagePacket},
    Unprotect[MessagePacket];
    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]}, " "],
            Black],
        obj}], form]]
      ];
    #
  ], HoldAll];

f[var : _] :=
    Block[{arg},
    arg = var;
    1/arg
];

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.

Thanks!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.