2

Doing something that throws out an error (warning):

ParallelTable[NIntegrate[1/Sin[10 t], {t, 0, W}], {W, 0, 10, 1}]

In parallel somehow limits a possiblity to harvest error messages like I usually do:

myMessageList = {};
Internal`InheritedBlock[{Message, $InMsg = False}, Unprotect[Message];
Message[msg_, vars___] /; ! $InMsg := 
Block[{$InMsg = True}, 
AppendTo[myMessageList, {HoldForm[msg], vars}];
Message[msg, vars]];
ParallelTable[NIntegrate[1/Sin[10 t], {t, 0, W}], {W, 0, 10, 1}]] (*this is the string that is being executed*)
myMessageList

This works for Table just fine. Is there a way to avoid that? What I really need is to discard any output that produces an error.

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Vsevolod A.
  • 959
  • 5
  • 15

1 Answers1

4

Two changes make it work. Collect the messages on each subkernel and alter Message on each subkernel. The messages can be harvested with ParallelEvaluate.

ParallelEvaluate[myMessageList = {}];
ParallelTable[
 Internal`InheritedBlock[{Message, $InMsg = False},
  Unprotect[Message];
  Message[msg_, vars___] /; ! $InMsg := Block[{$InMsg = True},
    AppendTo[myMessageList, {HoldForm[msg], vars}];
    Message[msg, vars]];
  NIntegrate[1/Sin[10 t], {t, 0, W}]
  ],
 {W, 0, 10, 1}]
ParallelEvaluate[myMessageList]  (* Flatten[%, 1] if desired *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747